public void AddUserAccount(UserSignUpView user) { using (DemoEntities1 db = new DemoEntities1()) { SYSUser SU = new SYSUser(); SU.LoginName = user.LoginName; //TODO : Implement Base64 Encode. SU.PasswordEncryptedText = user.Password; SU.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; SU.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; SU.RowCreatedDateTime = DateTime.Now; SU.RowMOdifiedDateTime = DateTime.Now; //Commit Change. db.SYSUsers.Add(SU); db.SaveChanges(); SYSUserProfile SUP = new SYSUserProfile(); SUP.SYSUserID = SU.SYSUserID; SUP.FirstName = user.FirstName; SUP.LastName = user.LastName; SUP.Gender = user.Gender; SUP.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; SUP.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; SUP.RowCreatedDateTime = DateTime.Now; SUP.RowModifiedDateTime = DateTime.Now; db.SYSUserProfiles.Add(SUP); db.SaveChanges(); if (user.LOOKUPRoleID > 0) { SYSUserRole SUR = new SYSUserRole(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; SUR.RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; db.SYSUserRoles.Add(SUR); db.SaveChanges(); } } }
public void Update(MT_SellOut entity, params Expression <Func <T, object> >[] updatedProperties) { using (var ctx = new DemoEntities1()) { ctx.MT_SellOut.Attach(entity); var entry = ctx.Entry(entity); entry.Property(e => e.Perform).IsModified = true; entry.Property(e => e.Rate).IsModified = true; ctx.SaveChanges(); } //if (updatedProperties.Any()) //{ // foreach (var property in updatedProperties) // { // entry.Property(property).IsModified = true; // db.SaveChanges(); // } //} //else //{ // foreach (var property in entry.OriginalValues.PropertyNames) // { // var original = entry.OriginalValues.GetValue<object>(property); // var current = entry.CurrentValues.GetValue<object>(property); // if (original != null && !original.Equals(current)) // entry.Property(property).IsModified = true; // } //} //var dbEntityEntry = db.Entry(entity); }
//[AuthorizeRoles("Admin")] public ActionResult DeleteOrder(int orderID) { using (DemoEntities1 db = new DemoEntities1()) { using (var dbContext = db.Database.BeginTransaction()) { try { var or = db.laporans.Where(o => o.id_laporan.Equals(orderID)); if (or.Any()) { db.laporans.Remove(or.FirstOrDefault()); db.SaveChanges(); } dbContext.Commit(); } catch (Exception ex) { dbContext.Rollback(); } } } return(Json(new { success = true })); }
public void Addoutbond(addoutbondView m) { using (DemoEntities1 db = new DemoEntities1()) { outbond mn = new outbond(); mn.harga = m.harga; mn.keterangan = m.keterangan; db.outbonds.Add(mn); db.SaveChanges(); } }
public void Add(T entity) { table.Add(entity); try { db.SaveChanges(); } catch (System.Data.Entity.Validation.DbEntityValidationException dbEx) { Exception raise = dbEx; foreach (var validationErrors in dbEx.EntityValidationErrors) { foreach (var validationError in validationErrors.ValidationErrors) { string message = string.Format("{0}:{1}", validationErrors.Entry.Entity.ToString(), validationError.ErrorMessage); // raise a new exception nesting // the current instance as InnerException raise = new InvalidOperationException(message, raise); } } throw raise; } }
public void DeleteUser(int userID) { using (DemoEntities1 db = new DemoEntities1()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { var SUR = db.SYSUserRoles.Where(o => o.SYSUserID == userID); if (SUR.Any()) { db.SYSUserRoles.Remove(SUR.FirstOrDefault()); db.SaveChanges(); } var SUP = db.SYSUserProfiles.Where(o => o.SYSUserID == userID); if (SUP.Any()) { db.SYSUserProfiles.Remove(SUP.FirstOrDefault()); db.SaveChanges(); } var SU = db.SYSUsers.Where(o => o.SYSUserID == userID); if (SU.Any()) { db.SYSUsers.Remove(SU.FirstOrDefault()); db.SaveChanges(); } dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }
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 })); }
// //[AuthorizeRoles("Admin")] public ActionResult DeleteCustomer(int id_pelanggan) { using (DemoEntities1 db = new DemoEntities1()) { using (var dbContext = db.Database.BeginTransaction()) { try { var mn = db.pelanggans.Where(o => o.id_pelanggan.Equals(id_pelanggan)); if (mn.Any()) { db.pelanggans.Remove(mn.FirstOrDefault()); db.SaveChanges(); } dbContext.Commit(); } catch (Exception ex) { dbContext.Rollback(); } } } return(Json(new { success = true })); }
public void AddOrder(addOrderView m) { using (DemoEntities1 db = new DemoEntities1()) { outbond mn = db.outbonds.Find(m.id_outbond); mn.harga = mn.harga; mn.id_outbond = mn.id_outbond; mn.keterangan = mn.keterangan; laporan lp = new laporan(); lp.id_outbond = m.id_outbond; lp.id_pelanggan = m.id_pelanggan; lp.keterangan = m.keterangan; lp.tgl_akhir = m.tgl_akhir; lp.tgl_mulai = m.tgl_mulai; lp.tgl_pesan = m.tgl_pesan; lp.quantity = m.quantity; lp.harga = m.harga; lp.jumlah = m.jumlah; db.laporans.Add(lp); db.SaveChanges(); } }
//[AuthorizeRoles("Admin")] public ActionResult UpdateoutbondData(int id_outbond, string keterangan, int harga) { outbondProfileView MPV = new outbondProfileView(); MPV.id_outbond = id_outbond; MPV.keterangan = keterangan; MPV.harga = harga; using (DemoEntities1 db = new DemoEntities1()) { using (var dbContext = db.Database.BeginTransaction()) { try { outbond m = db.outbonds.Find(MPV.id_outbond); m.keterangan = MPV.keterangan; m.harga = MPV.harga; db.SaveChanges(); dbContext.Commit(); } catch (Exception ex) { dbContext.Rollback(); } } } return(Json(new { success = true, id_outbond = MPV.id_outbond, keterangan = MPV.keterangan, harga = MPV.harga })); }
public void UpdateUserAccount(UserProfileView user) { using (DemoEntities1 db = new DemoEntities1()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { SYSUser SU = db.SYSUsers.Find(user.SYSUserID); SU.LoginName = user.LoginName; SU.PasswordEncryptedText = user.Password; SU.RowCreatedSYSUserID = user.SYSUserID; SU.RowModifiedSYSUserID = user.SYSUserID; SU.RowCreatedDateTime = DateTime.Now; SU.RowMOdifiedDateTime = DateTime.Now; db.SaveChanges(); var userProfile = db.SYSUserProfiles.Where(o => o.SYSUserID == user.SYSUserID); if (userProfile.Any()) { SYSUserProfile SUP = userProfile.FirstOrDefault(); SUP.SYSUserID = SU.SYSUserID; SUP.FirstName = user.FirstName; SUP.LastName = user.LastName; SUP.Gender = user.Gender; SUP.RowCreatedSYSUserID = user.SYSUserID; SUP.RowModifiedSYSUserID = user.SYSUserID; SUP.RowCreatedDateTime = DateTime.Now; SUP.RowModifiedDateTime = DateTime.Now; db.SaveChanges(); } if (user.LOOKUPRoleID > 0) { var userRole = db.SYSUserRoles.Where(o => o.SYSUserID == user.SYSUserID); SYSUserRole SUR = null; if (userRole.Any()) { SUR = userRole.FirstOrDefault(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID; SUR.RowModifiedSYSUserID = user.SYSUserID; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; } else { SUR = new SYSUserRole(); SUR.LOOKUPRoleID = user.LOOKUPRoleID; SUR.SYSUserID = user.SYSUserID; SUR.IsActive = true; SUR.RowCreatedSYSUserID = user.SYSUserID; SUR.RowModifiedSYSUserID = user.SYSUserID; SUR.RowCreatedDateTime = DateTime.Now; SUR.RowModifiedDateTime = DateTime.Now; db.SYSUserRoles.Add(SUR); } db.SaveChanges(); } dbContextTransaction.Commit(); } catch { dbContextTransaction.Rollback(); } } } }