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 <CustomerProfileView> GetAllCustomers() { List <CustomerProfileView> customers = new List <CustomerProfileView>(); using (DemoEntities1 db = new DemoEntities1()) { CustomerProfileView CV; var customer = db.pelanggans.ToList(); foreach (pelanggan p in db.pelanggans) { CV = new CustomerProfileView(); CV.id_pelanggan = p.id_pelanggan; CV.no_id = p.no_id; CV.nama = p.nama; CV.alamat = p.alamat; CV.no_tlp1 = p.no_tlp1; CV.no_tlp2 = p.no_tlp2; customers.Add(CV); } return(customers); } }
public List <CustomerProfileView> GetAllCustomerProfiles() { List <CustomerProfileView> profiles = new List <CustomerProfileView>(); using (CMSProjectEntities db = new CMSProjectEntities()) { CustomerProfileView CPV; var users = db.Users.ToList(); foreach (User u in db.Users) { CPV = new CustomerProfileView(); CPV.UserID = u.UserID; CPV.Username = u.Username; CPV.Password = u.Password; var UP = db.UserProfiles.Where(o => o.UserID.Equals(CPV.UserID)).FirstOrDefault(); CPV.UserProfileID = UP.UserProfileID; CPV.FirstName = UP.FirstName; CPV.LastName = UP.LastName; CPV.Gender = UP.Gender; CPV.BirthDate = Convert.ToDateTime(UP.BirthDate).ToString("yyyy-MM-dd"); CPV.Mobile = UP.Mobile; CPV.Email = UP.Email; CPV.RoleID = UP.RoleID; var uRole = db.UserRoles.Where(o => o.RoleID.Equals(CPV.RoleID)).FirstOrDefault(); CPV.RoleName = uRole.RoleName; if (CPV.RoleName == "Customer") { CPV.Active = db.CustomerUsers.Where(o => o.UserID.Equals(CPV.UserID)).FirstOrDefault().Active; profiles.Add(CPV); } } } return(profiles); }