private ProductCategoryEditModel RenderEditModel(IdentityProductCategory identity) { var editModel = new ProductCategoryEditModel(); editModel.Id = identity.Id; editModel.Name = identity.Name; editModel.Code = identity.Code; editModel.Status = identity.Status; return(editModel); }
private IdentityProductCategory ExtractEditFormData(ProductCategoryEditModel formData) { var myIdetity = new IdentityProductCategory(); myIdetity.Id = formData.Id; myIdetity.Name = formData.Name; myIdetity.Code = formData.Code; myIdetity.Status = formData.Status; return(myIdetity); }
public async Task <IActionResult> Save([FromBody] ProductCategoryEditModel model) { // Refresh roles in the model if validation fails //var temp = UserEditModel.Create(_db); //model.Roles = temp.Roles; if (model.ProductCategory == null) { return(BadRequest("The user could not be found.")); } try { var productCategoryId = model.ProductCategory.ID; var isNew = productCategoryId == 0; if (string.IsNullOrWhiteSpace(model.ProductCategory.Name)) { return(BadRequest("Name is mandatory.")); } //if (string.IsNullOrWhiteSpace(model.SelectedProductCategory)) //{ // return BadRequest("product category is mandatory."); //} var result = model.Save(_productCategoryRepository); if (result) { var res = UOW.SaveChanges(); if (res > 0) { return(Ok(Get(model.ProductCategory.ID))); } } var errorMessages = new List <string>(); return(BadRequest("The user could not be saved." + "<br/><br/>" + string.Join("<br />", errorMessages))); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
public ActionResult Edit(ProductCategoryEditModel model) { if (!ModelState.IsValid) { string messages = string.Join("; ", ModelState.Values .SelectMany(x => x.Errors) .Select(x => x.ErrorMessage + x.Exception)); this.AddNotification(messages, NotificationType.ERROR); return(View(model)); } try { //Extract data var info = ExtractEditFormData(model); var isSuccess = _mainStore.Update(info); //Clear cache CachingHelpers.ClearProductCategoryCache(); if (isSuccess) { this.AddNotification(ManagerResource.LB_UPDATE_SUCCESS, NotificationType.SUCCESS); } } catch (Exception ex) { this.AddNotification(NotifSettings.Error_SystemBusy, NotificationType.ERROR); logger.Error("Failed for Edit ProductCategory request: " + ex.ToString()); return(View(model)); } return(RedirectToAction("Edit/" + model.Id)); }
public ProductCategoryEditModel Get(int id) { return(ProductCategoryEditModel.GetById(_productCategoryRepository, id)); }
public ProductCategoryEditModel Add() { return(ProductCategoryEditModel.Create(_productCategoryRepository)); }