public void TambahPelanggan(TambahPelangganModel PelangganModel) { using (DemoDBEntities db = new DemoDBEntities()) { pelanggan p = new pelanggan(); p.alamat = PelangganModel.alamat; p.id_pelanggan = PelangganModel.id_pelanggan; p.nama = PelangganModel.nama; p.no_id = PelangganModel.no_id; p.no_tlp2 = PelangganModel.no_tlp2; p.no_tlp1 = PelangganModel.no_tlp1; db.pelanggans.Add(p); try { db.SaveChanges(); } catch (Exception ex) { String x = ""; foreach (var y in db.GetValidationErrors()) { x = x + y.ValidationErrors.First().PropertyName + " " + y.ValidationErrors.First().ErrorMessage; } throw new Exception(x); } } }
public void AddPelanggan(Pelanggan user) { using (DBOutbondEntities1 db = new DBOutbondEntities1()) { pelanggan PU = new pelanggan(); PU.no_id = user.no_id; PU.nama = user.nama; PU.alamat = user.alamat; PU.no_tlp = user.no_tlp; PU.no_tlp2 = user.no_tlp2; db.pelanggans.Add(PU); db.SaveChanges(); } }
public void AddCustomer(addCustomerView c) { using (DemoEntities1 db = new DemoEntities1()) { pelanggan p = new pelanggan(); p.no_id = c.no_id; p.nama = c.nama; p.alamat = c.alamat; p.no_tlp1 = c.no_tlp1; p.no_tlp2 = c.no_tlp2; db.pelanggans.Add(p); db.SaveChanges(); } }
public ActionResult EditCustomer( int id_pelanggan, string no_id, string nama, string alamat, string no_tlp1, string no_tlp2) { CustomerProfileView CPV = new CustomerProfileView(); CPV.id_pelanggan = id_pelanggan; CPV.no_id = no_id; CPV.nama = nama; CPV.alamat = alamat; CPV.no_tlp1 = no_tlp1; CPV.no_tlp2 = no_tlp2; using (DemoEntities1 db = new DemoEntities1()) { using (var dbContext = db.Database.BeginTransaction()) { try { pelanggan p = db.pelanggans.Find(id_pelanggan); p.alamat = CPV.alamat; p.nama = CPV.nama; p.no_id = CPV.no_id; p.no_tlp1 = CPV.no_tlp1; p.no_tlp2 = CPV.no_tlp2; db.SaveChanges(); dbContext.Commit(); } catch (Exception ex) { dbContext.Rollback(); } } } return(Json(new { success = true, id_pelanggan = CPV.id_pelanggan, no_id = CPV.no_id, nama = CPV.nama, alamat = CPV.alamat, no_tlp1 = CPV.no_tlp1, no_tlp2 = CPV.no_tlp2 })); }
public List <OrderProfileView> GetAllOrders() { List <OrderProfileView> orders = new List <OrderProfileView>(); using (DemoEntities1 db = new DemoEntities1()) { OrderProfileView OV; //var orderData = db.laporans.ToList(); ??? foreach (laporan l in db.laporans) { OV = new OrderProfileView(); OV.id_laporan = l.id_laporan; pelanggan pelanggan = db.pelanggans.Where(o => o.id_pelanggan.Equals(l.id_pelanggan)).FirstOrDefault(); OV.namapelanggan = pelanggan.nama; outbond outbond = db.outbonds.Where(o => o.id_outbond.Equals(l.id_outbond)).FirstOrDefault(); OV.namaoutbond = outbond.keterangan; OV.keterangan = l.keterangan; OV.tgl_akhir = (DateTime)l.tgl_akhir; OV.tgl_mulai = (DateTime)l.tgl_mulai; OV.tgl_pesan = (DateTime)l.tgl_pesan; OV.harga = l.harga; OV.quantity = l.quantity; OV.jumlah = l.jumlah; orders.Add(OV); } } orders.Reverse(); return(orders); }