public ActionResult Edit(IngredientModel model) { try { //====== if (!ModelState.IsValid) { model.GetFillData(CurrentUser.ListOrganizationId); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } model.UpdatedBy = CurrentUser.UserName; model.UpdatedDate = DateTime.Now; //====== model.ListIngSupplier = model.ListIngSupplier.Where(x => x.IsActived).ToList(); model.ListIngSupplierUnSelected = model.ListIngSupplierUnSelected.Where(x => x.IsActived).ToList(); model.ListIngSupplier.AddRange(model.ListIngSupplierUnSelected); //=============== model.ListIngUOM = model.ListIngUOM.Where(x => x.Status != (int)Commons.EStatus.Deleted).ToList(); List <string> listItemUOMOnData = _IngredientUOMFactory.GetDataForIngredient(model.Id).Select(x => x.Id).ToList(); var listIngUOMIdDelete = listItemUOMOnData.Where(a => !(model.ListIngUOM.Select(x => x.Id).ToList()).Any(a1 => a1 == a)).ToList(); //For Xero Ingredient model.ListStoreId = CurrentUser.ListStoreID; //============== string msg = ""; bool result = _factory.Update(model, listIngUOMIdDelete, ref msg); if (result) { return(RedirectToAction("Index")); } else { model.GetFillData(CurrentUser.ListOrganizationId); ModelState.AddModelError("CompanyId", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(msg)); Response.StatusCode = (int)HttpStatusCode.BadRequest; return(PartialView("_Edit", model)); } } catch (Exception ex) { model.GetFillData(CurrentUser.ListOrganizationId); _logger.Error(ex.Message); return(new HttpStatusCodeResult(400, ex.Message)); } }