public PartialViewResult CreateAgreedDays(CreateAgreedDaysAndPickup model) { string session = GetNewChildWizardSession(); if (ModelState.IsValid) { Toddler toddler = GetCurrentToddler(); AgreedDays agreedDays = new AgreedDays(); agreedDays.ToddlerId = toddler.ToddlerId; agreedDays.StartDate = model.agreedDays.StartDate; agreedDays.EndDate = model.agreedDays.EndDate; agreedDays.Monday = (bool)model.agreedDays.Monday; agreedDays.Tuesday = (bool)model.agreedDays.Tuesday; agreedDays.Wednesday = (bool)model.agreedDays.Wednesday; agreedDays.Thursday = (bool)model.agreedDays.Thursday; agreedDays.Friday = (bool)model.agreedDays.Friday; agreedDays.SpecialNotice = model.agreedDays.SpecialNotice; db.AgreedDays.Add(agreedDays); db.SaveChanges(); } return(PartialView("_ListAgreedDays", GetAgreedDaysOfCurrentToddler())); }
// This function will generate a list of all the days the toddler will come next month. /* * Get the Agreed days for nex month * Generate every day in the next month * Check if the toddler has to come that day * Add that day to the list */ private List <DateTime> getAllAgreedDaysInMonth(Toddler t, int year, int month) { List <DateTime> ADays = new List <DateTime>(); AgreedDays ADnextMonth = agreedDaysThatApply(t, year, month); int days = DateTime.DaysInMonth(year, month); for (int day = 1; day <= days; day++) { DateTime thisDay = new DateTime(year, month, day); if (thisDay >= ADnextMonth.StartDate && thisDay <= ADnextMonth.EndDate) { switch (thisDay.DayOfWeek) { case DayOfWeek.Monday: if (ADnextMonth.Monday == true) { ADays.Add(thisDay); } break; case DayOfWeek.Tuesday: if (ADnextMonth.Tuesday == true) { ADays.Add(thisDay); } break; case DayOfWeek.Wednesday: if (ADnextMonth.Wednesday == true) { ADays.Add(thisDay); } break; case DayOfWeek.Thursday: if (ADnextMonth.Thursday == true) { ADays.Add(thisDay); } break; case DayOfWeek.Friday: if (ADnextMonth.Friday == true) { ADays.Add(thisDay); } break; default: break; } } } return(ADays); }
// PUBLIC FUNCTIONS /// <summary> /// Create the first Invoice for the new Child. /// </summary> /// <param name="toddlerId"></param> public void CreateFirstInvoice(string toddlerId) { Toddler t = db.Toddlers.Find(toddlerId); AgreedDays ad = db.AgreedDays.Where(ads => ads.Toddler == t).OrderBy(add => add.StartDate).First(); Invoice firstInvoice = new Invoice(); firstInvoice.CreationDate = DateTime.Now; firstInvoice.Month = ad.StartDate.Month; firstInvoice.Year = ad.StartDate.Year; firstInvoice.Toddler = t; firstInvoice.NormalDaysNextMonth = getAllAgreedDaysInMonth(t, firstInvoice.Month, firstInvoice.Year).Count; firstInvoice.ExtraDaysThisMonth = 0; firstInvoice.DayCareClosedThisMonth = 0; firstInvoice.Payed = false; firstInvoice.HasSibling = false; firstInvoice.TotalAmount = 0; db.Invoices.Add(firstInvoice); db.SaveChanges(); }