public static bool Update(TokoViewModel model) { bool result = true; try { using (var db = new PosContext()) { if (model.Id == 0) { Toko toko = new Toko(); toko.Id = model.Id; toko.Nama = model.Nama; toko.Alamat = model.Alamat; toko.NoTelp = model.NoTelp; toko.CreatedBy = "Rio"; toko.CreatedDate = DateTime.Now; db.Mst_Tokos.Add(toko); db.SaveChanges(); } else { Toko toko = db.Mst_Tokos.Where(o => o.Id == model.Id).FirstOrDefault(); if (toko != null) { toko.Nama = model.Nama; toko.Alamat = model.Alamat; toko.NoTelp = model.NoTelp; toko.ModifiedBy = "Rio"; toko.ModifiedDate = DateTime.Now; db.SaveChanges(); } } } } catch (Exception ex) { result = false; Message = ex.Message; } return(result); }
public static bool DeleteById(int id) { bool result = true; try { using (var db = new PosContext()) { Toko toko = db.Mst_Tokos.Where(d => d.Id == id).FirstOrDefault(); db.Mst_Tokos.Remove(toko); db.SaveChanges(); } } catch (Exception ex) { result = false; Message = ex.Message; } return(result); }