public BossListWorkOrderModel(WorkOrder workOrder) { Id = workOrder.Id; Customer = workOrder.Customer; Description = workOrder.Description; IsComplete = workOrder.IsComplete; Category = workOrder.Category == null ? string.Empty : workOrder.Category.Name; AssignedTo = workOrder.Crew == null ? "Unassigned" : workOrder.Crew.Name; Date = workOrder.Date.HasValue ? workOrder.Date.Value.ToString("dd-MMM-yyyy hh:mm tt") : string.Empty; Order = workOrder.Date.HasValue ? workOrder.Date.Value.Ticks : BossListWorkOrderModel.nextOrder++; Duration = workOrder.Duration; }
public ActionResult Index(WorkOrder input) { using(var context = new WorkOrderContext()) { input.Id = Guid.NewGuid(); context.WorkOrders.Add(input); if (input.Duration.EndsWith("d", StringComparison.InvariantCultureIgnoreCase)) { var duration = default(int); if (int.TryParse(input.Duration.Replace("d", ""), out duration)) { duration--; var days = 1; var date = input.Date.HasValue ? input.Date : (null as DateTime?); while (days <= duration) { if (date.HasValue) { date = date.Value.AddDays(1); if(date.Value.DayOfWeek == DayOfWeek.Saturday){ date = date.Value.AddDays(2); } if (date.Value.DayOfWeek == DayOfWeek.Sunday) { date = date.Value.AddDays(1); } } var nextWorkOrder = new WorkOrder { Id = Guid.NewGuid(), CategoryId=input.CategoryId, CrewId=input.CrewId, Customer=input.Customer, Description=input.Description, Duration=input.Duration, Date = date }; context.WorkOrders.Add(nextWorkOrder); days++; } } } context.SaveChanges(); return RedirectToAction("Index"); } }
public ActionResult Save(Guid? id, WorkOrder input) { using (var context = new WorkOrderContext()) { context.Entry(input).State = System.Data.EntityState.Modified; context.SaveChanges(); return RedirectToAction("Index"); } }