public ActionResult Edit(Share share, int employeeId = 0) { PoolDataEntitiesConnection ctx = new PoolDataEntitiesConnection(); //if (!ctx.Employees.Any(e => e.Id == employeeId && e.Active == true)) //{ // ModelState.AddModelError("employeeId", "You must provide a valid employee ID in order to make this change"); //} if (ModelState.IsValid) { if (!ctx.Employees.Any(e => e.Id == employeeId && e.Active == true)) { Employee employee = ctx.Employees.Single(e => e.Id == employeeId); share.Notes = "Marked " + (share.Paid_Dues ? "paid" : "unpaid") + " by " + employee.FullName + ". Date " + DateTime.Now; db.Entry(share).State = EntityState.Modified; AuditLog log = new AuditLog() { date = DateTime.Now, message = "Share " + share.Id + " marked " + (share.Paid_Dues ? "paid" : "unpaid") + " by " + employee.FullName }; db.AuditLogs.Add(log); } else { share.Notes = "Marked " + (share.Paid_Dues ? "paid" : "unpaid") + " on date " + DateTime.Now; db.Entry(share).State = EntityState.Modified; } db.SaveChanges(); return RedirectToAction("Index"); } return View(share); }
public ActionResult ArchivePerson(int? id, int? delete) { PoolDataEntitiesConnection ctx = new PoolDataEntitiesConnection(); if (!ctx.People.Any(s => s.Id == delete)) { return RedirectToAction("Index"); } var person = ctx.People.Single(s => s.Id == delete); var family = person.Family; person.Family = null; family.People.Remove(person); if (family.People.Where(p=>p.Is_Guest == false).Count() == 0) { ModelState.AddModelError("id", "You must add another member first in order to remove this entry"); return Search(family.ShareFamilies.Single().Share.Id.ToString()); } AuditLog log = new AuditLog() { date = DateTime.Now, message = person.FullName + " removed from family " + family.FamilyName + ", family.id=" + family.Id + ", share=" + family.ShareFamilies.Single().Share.Id, personId = id }; ctx.AuditLogs.Add(log); if(ModelState.IsValid){ try { ctx.SaveChanges(); TempData["success"] = "Successfully archived person"; } catch (DbEntityValidationException e) { foreach (var eve in e.EntityValidationErrors) { foreach(var ve in eve.ValidationErrors) { ModelState.AddModelError(ve.PropertyName, ve.ErrorMessage); } } } } return Search(id.ToString()); }
public ActionResult ConfirmCheckin(int[] CheckinPeople, String[] PersonEmail, int TicketCount, int CashCount, int CreditCount) { PoolDataEntitiesConnection ctx = new PoolDataEntitiesConnection(); var checkinPersonObjects = new List<Person>(); foreach (var pid in CheckinPeople) { checkinPersonObjects.Add(ctx.People.Single(p => p.Id == pid)); } if((TicketCount + CashCount + CreditCount) != checkinPersonObjects.Count(p => p.Is_Guest == true)){ ModelState.AddModelError("CheckinPeople","Cash, ticket, and credit counts do not equal guest count"); } if (!checkinPersonObjects.First().Family.ShareFamilies.First().Share.Paid_Dues) { ModelState.AddModelError("CheckinPeople", "Member dues have not been paid! Please see an employee"); } var remainingTicket = TicketCount; var remainingCash = CashCount; var remainingCredit = CreditCount; for (int i = 0; i < CheckinPeople.Length; i++) { var personId = CheckinPeople[i]; Person person = ctx.People.Single(p => p.Id == personId); var entry = new Entry() { Entry_Person = personId, Time = DateTime.Now }; if (person.Is_Guest == true) { if (remainingTicket > 0) { entry.Entry_Type = "TICKET"; remainingTicket--; } else if (remainingCash > 0) { entry.Entry_Type = "CASH"; remainingCash--; } else if (remainingCredit > 0) { entry.Entry_Type = "CREDIT"; remainingCredit--; } AuditLog log = new AuditLog() { date = DateTime.Now, message = person.FullName + " used " + entry.Entry_Type, personId = personId }; ctx.AuditLogs.Add(log); } else { entry.Entry_Type = "MEMBER"; } ctx.Entries.Add(entry); try { if (!String.IsNullOrWhiteSpace(PersonEmail[i])) { MailAddress address = new MailAddress(PersonEmail[i]); person.Email = PersonEmail[i]; } } catch (Exception) { } } if (ModelState.IsValid) { ctx.SaveChanges(); TempData["success"] = "Successfully checked in"; return RedirectToAction("Index"); } return View("ConfirmCheckin", checkinPersonObjects); }
public ActionResult ArchiveGuest(int? Id) { PoolDataEntitiesConnection ctx = new PoolDataEntitiesConnection(); if (!ctx.People.Any(s => s.Id == Id && s.Is_Guest.HasValue && s.Is_Guest.Value)) { return RedirectToAction("Index"); } var person = ctx.People.Single(s => s.Id == Id && s.Is_Guest.HasValue && s.Is_Guest.Value); var family = person.Family; person.Family = null; family.People.Remove(person); AuditLog log = new AuditLog() { date = DateTime.Now, message = person.FullName + " removed from family " + family.FamilyName + ", family.id=" + family.Id + ", share=" + family.ShareFamilies.Single().Share.Id, personId = Id }; ctx.SaveChanges(); TempData["success"] = "Successfully archived guest"; return new JsonResult() { Data = new { Success = true } }; }