public ActionResult Create(ReceiptNoteModels model) { try { model.CreatedBy = CurrentUser.UserName; model.UpdatedBy = CurrentUser.UserName; model.ReceiptBy = CurrentUser.UserName; model.CreatedDate = DateTime.Now; model.UpdatedDate = DateTime.Now; model.ReceiptDate = DateTime.Now; model.ListPurchaseOrder.ForEach(x => { x.ListItem = x.ListItem.Where(z => !z.IsVisible).ToList(); }); string msg = ""; model.ListPurchaseOrder = model.ListPurchaseOrder.Where(x => x.ListItem.Count > 0 && x.Delete != (int)Commons.EStatus.Deleted).ToList(); //=================== if (!model.IsPurchaseOrder) { model.ListItem = model.ListItem.Where(x => x.Delete != (int)Commons.EStatus.Deleted).ToList(); foreach (var itemIngredient in model.ListItem) { int type = 0; double BaseUsage = _IngredientFactory.GetUsageUOMForIngredient(itemIngredient.IngredientId, itemIngredient.BaseUOMId, ref type); itemIngredient.BaseReceivingQty = type != 0 ? (BaseUsage * itemIngredient.Qty) : (1 * itemIngredient.Qty); } } List <string> lstStoreId = lstStore.Select(z => z.Value).ToList(); bool result = _factory.Insert(model, lstStoreId, ref msg); if (result) { return(RedirectToAction("Index")); } else { //model.GetListSupplierFromCompnay(listCompanyId); var ListSupplierInfo = GetListSuppliers(model.StoreId); var ListSupplier = new SelectList(ListSupplierInfo, "Id", "Name"); model.ListSupplier = ListSupplier.ToList(); ModelState.AddModelError("StoreId", msg); return(View(model)); } } catch (Exception ex) { NSLog.Logger.Error("ReceiptNote_Create: ", ex); return(new HttpStatusCodeResult(400, ex.Message)); } }
public ActionResult AddIngredient(RecipeProductIngredientViewModels data) { List <string> listUpdate = new List <string>(); List <string> listUpdateModifier = new List <string>(); List <RecipeProductModels> listInfo = new List <RecipeProductModels>(); int type = 0; data.ListItem = data.ListItem.Where(x => x.IsSelect).ToList(); foreach (var item in data.ListItem) { RecipeProductModels model = new RecipeProductModels { StoreId = data.StoreId, ItemId = data.ProductId, ItemName = data.ProductName, ItemType = (byte)Commons.EProductType.Dish, IngredientId = item.IngredientId, UOMId = item.BaseUOM, Usage = item.Usage, BaseUsage = item.Usage }; double BaseUsage = _IngredientFactory.GetUsageUOMForIngredient(model.IngredientId, model.UOMId, ref type); if (type != 0) { model.BaseUsage = (BaseUsage * model.Usage); } var itemDb = _factory.CheckInsertProduct(model, data.Type, listStoreId); if (itemDb == null) //Insert { if (item.IsSelect) { model.CreatedBy = CurrentUser.UserId; model.CreatedDate = DateTime.Now; model.UpdatedBy = CurrentUser.UserId; model.UpdatedDate = DateTime.Now; string Id = ""; _factory.InsertRecipeProduct(model, data.Type, ref Id); if (data.Type == (byte)Commons.EProductType.Dish) { listUpdate.Add(Id); } else if (data.Type == (byte)Commons.EProductType.Modifier) { listUpdateModifier.Add(Id); } } } else //Update { if (item.IsSelect) { model.UpdatedBy = CurrentUser.UserId; model.UpdatedDate = DateTime.Now; model.Id = itemDb.Id; _factory.UpdateRecipeProduct(model, data.Type); if (data.Type == (byte)Commons.EProductType.Dish) { listUpdate.Add(itemDb.Id); } else if (data.Type == (byte)Commons.EProductType.Modifier) { listUpdateModifier.Add(itemDb.Id); } } //else //{ // model.UpdatedBy = CurrentUser.UserId; // model.UpdatedDate = DateTime.Now; // model.Id = itemDb.Id; // _factory.DeleteRecipeProduct(model, data.Type); //} } } //Delete if (data.Type == (byte)Commons.EProductType.Dish) { _factory.DeleteListIdRecipeProduct(data.ProductId, data.StoreId, listUpdate, (byte)Commons.EProductType.Dish); } else if (data.Type == (byte)Commons.EProductType.Modifier) { _factory.DeleteListIdRecipeProduct(data.ProductId, data.StoreId, listUpdateModifier, (byte)Commons.EProductType.Modifier); } //Response.StatusCode = (int)HttpStatusCode.BadRequest; return(new HttpStatusCodeResult(HttpStatusCode.OK)); }