public virtual IActionResult Edit(int id, UpdateMaterialModel model, bool continueEditing) { if (!_permissionService.Authorize(XrmsPermissionProvider.ManageMaterials)) { return(AccessDeniedView()); } var material = _materialService.GetMaterialById(id); if (material == null || material.Deleted) { //No material found with the specified id return(RedirectToAction("List")); } //check if the material quantity has been changed while we were editing the material //and if it has been changed then we show error notification //and redirect on the editing page without data saving /*if (material.StockQuantity != model.LastStockQuantity) * { * ErrorNotification(_localizationService.GetResource("Admin.Catalog.Materials.Fields.StockQuantity.ChangedWarning")); * return RedirectToAction("Edit", new { id = material.Id }); * }*/ if (ModelState.IsValid) { //some previously used values var previousWarehouseId = material.WarehouseId; var previousStockQuantity = material.StockQuantity; //material material = model.ToEntity(material); material.UpdatedOnUtc = DateTime.UtcNow; _materialService.UpdateMaterial(material); // quantity change history if (previousWarehouseId != material.WarehouseId) { //warehouse is changed //compose a message var oldWarehouseMessage = string.Empty; if (previousWarehouseId > 0) { var oldWarehouse = _shippingService.GetWarehouseById(previousWarehouseId); if (oldWarehouse != null) { oldWarehouseMessage = string.Format(_localizationService.GetResource("Xrms.Admin.Catalog.Materials.StockQuantityHistory.Messages.EditWarehouse.Old"), oldWarehouse.Name); } } var newWarehouseMessage = string.Empty; if (material.WarehouseId > 0) { var newWarehouse = _shippingService.GetWarehouseById(material.WarehouseId); if (newWarehouse != null) { newWarehouseMessage = string.Format(_localizationService.GetResource("Xrms.Admin.Catalog.Materials.StockQuantityHistory.Messages.EditWarehouse.New"), newWarehouse.Name); } } var message = string.Format(_localizationService.GetResource("Xrms.Admin.Catalog.Materials.StockQuantityHistory.Messages.EditWarehouse"), oldWarehouseMessage, newWarehouseMessage); //record history _materialService.AddStockQuantityHistoryEntry(material, -previousStockQuantity, 0, previousWarehouseId, message); _materialService.AddStockQuantityHistoryEntry(material, material.StockQuantity, material.StockQuantity, material.WarehouseId, message); } else { _materialService.AddStockQuantityHistoryEntry(material, material.StockQuantity - previousStockQuantity, material.StockQuantity, material.WarehouseId, _localizationService.GetResource("Xrms.Admin.Catalog.Materials.StockQuantityHistory.Messages.Edit")); } //activity log _customerActivityService.InsertActivity("EditMaterial", _localizationService.GetResource("Xrms.ActivityLog.EditMaterial"), material); SuccessNotification(_localizationService.GetResource("Xrms.Admin.Catalog.Materials.Notifications.Updated")); if (continueEditing) { //selected tab SaveSelectedTabName(); return(RedirectToAction("Edit", new { id = material.Id })); } return(RedirectToAction("List")); } //If we got this far, something failed, redisplay form var viewModel = new MaterialDetailsPageViewModel(); model.ToDetailsViewModel(viewModel); // groups PrepareAvailableMaterialGroups(viewModel); // warehouses PrepareAvailableWarehouses(viewModel); return(View("~/Plugins/Xrms/Areas/Admin/Views/Material/Edit.cshtml", viewModel)); }
public static Material ToEntity(this UpdateMaterialModel model, Material entity) { return(model.MapTo(entity)); }
public static MaterialDetailsPageViewModel ToDetailsViewModel(this UpdateMaterialModel model, MaterialDetailsPageViewModel viewModel) { return(model.MapTo(viewModel)); }
public static Material ToEntity(this UpdateMaterialModel model) { return(model.MapTo <UpdateMaterialModel, Material>()); }