public ActionResult SetSuspension(string Id, SuspensionModel suspension) { Guid customerId = Guid.Parse(Id); dbContext.Suspensions.Add(suspension); // get all suspensions for current customer // todo: convert this into a separate utility function that can be used elsewhere // todo: optimization: weed out suspensions that ended in the past List <SuspensionModel> suspensions = dbContext.Suspensions .Where(sus => sus.CustomerId == customerId) .OrderBy(sus => sus.Start) .ToList(); suspensions.Add(suspension); // get next recurring pickup day PickUpModel pickUp = dbContext.PickUps .Where(pick => pick.CustomerId == customerId && pick.Recurring == true && pick.Completed == false) .FirstOrDefault(); // check that the recurring date conforms to all suspensions DetermineNextPickUpDay(suspensions, ref pickUp); dbContext.SaveChanges(); return(RedirectToAction("Details", new { Id = customerId })); }
public ActionResult DeleteConfirmed(Guid id) { PickUpModel pickUpModel = db.PickUps.Find(id); db.PickUps.Remove(pickUpModel); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult RegisterCustomer(RegisterCustomerViewModel model) { var address = new AddressModel { AddressId = Guid.NewGuid(), StreetAddress = model.StreetAddress, SecondaryAddress = model.SecondaryAddress, City = model.City, ZipCode = model.ZipCode, State = model.State }; dbContext.Addresses.Add(address); var customer = new CustomerModel { CustomerId = Guid.NewGuid(), FirstName = model.FirstName, LastName = model.LastName, Status = 0, PickUpDay = model.PickUpDay, BaseCost = model.BaseCost, ApplicationId = model.ApplicationId, AddressId = address.AddressId }; dbContext.Customers.Add(customer); var pickUp = new PickUpModel { PickUpId = Guid.NewGuid(), Pending = true, Completed = false, Recurring = true, Cost = model.BaseCost, Paid = false, CustomerId = customer.CustomerId }; // todo: move this logic elsewhere (used in CustomerController, as well for (int i = 1; i < 8; i++) { DayOfWeek dayOfWeek = DateTimeOffset.UtcNow.ToLocalTime().AddDays(i).DayOfWeek; if (dayOfWeek == model.PickUpDay) { pickUp.Scheduled = DateTimeOffset.UtcNow.ToLocalTime().AddDays(i).UtcDateTime; break; } } dbContext.PickUps.Add(pickUp); dbContext.SaveChanges(); return(RedirectToAction("Details", "Customer", new { Id = customer.CustomerId })); }
// private UpdatePickUpsForSuspensions CustomerId, new suspension dbContext private void DetermineNextPickUpDay(List <SuspensionModel> suspensions, ref PickUpModel pickUp) { foreach (SuspensionModel suspension in suspensions) { if (pickUp.Scheduled > suspension.Start && pickUp.Scheduled < suspension.End) { pickUp.Scheduled = DetermineNextAvailablePickUpDay(pickUp, suspension.End); } } }
public ActionResult EditStatus([Bind(Include = "ID,CustomerID,Price,PickUpStatus,ExtraPickUpStatus")] PickUpModel pickUpModel) { if (ModelState.IsValid) { db.Entry(pickUpModel).State = EntityState.Modified; db.SaveChanges(); return(RedirectToAction("EditBalance", pickUpModel)); } return(View(pickUpModel)); }
public ActionResult Create([Bind(Include = "PickUpId,Scheduled,Pending,Completed,Recurring,Cost,Paid,CustomerId")] PickUpModel pickUpModel) { if (ModelState.IsValid) { pickUpModel.PickUpId = Guid.NewGuid(); db.PickUps.Add(pickUpModel); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "FirstName", pickUpModel.CustomerId); return(View(pickUpModel)); }
public ActionResult CreateAddPickUp(PickUpModel pickUp) { try { dbContext.PickUps.Add(pickUp); dbContext.SaveChanges(); return(RedirectToAction("Details", "Customer", new { Id = pickUp.CustomerId })); } catch { return(View()); } }
// GET: PickUpModels/Delete/5 public ActionResult Delete(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PickUpModel pickUpModel = db.PickUps.Find(id); if (pickUpModel == null) { return(HttpNotFound()); } return(View(pickUpModel)); }
// GET: PickUpModels/Edit/5 public ActionResult Edit(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PickUpModel pickUpModel = db.PickUps.Find(id); if (pickUpModel == null) { return(HttpNotFound()); } ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "FirstName", pickUpModel.CustomerId); return(View(pickUpModel)); }
private DateTime DetermineNextAvailablePickUpDay(PickUpModel pickUp, DateTime startSearch) { DayOfWeek currentDayOfWeekPickUp = pickUp.Scheduled.DayOfWeek; for (int i = 2; i < 8; i++) { DayOfWeek dayOfWeekToCheck = startSearch.ToLocalTime().AddDays(i).DayOfWeek; if (dayOfWeekToCheck == currentDayOfWeekPickUp) { pickUp.Scheduled = startSearch.ToLocalTime().AddDays(i); break; } } return(pickUp.Scheduled); }
// GET: Customer/Create public ActionResult CreateAddPickUp(string Id) { var customerModel = dbContext.Customers.Find(Guid.Parse(Id)); var model = new PickUpModel { PickUpId = Guid.NewGuid(), Scheduled = DateTimeOffset.UtcNow.ToLocalTime().UtcDateTime, Pending = true, Completed = false, Recurring = false, Cost = customerModel.BaseCost, Paid = false, CustomerId = Guid.Parse(Id) }; return(View(model)); }
// GET: PickUpModels/Details/5 public ActionResult Details(Guid?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } PickUpModel pickUpModel = db.PickUps .Include(pick => pick.Customer) .Include(pick => pick.Customer.Address) .Where(pick => pick.PickUpId == id) .SingleOrDefault(); if (pickUpModel == null) { return(HttpNotFound()); } return(View(pickUpModel)); }
public ActionResult Edit([Bind(Include = "PickUpId,Scheduled,Pending,Completed,Recurring,Cost,Paid,CustomerId")] PickUpModel pickUpModel) { if (ModelState.IsValid) { db.Entry(pickUpModel).State = EntityState.Modified; db.SaveChanges(); var userId = User.Identity.GetUserId(); EmployeeModel employee = db.Employees .Where(emp => emp.ApplicationId == userId) .FirstOrDefault(); return(RedirectToAction("Index", new { Id = employee.EmployeeId })); } ViewBag.CustomerId = new SelectList(db.Customers, "CustomerId", "FirstName", pickUpModel.CustomerId); return(View(pickUpModel)); }
public ActionResult EditBalance([Bind(Include = "ID,Name,Email,Address,ZipcodeID,TrashDayID,ExtraID,ApplicationUserID,Balance")] Customer customer, PickUpModel pickUpModel) { if (pickUpModel.PickUpStatus == true) { var billCustomer = db.Customers.Where(b => b.ID == pickUpModel.CustomerID).FirstOrDefault(); billCustomer.Balance += pickUpModel.Price; db.SaveChanges(); return(RedirectToAction("CreateSchedule")); } return(RedirectToAction("CreateSchedule")); }