public void DeleteRecipeProduct(RecipeProductModels model, int ProductType) { using (var cxt = new NuWebContext()) { if (ProductType == (byte)Commons.EProductType.Dish) { var item = cxt.I_Recipe_Item.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.Status = (byte)Commons.EStatus.Deleted; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } else if (ProductType == (byte)Commons.EProductType.Modifier) { var item = cxt.I_Recipe_Modifier.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.Status = (byte)Commons.EStatus.Deleted; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } } }
public RecipeProductModels CheckInsertProduct(RecipeProductModels model, int ProductType, List <string> ListStoreId) { var item = new RecipeProductModels(); using (var cxt = new NuWebContext()) { RecipeProductModels itemDb = null; //Check StoreId | ProductId | IngredientId if (ProductType == (byte)Commons.EProductType.Dish) { itemDb = cxt.I_Recipe_Item.Where( s => s.StoreId.Equals(model.StoreId) && s.ItemId.Equals(model.ItemId) && s.IngredientId.Equals(model.IngredientId) && s.Status == (byte)Commons.EStatus.Actived && ListStoreId.Contains(s.StoreId) ).Select(x => new RecipeProductModels { Id = x.Id }).FirstOrDefault(); } else if (ProductType == (byte)Commons.EProductType.Modifier) { itemDb = cxt.I_Recipe_Modifier.Where( s => s.StoreId.Equals(model.StoreId) && s.ModifierId.Equals(model.ItemId) && s.IngredientId.Equals(model.IngredientId) && s.Status == (byte)Commons.EStatus.Actived && ListStoreId.Contains(s.StoreId) ).Select(x => new RecipeProductModels { Id = x.Id }).FirstOrDefault(); } if (itemDb != null) { item = itemDb; } return(itemDb); } //return null; }
public void UpdateRecipeProduct(RecipeProductModels model, int ProductType) { using (var cxt = new NuWebContext()) { try { if (ProductType == (byte)Commons.EProductType.Dish) { var item = cxt.I_Recipe_Item.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.UOMId = model.UOMId; item.Usage = model.Usage; item.BaseUsage = model.BaseUsage; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } else if (ProductType == (byte)Commons.EProductType.Modifier) { var item = cxt.I_Recipe_Modifier.Where(s => s.Id == model.Id).FirstOrDefault(); if (item != null) { item.UOMId = model.UOMId; item.Usage = model.Usage; item.BaseUsage = model.BaseUsage; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = DateTime.Now; cxt.SaveChanges(); } } } catch (Exception e) { _logger.Error("RecipeProduct_Update: " + e); } } }
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)); }
public void InsertRecipeProduct(RecipeProductModels model, int ProductType, ref string Id) { using (NuWebContext cxt = new NuWebContext()) { try { if (ProductType == (byte)Commons.EProductType.Dish) { I_Recipe_Item itemInsert = new I_Recipe_Item(); itemInsert.Id = Guid.NewGuid().ToString(); itemInsert.StoreId = model.StoreId; itemInsert.IngredientId = model.IngredientId; itemInsert.ItemId = model.ItemId; itemInsert.ItemName = model.ItemName; itemInsert.ItemType = model.ItemType; itemInsert.UOMId = model.UOMId; itemInsert.Usage = model.Usage; itemInsert.BaseUsage = model.BaseUsage; itemInsert.Status = (byte)Commons.EStatus.Actived; itemInsert.CreatedBy = model.CreatedBy; itemInsert.CreatedDate = model.CreatedDate; itemInsert.UpdatedBy = model.UpdatedBy; itemInsert.UpdatedDate = model.UpdatedDate; cxt.I_Recipe_Item.Add(itemInsert); Id = itemInsert.Id; } else if (ProductType == (byte)Commons.EProductType.Modifier) { I_Recipe_Modifier itemInsert = new I_Recipe_Modifier(); itemInsert.Id = Guid.NewGuid().ToString(); itemInsert.StoreId = model.StoreId; itemInsert.IngredientId = model.IngredientId; itemInsert.ModifierId = model.ItemId; itemInsert.ModifierName = model.ItemName; itemInsert.UOMId = model.UOMId; itemInsert.Usage = model.Usage; itemInsert.BaseUsage = model.BaseUsage; itemInsert.Status = (byte)Commons.EStatus.Actived; itemInsert.CreatedBy = model.CreatedBy; itemInsert.CreatedDate = model.CreatedDate; itemInsert.UpdatedBy = model.UpdatedBy; itemInsert.UpdatedDate = model.UpdatedDate; cxt.I_Recipe_Modifier.Add(itemInsert); Id = itemInsert.Id; } cxt.SaveChanges(); } catch (Exception e) { _logger.Error("RecipeProduct_Insert: " + e); } } }