public static bool Update(VarianViewModel model) { bool result = true; try { using (var db = new VapeContext()) { if (model.Id == 0) { Mst_Varian var = new Mst_Varian(); var.VarianCode = model.VarianCode; var.VarianName = model.VarianName; var.ItemCode = model.ItemCode; var.Country = model.Country; var.Strength = model.Strength; var.PGVG = model.PGVG; var.Size = model.Size; var.Price = model.Price; var.Unit = model.Unit; var.IsActive = model.IsActive; db.Mst_Varian.Add(var); db.SaveChanges(); } else { Mst_Varian var = db.Mst_Varian.Where(o => o.Id == model.Id).FirstOrDefault(); if (var != null) { var.VarianCode = model.VarianCode; var.VarianName = model.VarianName; var.ItemCode = model.ItemCode; var.Country = model.Country; var.Strength = model.Strength; var.PGVG = model.PGVG; var.Size = model.Size; var.Price = model.Price; var.Unit = model.Unit; var.IsActive = model.IsActive; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public static bool Delete(int id) { bool result = true; try { using (var db = new VapeContext()) { Mst_Varian var = db.Mst_Varian.Where(o => o.Id == id).FirstOrDefault(); if (var != null) { db.Mst_Varian.Remove(var); db.SaveChanges(); } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }