public async Task <IActionResult> CreateBillableTimePost(CreateBillableTimeViewModel model, int Id) { var user = await _userManager.GetUserAsync(User); var settings = _context.SiteSettings.First(); var serviceOrder = _context.ServiceOrders.Where(so => so.Id == Id).First(); BillableTime billableTime = new BillableTime { Minutes = model.Minutes, ServiceOrder = serviceOrder, AddedBy = user, Cost = (((Math.Round(model.Minutes / 15.0) * 15)) * (settings.ChargeRate / 60.0)), WorkPerformed = model.WorkPerformed }; _context.Add(billableTime); var billedCosts = _context.BillableTime.Where(bt => bt.ServiceOrder == serviceOrder).ToList(); double total = 0; foreach (var cost in billedCosts) { total += Math.Round(((double)cost.Cost), 2); } serviceOrder.TotalCharge = total + billableTime.Cost; _context.Update(serviceOrder); await _context.SaveChangesAsync(); return(RedirectToAction("SeeBillableTimes", new { Id = Id })); }
public IActionResult CreateBillableTimeGet(int Id) { var serviceOrder = _context.ServiceOrders.Where(so => so.Id == Id).First(); CreateBillableTimeViewModel model = new CreateBillableTimeViewModel { ServiceOrder = serviceOrder }; return(View("BillableTime/CreateBillableTimeView", model)); }