예제 #1
0
 public void DeleteUser(int userID)
 {
     using (PerpustakaanEntities db = new PerpustakaanEntities())
     {
         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();
             }
         }
     }
 }
예제 #2
0
 public void AddUserAccount(UserSignUpView user)
 {
     using (PerpustakaanEntities db = new PerpustakaanEntities())
     {
         SYSUser SU = new SYSUser();
         SU.LoginName             = user.LoginName;
         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;
         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();
         }
     }
 }
예제 #3
0
 public void UpdateBuku(BukuView bv)
 {
     using (PerpustakaanEntities db = new PerpustakaanEntities())
     {
         buku bk = db.bukus.Find(bv.id_buku);
         bk.isbn     = bv.isbn;
         bk.judul    = bv.judul;
         bk.penulis  = bv.penulis;
         bk.penerbit = bv.penerbit;
         bk.tahun    = bv.tahun;
         bk.stok     = bv.stok;
         db.bukus.Add(bk);
         db.SaveChanges();
     }
 }
예제 #4
0
 public void DeleteBuku(int bukuID)
 {
     using (PerpustakaanEntities db = new PerpustakaanEntities())
     {
         using (var dbContextTransaction = db.Database.BeginTransaction())
         {
             try
             {
                 var bk = db.bukus.Where(o => o.id_buku == bukuID);
                 if (bk.Any())
                 {
                     db.bukus.Remove(bk.FirstOrDefault());
                     db.SaveChanges();
                 }
                 dbContextTransaction.Commit();
             }
             catch
             {
                 dbContextTransaction.Rollback();
             }
         }
     }
 }
예제 #5
0
 public void UpdateUserAccount(UserProfileView user)
 {
     using (PerpustakaanEntities db = new PerpustakaanEntities())
     {
         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();
             }
         }
     }
 }