private void fillListBlanks(DateTime startDate, DateTime endDate) { // start and end date should be coming in as first day of the month DateTime d = startDate; DateTime endLoop = endDate.AddDays(1); while (d < endLoop) { // if not present, create a blank one var hours = parent.Detail.GeneralHours.Where(x => x.Year == d.Year && x.Month == d.Month).FirstOrDefault(); if (hours == null) { hours = new CaseAuthorizationGeneralHours(); hours.Year = d.Year; hours.Month = d.Month; hours.Hours = 0; parent.Detail.GeneralHours.Add(hours); } d = d.AddMonths(1); } // clean up any existing hours that aren't part of our range parent.Detail.GeneralHours.RemoveAll(x => x.Year < startDate.Year); parent.Detail.GeneralHours.RemoveAll(x => x.Year > endDate.Year); parent.Detail.GeneralHours.RemoveAll(x => x.Month < startDate.Month && x.Year <= startDate.Year); parent.Detail.GeneralHours.RemoveAll(x => x.Month > endDate.Month && x.Year >= endDate.Year); parent.Detail.GeneralHours = parent.Detail.GeneralHours.OrderBy(x => x.Year).ThenBy(x => x.Month).ToList(); }
/********************* * CASE AUTH GENERAL HOURS *********************/ public static CaseAuthorizationGeneralHours CaseAuthorizationGeneralHour(Models.CaseAuthCodeGeneralHour entity) { if (entity == null) { return(null); } var item = new CaseAuthorizationGeneralHours(); item.CaseAuthID = entity.CaseAuthID; item.DateCreated = entity.DateCreated; item.Hours = (double)entity.HoursApplied; item.ID = entity.ID; item.Month = entity.HoursMonth; item.Year = entity.HoursYear; return(item); }
public CaseGeneralHoursVM GetGeneralHours(int caseID) { var model = new CaseGeneralHoursVM(); model.Items = new List <CaseGeneralHoursListItemVM>(); using (SqlConnection conn = new SqlConnection(this.connectionString)) using (SqlCommand cmd = new SqlCommand()) { cmd.Connection = conn; string authsSql = ""; authsSql += "SELECT cac.ID, cac.DateCreated, cac.AuthCodeID, cac.AuthClassID, "; authsSql += " cac.AuthStartDate, cac.AuthEndDate, cac.AuthTotalHoursApproved, "; authsSql += " ac.CodeCode, ac.CodeDescription, "; authsSql += " cls.AuthClassCode, cls.AuthClassName, cls.AuthClassDescription "; authsSql += "FROM CaseAuthCodes AS cac "; authsSql += "INNER JOIN AuthCodes AS ac ON ac.ID = cac.AuthCodeID "; authsSql += "INNER JOIN CaseAuthClasses AS cls ON cac.AuthClassID = cls.ID "; authsSql += "WHERE cac.CaseID = @CaseID "; authsSql += "ORDER BY cac.AuthClassID "; authsSql += ";"; string genHoursSql = ""; genHoursSql += "SELECT gh.ID, gh.CaseAuthID, gh.HoursYear, gh.HoursMonth, gh.HoursApplied "; genHoursSql += "FROM dbo.CaseAuthCodeGeneralHours AS gh "; genHoursSql += "INNER JOIN dbo.CaseAuthCodes AS cac ON cac.ID = gh.CaseAuthID "; genHoursSql += "WHERE cac.CaseID = @CaseID "; genHoursSql += ";"; cmd.CommandText = authsSql + genHoursSql; cmd.Parameters.AddWithValue("@CaseID", caseID); var set = cmd.GetDataSet(new string[] { "Auths", "GeneralHours" }); var generalHours = new List <Domain.Cases.CaseAuthorizationGeneralHours>(); foreach (DataRow r in set.Tables["GeneralHours"].Rows) { var gh = new CaseAuthorizationGeneralHours(); gh.ID = r.ToInt("ID"); gh.Year = r.ToInt("HoursYear"); gh.Month = r.ToInt("HoursMonth"); gh.Hours = r.ToDouble("HoursApplied"); gh.CaseAuthID = r.ToInt("CaseAuthID"); generalHours.Add(gh); } foreach (DataRow r in set.Tables["Auths"].Rows) { var item = new CaseGeneralHoursListItemVM(); item.AuthClass = new AuthorizationClass() { ID = r.ToInt("AuthClassID"), Code = r.ToStringValue("AuthClassCode"), Name = r.ToStringValue("AuthClassName"), Description = r.ToStringValue("AuthClassDescription") }; item.CaseAuthorizationID = r.ToInt("ID"); item.Code = r.ToStringValue("CodeCode"); item.Description = r.ToStringValue("CodeDescription"); item.EndDate = r.ToDateTime("AuthEndDate"); item.ID = r.ToInt("AuthCodeID"); item.StartDate = r.ToDateTime("AuthStartDate"); item.TotalHoursApproved = r.ToDouble("AuthTotalHoursApproved"); item.GeneralHours = new List <CaseAuthorizationGeneralHours>(); item.GeneralHours.AddRange(generalHours.Where(x => x.CaseAuthID.Value == item.CaseAuthorizationID.Value).ToList()); model.Items.Add(item); } return(model); } }