public async Task <IActionResult> FillItem(int id, bool error, string errorMessage) { var model = new FillItemView(); model.Error = error; model.ErrorMessage = HttpUtility.UrlDecode(errorMessage); model.Fill = await _resourceOrdersService.GetOrderFillById(id); return(View(model)); }
public async Task <IActionResult> FillItem(FillItemInput data) { var model = new FillItemView(); if (data == null || data.Id == 0 || data.Units == null || data.Units.Count() <= 0) { model.Error = true; model.ErrorMessage = "There was an issue trying to process you fill. Please open the order and try the fill again."; return(View(model)); } var item = await _resourceOrdersService.GetOrderItemById(data.Id); if (item == null) { model.Error = true; model.ErrorMessage = "Unable to find this order. The order may be been closed or removed."; return(View(model)); } var order = await _resourceOrdersService.GetOrderById(item.ResourceOrderId); var settings = await _resourceOrdersService.GetSettingsByDepartmentId(order.DepartmentId); var department = _departmentsService.GetDepartmentById(order.DepartmentId); var fill = new ResourceOrderFill(); fill.ResourceOrderItemId = item.ResourceOrderItemId; fill.DepartmentId = DepartmentId; fill.FillingUserId = UserId; fill.ContactName = data.Name; fill.ContactNumber = data.Number; fill.Note = data.Note; fill.LeadUserId = data.LeadUserId; fill.FilledOn = DateTime.UtcNow; if (order.AutomaticFillAcceptance) { fill.Accepted = true; fill.AcceptedOn = DateTime.UtcNow; if (settings != null && settings.DefaultResourceOrderManagerUserId != null) { fill.AcceptedUserId = settings.DefaultResourceOrderManagerUserId; } else { fill.AcceptedUserId = department.ManagingUserId; } } fill.Units = new List <ResourceOrderFillUnit>(); foreach (var unit in data.Units) { var itemUnit = new ResourceOrderFillUnit(); itemUnit.UnitId = unit; fill.Units.Add(itemUnit); } var savedFill = await _resourceOrdersService.CreateFill(fill); return(Json(new { id = savedFill.ResourceOrderFillId, error = model.Error, errorMessage = HttpUtility.UrlEncode(model.ErrorMessage) })); }