public void UpdateRecipeIngredient(RecipeIngredientModels model) { using (var cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { var item = cxt.I_Recipe_Ingredient.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(); transaction.Commit(); } } catch (Exception e) { _logger.Error("RecipeProduct_Update: " + e); transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } }
public void DeleteRecipeIngredient(RecipeIngredientModels model) { using (var cxt = new NuWebContext()) { var item = cxt.I_Recipe_Ingredient.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 void InsertRecipeIngredient(RecipeIngredientModels model, ref string Id) { using (NuWebContext cxt = new NuWebContext()) { using (var transaction = cxt.Database.BeginTransaction()) { try { I_Recipe_Ingredient itemInsert = new I_Recipe_Ingredient(); itemInsert.Id = Guid.NewGuid().ToString(); itemInsert.IngredientId = model.IngredientId; itemInsert.MixtureIngredientId = model.MixtureIngredientId; itemInsert.UOMId = model.UOMId; itemInsert.Usage = model.Usage; itemInsert.Status = (byte)Commons.EStatus.Actived; itemInsert.BaseUsage = model.BaseUsage; itemInsert.CreatedBy = model.CreatedBy; itemInsert.CreatedDate = model.CreatedDate; itemInsert.UpdatedBy = model.UpdatedBy; itemInsert.UpdatedDate = model.UpdatedDate; cxt.I_Recipe_Ingredient.Add(itemInsert); cxt.SaveChanges(); transaction.Commit(); Id = itemInsert.Id; } catch (Exception e) { _logger.Error("RecipeProduct_Insert: " + e); transaction.Rollback(); } finally { if (cxt != null) { cxt.Dispose(); } } } } }
public RecipeIngredientModels CheckInsertIngredient(RecipeIngredientModels model) { var item = new RecipeIngredientModels(); using (var cxt = new NuWebContext()) { RecipeIngredientModels itemDb = null; //Check MixtureIngredientId | IngredientId itemDb = cxt.I_Recipe_Ingredient.Where(s => s.MixtureIngredientId.Equals(model.MixtureIngredientId) && s.IngredientId.Equals(model.IngredientId) && s.Status == (byte)Commons.EStatus.Actived) .Select(x => new RecipeIngredientModels { Id = x.Id }).FirstOrDefault(); if (itemDb != null) { item = itemDb; } return(itemDb); } }
public ActionResult AddIngredientIngredient(RecipeIngredientIngredientViewModels data) { List <string> listUpdate = new List <string>(); List <RecipeProductModels> listInfo = new List <RecipeProductModels>(); data.ListItem = data.ListItem.Where(x => x.IsSelect).ToList(); int type = 0; foreach (var item in data.ListItem) { RecipeIngredientModels model = new RecipeIngredientModels { MixtureIngredientId = data.Id, UOMId = item.BaseUOM, IngredientId = item.IngredientId, 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.CheckInsertIngredient(model); 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.InsertRecipeIngredient(model, ref Id); listUpdate.Add(Id); } } else //Update { if (item.IsSelect) { model.UpdatedBy = CurrentUser.UserId; model.UpdatedDate = DateTime.Now; model.Id = itemDb.Id; _factory.UpdateRecipeIngredient(model); listUpdate.Add(itemDb.Id); } //else //{ // model.UpdatedBy = CurrentUser.UserId; // model.UpdatedDate = DateTime.Now; // model.Id = itemDb.Id; // _factory.DeleteRecipeIngredient(model); //} } } //=========== //Delete _factory.DeleteListIdRecipeIngredient(data.Id, listUpdate); //Response.StatusCode = (int)HttpStatusCode.BadRequest; return(new HttpStatusCodeResult(HttpStatusCode.OK)); }