public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } var pelanggan = _db.Pelanggans.Find(id); if (pelanggan == null) { return(HttpNotFound()); } var model = new PelangganViewModel { Alamat = pelanggan.Alamat, Hp = pelanggan.Hp, Kode = pelanggan.Kode, Nama = pelanggan.Nama, NoKtp = pelanggan.NoKtp }; return(View(model)); }
public ActionResult CreateEdit(PelangganViewModel model) { try { if (ModelState.IsValid) { if (PelangganDataAccess.Update(model)) { return(Json(new { success = true, message = "Succes" }, JsonRequestBehavior.AllowGet)); } else { return(Json(new { success = false, message = PelangganDataAccess.Message }, JsonRequestBehavior.AllowGet)); } } else { return(Json(new { success = false, message = "Pelase full fill required fields" }, JsonRequestBehavior.AllowGet)); } } catch (Exception ex) { return(Json(new { success = false, message = ex.Message }, JsonRequestBehavior.AllowGet)); { } } }
public PelangganForm(PelangganViewModel vm) { InitializeComponent(); if (vm.ModelPelanggan == null) { vm.ModelPelanggan = new Pelanggan(); } DataContext = vm; }
private void SimpanDataPelanggan(PelangganViewModel model) { var pelanggan = new Pelanggan { Alamat = model.Alamat, Hp = model.Hp, Nama = model.Nama, NoKtp = model.NoKtp }; _db.Pelanggans.Add(pelanggan); _db.SaveChanges(); }
public static bool Update(PelangganViewModel model) { bool result = true; try { using (var db = new TokoKonteks()) { if (model.Id == 0) { Mst_Pelanggan Plg = new Mst_Pelanggan(); Plg.Kode = model.Kode; Plg.Nama = model.Nama; Plg.Alamat = model.Alamat; Plg.NoHp = model.NoHp; Plg.Aktif = model.Aktif; Plg.DibuatOleh = "Test"; Plg.Dibuat = DateTime.Now; db.Mst_Pelanggan.Add(Plg); db.SaveChanges(); } else { Mst_Pelanggan Plg = db.Mst_Pelanggan.Where(o => o.Id == model.Id).FirstOrDefault(); if (Plg != null) { Plg.Kode = model.Kode; Plg.Nama = model.Nama; Plg.Alamat = model.Alamat; Plg.NoHp = model.NoHp; Plg.Aktif = model.Aktif; Plg.DiubahOleh = "Test"; Plg.Diubah = DateTime.Now; db.SaveChanges(); } } } } catch (Exception ex) { Message = ex.Message; result = false; } return(result); }
public PelangganView() { InitializeComponent(); vm = new PelangganViewModel(); vm.OnReload += () => { LstData.ItemsSource = null; LstData.ItemsSource = vm.DataPelanggan; if (form != null) { form.Close(); } vm.ModelPelanggan = null; }; DataContext = vm; }
public ActionResult Create(PelangganViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var pelanggan = new Pelanggan { Alamat = model.Alamat, Hp = model.Hp, Nama = model.Nama, NoKtp = model.NoKtp }; _db.Pelanggans.Add(pelanggan); _db.SaveChanges(); return(RedirectToAction("Index")); }
public static PelangganViewModel GetById(int id) { PelangganViewModel result = new PelangganViewModel(); using (var db = new TokoKonteks()) { result = (from Plg in db.Mst_Pelanggan where Plg.Id == id select new PelangganViewModel { Id = Plg.Id, Kode = Plg.Kode, Nama = Plg.Nama, Alamat = Plg.Alamat, NoHp = Plg.NoHp, Aktif = Plg.Aktif }).FirstOrDefault(); } return(result); }
public ActionResult Edit(PelangganViewModel model) { if (!ModelState.IsValid) { return(View(model)); } var pelanggan = new Pelanggan { Kode = model.Kode, Alamat = model.Alamat, Hp = model.Hp, Nama = model.Nama, NoKtp = model.NoKtp }; _db.Entry(pelanggan).State = EntityState.Modified; _db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult Edit(PelangganViewModel model) { return(CreateEdit(model)); }