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)); } }
public ActionResult Create() { IngredientModel model = new IngredientModel(); model.ReceivingQty = 1; model.GetFillData(CurrentUser.ListOrganizationId); return(View(model)); }
public ActionResult Create(IngredientModel model) { try { if (!ModelState.IsValid) { model.GetFillData(CurrentUser.ListOrganizationId); return(View(model)); } model.CreatedBy = CurrentUser.UserName; model.UpdatedBy = CurrentUser.UserName; model.CreatedDate = DateTime.Now; model.UpdatedDate = DateTime.Now; model.ListIngUOM = model.ListIngUOM.Where(x => x.Status != (int)Commons.EStatus.Deleted).ToList(); model.ListIngSupplier = model.ListIngSupplier.Where(x => x.IsActived).ToList(); //For Xero Ingredient model.ListStoreId = CurrentUser.ListStoreID; //============== string msg = ""; bool result = _factory.Insert(model, ref msg); if (result) { return(RedirectToAction("Index")); } else { model.GetFillData(CurrentUser.ListOrganizationId); ModelState.AddModelError("CompanyId", _AttributeForLanguage.CurrentUser.GetLanguageTextFromKey(msg)); return(View(model)); } } catch (Exception ex) { _logger.Error(ex.Message); return(new HttpStatusCodeResult(400, ex.Message)); } }
public IngredientModel GetDetail(string id) { try { IngredientModel model = _factory.GetIngredientById(id); if (!string.IsNullOrEmpty(model.CompanyId)) { model.CompanyName = lstCompany.Where(z => z.Value.Equals(model.CompanyId)).FirstOrDefault().Text; } else { model.CompanyName = "None"; } model.GetFillData(CurrentUser.ListOrganizationId); //============= var ListIngUOM = _IngredientUOMFactory.GetDataForIngredient(model.Id); for (int i = 0; i < ListIngUOM.Count; i++) { var IngUOM = ListIngUOM[i]; model.ListIngUOM.Add(new IngredientUOMModels { Id = IngUOM.Id, OffSet = i, UOMId = IngUOM.UOMId, ReceivingQty = IngUOM.ReceivingQty, UOMName = IngUOM.UOMName }); } var ListIngSup = _IngredientSupplierFactory.GetDataForIngredient(model.Id, model.CompanyId); var lstSupplierItem = _SupplierFactory.GetData(); lstSupplierItem = lstSupplierItem.Where(x => x.CompanyId.Equals(model.CompanyId)).ToList(); if (lstSupplierItem != null) { foreach (SupplierModels supplier in lstSupplierItem) { model.ListIngSupplier.Add(new Ingredients_SupplierModel { Id = supplier.Id, SupplierName = supplier.Name, SupplierAddress = supplier.Address, SupplierPhone = supplier.Phone1 + " - " + supplier.Phone2, //IsCheck = false, IsActived = ListIngSup.Any(x => x.Equals(supplier.Id)), CompanyId = supplier.CompanyId }); } model.ListIngSupplier = model.ListIngSupplier.OrderBy(oo => oo.SupplierName).ToList(); } //model.ListIngSupplier.ForEach(x => //{ // x.IsCheck = ListIngSup.Any(z => z.Equals(x.Id)); //}); model.ListIngSupplier = model.ListIngSupplier.Where(x => x.IsActived).OrderByDescending(x => x.IsActived ? 1 : 0).ThenBy(x => x.IngredientName).ToList(); return(model); } catch (Exception ex) { _logger.Error("IngredienDetail: " + ex); return(null); } }