public bool Delete(string Id, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { I_Ingredient_UOM itemDelete = (from tb in cxt.I_Ingredient_UOM where tb.Id == Id select tb).FirstOrDefault(); //cxt.I_Ingredient_UOM.Remove(itemDelete); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }
public bool Insert(List <IngredientUOMModels> models, ref string msg) { bool result = true; using (NuWebContext cxt = new NuWebContext()) { try { List <I_Ingredient_UOM> listInsert = new List <I_Ingredient_UOM>(); I_Ingredient_UOM item = null; foreach (var model in models) { item = new I_Ingredient_UOM(); item.Id = Guid.NewGuid().ToString(); item.IngredientId = model.IngredientId; item.UOMId = model.UOMId; item.BaseUOM = model.BaseUOM; item.ReceivingQty = model.ReceivingQty; item.CreatedBy = model.CreatedBy; item.CreatedDate = model.CreatedDate; item.UpdatedBy = model.UpdatedBy; item.UpdatedDate = model.UpdatedDate; item.IsActived = model.IsActived; listInsert.Add(item); } cxt.I_Ingredient_UOM.AddRange(listInsert); cxt.SaveChanges(); } catch (Exception ex) { _logger.Error(ex); result = false; } finally { if (cxt != null) { cxt.Dispose(); } } } return(result); }