public ActionResult Update(Models.EditableDataTableUpdateModel input) { HomeCareEntitledPeriod model = Repo.HomeCareEntitledPeriods.Select.Single(f => f.Id == input.id); if (model.EndDate.HasValue) { return(Content("The end date can't be changed.")); } var ed = input.value.Parse <DateTime>(); model.EndDate = ed.HasValue ? ed.Value.AddDays(1) : (DateTime?)null; if (this.Permissions.User.RoleId != (int)FixedRoles.Admin) { var lastReport = ccEntitiesExtensions.LastSubmittedHcRepDate(model.ClientId); if (model.EndDate < lastReport) { ModelState.AddModelError(string.Empty, "End Date cannot be within an already submitted Financial Report period."); } } TryValidateModel(model); if (ModelState.IsValid) { var rowsUpdated = Repo.SaveChanges(); if (model.EndDate.HasValue) { var cfs = db.CfsRows.FirstOrDefault(f => f.ClientId == model.ClientId && f.EndDate == null); if (cfs != null) { var lastDay = new DateTime(DateTime.Today.Year, DateTime.Today.Month, DateTime.DaysInMonth(DateTime.Today.Year, DateTime.Today.Month)); cfs.EndDate = lastDay; cfs.EndDateReasonId = db.CfsEndDateReasons.SingleOrDefault(f => f.Name == "A leave reason/leave date has been entered in the client details").Id; cfs.UpdatedById = this.CcUser.Id; try { db.SaveChanges(); } catch (Exception ex) { } } } } if (ModelState.IsValid) { return(Content("Success")); } else { return(Content(ModelState.ValidationErrorMessages().First())); } }
public static void AddHomeCarePeriod(string FirstName, DateTime from, DateTime to) { ccEntities context = new ccEntities(); var client = context.Clients.First(x => x.FirstName == FirstName); HomeCareEntitledPeriod hc = new HomeCareEntitledPeriod(); hc.ClientId = client.Id; hc.StartDate = from; hc.EndDate = to; hc.UpdatedAt = DateTime.Now; hc.UpdatedBy = GetAdminUser().Id; context.HomeCareEntitledPeriods.AddObject(hc); context.SaveChanges(); }
public ActionResult Create(HomeCareEntitledPeriod model) { if (!this.Permissions.CanUpdateExistingClient) { throw new InvalidOperationException(); } var client = db.Clients.Include(f => f.HomeCareEntitledPeriods).SingleOrDefault(f => f.Id == model.ClientId); if (model.StartDate < client.JoinDate) { ModelState.AddModelError(string.Empty, "Start Date cannot be earlier than client's join date."); } if (this.Permissions.User.RoleId != (int)FixedRoles.Admin) { var lastReport = ccEntitiesExtensions.LastSubmittedHcRepDate(model.ClientId); if (model.StartDate < lastReport) { ModelState.AddModelError(string.Empty, "Start Date cannot be within an already submitted Financial Report period."); } if (!Client.CanAddEligibility(client) || model.StartDate < ccEntitiesExtensions.ClientFirstApprovedDate(client.Id)) { ModelState.AddModelError(string.Empty, "You are not allowed to add eligibility for this client on this period."); } } if (ModelState.IsValid) { try { Repo.HomeCareEntitledPeriods.Add(model); var rowsUpdated = Repo.SaveChanges(); ViewBag.Success = true; return(View()); } catch (Exception ex) { ModelState.AddModelError("Exception", ex.Message); } } return(View()); }
public ActionResult Delete(int id, FormCollection collection) { try { var model = new HomeCareEntitledPeriod() { Id = id }; Repo.HomeCareEntitledPeriods.Attach(model); Repo.HomeCareEntitledPeriods.Remove(model); Repo.SaveChanges(); return(Content("ok")); } catch { return(Content("oh dear, oh dear!")); } }