Tech
News
Videos
Forums
Jobs
Books
Events
More
Interviews
Live
Learn
Training
Career
Members
Blogs
Challenges
Certification
Contribute
Article
Blog
Video
Ebook
Interview Question
.NET
.NET Core
.NET MAUI
.NET Standard
Active Directory
ADO.NET
Agile Development
AI
AJAX
AlbertAGPT
Alchemy
Alexa Skills
Algorand
Algorithms in C#
Android
Angular
ArcObject
ASP.NET
ASP.NET Core
Augmented Reality
Avalanche
AWS
Azure
Backbonejs
Big Data
BizTalk Server
Blazor
Blockchain
Bootstrap
Bot Framework
Business
Business Intelligence(BI)
C#
C# Corner
C# Strings
C, C++, MFC
Career Advice
Careers and Jobs
Chapters
ChatGPT
Cloud
Coding Best Practices
Cognitive Services
COM Interop
Compact Framework
Copilot
Cortana Development
Cosmos DB
Cryptocurrency
Cryptography
Crystal Reports
CSS
Current Affairs
Custom Controls
Cyber Security
Data Mining
Data Science
Databases & DBA
Databricks
Design Patterns & Practices
DevExpress
DevOps
DirectX
Dynamics CRM
Enterprise Development
Entity Framework
Error Zone
Exception Handling
F#
Files, Directory, IO
Flutter
Games Programming
GDI+
General
Generative AI
GO
Google Cloud
Google Development
Graphics Design
Graphite Studio
Hardware
Hiring and Recruitment
HoloLens
How do I
HTML 5
Infragistics
Internet & Web
Internet of Things
Ionic
Java
Java and .NET
JavaScript
JQuery
JSON
JSP
Knockout
Kotlin
Langchain
Leadership
Learn .NET
Learn iOS Programming
LINQ
Machine Learning
Metaverse
Microsoft 365
Microsoft Fabric
Microsoft Office
Microsoft Phone
Microsoft Teams
Mobile Development
MongoDB
MuleSoft
MySQL
NEAR
NetBeans
Networking
NFT
NoCode LowCode
Node.js
Office Development
OOP/OOD
Open Source
Operating Systems
Oracle
Outsourcing
Philosophy
PHP
Polygon
PostgreSQL
Power Apps
Power Automate
Power BI
Power Pages
Printing in C#
Products
Progress
Progressive Web Apps
Project Management
Public Speaking
Python
Q#
QlikView
Quantum Computing
R
React
React Native
Reports using C#
Robotics & Hardware
RPA
Ruby on Rails
RUST
Salesforce
Security
Servers
ServiceNow
SharePoint
Sharp Economy
SignalR
Smart Devices
Snowflake
Software Architecture/Engineering
Software Testing
Solana
Solidity
Sports
SQL
SQL Server
Startups
Stratis Blockchain
Swift
SyncFusion
Threading
Tools
TypeScript
Unity
UWP
Visual Basic .NET
Visual Studio
Vue.js
WCF
Wearables
Web API
Web Design
Web Development
Web3
Windows
Windows Controls
Windows Forms
Windows PowerShell
Windows Services
Workflow Foundation
WPF
Xamarin
XAML
XML
XNA
XSharp
Register
Login
1
Answer
calendar perio in dropdown for current month only appearing two times?
Praveen Kumar
4y
532
1
Reply
Hi,
In my dropdown the current month generates two times.How to avoid- help me to fix this. "Jul 2020" duplicate.
//Controller
public
ActionResult Billing(BillingManagerQueryParameters query)
{
if
(_logger.IsInfoEnabled)
{
MethodBase m = MethodBase.GetCurrentMethod();
_logger.LogInfo(
string
.Format(
"Entering {0} with calendarPeriodId:{1} workflowGroupId:{2} companyId:{3}"
, m.Name, query.CalendarPeriodId, query.WorkflowGroupId, query.CompanyId));
}
CalendarPeriod period;
bool
locked =
false
;
User user =
null
;
using
(var dbContextScope = _dbContextScopeFactory.CreateReadOnly())
{
user = _Login.GetCurrentUser();
var calendarRepo =
new
CalendarPeriodRepository(_ambientDbContextLocator);
Customer customer = _wfRepo.FindBy<UserCustomer>(uc => uc.UserId == user.UserId,
new
[] {
"Customer"
}).FirstOrDefault().Customer;
if
(query.CalendarPeriodId ==
null
|| query.CalendarPeriodId == 0)
{
period = calendarRepo.GetCalendarPeriod(PeriodType.M, DateTime.Now, customer.Id);
//get last month available if there are calendar periods but just not one for the current month
if
(period ==
null
)
{
period = calendarRepo.GetLastMonthAvailablePeriod(PeriodType.M, DateTime.Now, customer.Id);
}
locked =
false
;
// TODO: Delete CustCalendarPeriod period.CustomerCalendarPeriods.Where(x => x.CustomerCUSTOMER_ID == customer.CUSTOMER_ID).FirstOrDefault().CLOSED_FLAG == "Y" ? true : false;
query.CalendarPeriodId = period.Id;
}
else
{
period = calendarRepo.GetCalendarPeriod((
int
)query.CalendarPeriodId);
Debug.WriteLine(
"Checked period lock "
+ period.Id);
locked =
false
;
// TODO: Delete CustCalendarPeriod period.CustomerCalendarPeriods.Where(x => x.CustomerCUSTOMER_ID == customer.CustomerId).FirstOrDefault().CLOSED_FLAG == "Y" ? true : false;
//Debug.WriteLine("Locked " + period.CustomerCalendarPeriods.Where(x => x.CustomerCUSTOMER_ID == customer.CustomerId).FirstOrDefault().CLOSED_FLAG);
//currentPeriod = calendarRepo.GetCalendarPeriod(PeriodType.M, DateTime.Now);
}
}
//Check if there are not any calendar periods in database, Show off a useful message to user to add Calendar Period for Monthly
if
(period ==
null
)
{
if
(_logger.IsInfoEnabled)
_logger.LogInfo(
"Exiting Billing"
);
return
View(
"~/Areas/Billing/Views/Manage/Modals/AddCalendarPeriodMonthlyModal.cshtml"
);
}
SelectList periods = CreateBillingPeriodSelectList(period);
var customerId = GetCustomerId();
SelectListItemHelper selectListItemHelper =
new
SelectListItemHelper();
SelectList companyList = selectListItemHelper.CompaniesByUser(customerId,user,
true
);
SelectList wgList = selectListItemHelper.WorkflowGroupsByUser(customerId,user,
true
);
// Build the model
BillingViewModel model =
new
BillingViewModel()
{
Query = query,
CurrentPeriod = period,
WorkflowGroups = selectListItemHelper.WorkflowGroupsByUser(customerId,user,
true
),
Companies = selectListItemHelper.CompaniesByUser(customerId,user,
true
),
BillingPeriods = periods,
CurrentPeriodLocked = locked,
};
return
View(model);
}
public
CalendarPeriod GetCalendarPeriod(PeriodType type, DateTime date,
int
customerId)
{
return
DbContext.CalendarPeriods
.Where(x => x.TypeCode == type.SmartCode &
x.StartDate <= date & x.EndDate >= date.Date &&
x.CalendarPeriodType.CustomerId == customerId
)
.FirstOrDefault();
}
public
CalendarPeriod GetLastMonthAvailablePeriod(PeriodType type, DateTime date,
int
customerId)
{
int
prevMonth = date.AddMonths(-1).Month;
return
DbContext.CalendarPeriods
.Where(x => x.TypeCode == type.SmartCode &
x.StartDate.Month <= prevMonth & x.EndDate.Month <= prevMonth &&
x.CalendarPeriodType.CustomerId == customerId)
.FirstOrDefault();
}
public
CalendarPeriod GetCalendarPeriod(
int
id)
{
return
DbContext.CalendarPeriods.Find(id);
}
private
SelectList CreateBillingPeriodSelectList(CalendarPeriod period)
{
var calendarRepo =
new
Repositories.CalendarPeriodRepository(_ambientDbContextLocator);
var billingRepo =
new
Repositories.BillingRepository(_ambientDbContextLocator);
int
customerId = GetCustomerId();
using
(var dbContextScope = _dbContextScopeFactory.CreateReadOnly())
{
List<CalendarPeriod> periodsAvailable =
new
List<CalendarPeriod>();
periodsAvailable.AddRange(calendarRepo.GetBillingPeriods(customerId));
if
(!periodsAvailable.Contains(period)) { periodsAvailable.Insert(0, period); }
SelectList monthList =
new
SelectList(periodsAvailable.Select(x =>
new
{ x.Id, x.Name }),
"Id"
,
"Name"
);
return
monthList;
}
}
public
List<CalendarPeriod> GetBillingPeriods(
int
customerId)
{
DateTime endDate = DateTime.Now.AddDays(15);
return
DbContext.CalendarPeriods
.Where(x => x.TypeCode == PeriodType.M.SmartCode &&
//x.StartDate >= startDate &&
x.StartDate <= endDate &&
x.VisibleToBilling &&
x.CalendarPeriodType.CustomerId == customerId)
.OrderByDescending(x => x.EndDate)
.ToList();
}
Post
Reset
Cancel
Answers (
1
)
Next Recommended Forum
Play/Pause functionality of File Upload in MVC
User-Profile ID login website using asp.net mcv c#?