コード例 #1
0
ファイル: UserManager.cs プロジェクト: AzerefA/asp_mvc_2.2
        public void AddUserAccount(UserModel user)
        {
            using (DemoDBEntities2 db = new DemoDBEntities2())
            {
                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.FirtsName            = 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();
                }
            }
        }
コード例 #2
0
ファイル: UserManager.cs プロジェクト: salsapr/asp_mvc_modul4
        public void DeleteUser(int userID)
        {
            using (DemoDBEntities2 db = new DemoDBEntities2())
            {
                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();
                    }
                }
            }
        }
コード例 #3
0
        public AddBook TambahBuku(AddBook Ku)
        {
            using (DemoDBEntities2 db = new DemoDBEntities2())
            {
                Buku Bu = new Buku();
                Bu.id_buku  = Ku.id_buku;
                Bu.judul    = Ku.judul;
                Bu.ISBN     = Ku.ISBN;
                Bu.penulis  = Ku.penulis;
                Bu.penerbit = Ku.penerbit;
                Bu.tahun    = Ku.tahun;
                Bu.stok     = Ku.stok;

                db.Bukus.Add(Bu);
                db.SaveChanges();
            }
            return(Ku);
        }
コード例 #4
0
ファイル: UserManager.cs プロジェクト: salsapr/asp_mvc_modul4
        public void UpdateUserAccount(UserProfileView user)
        {
            using (DemoDBEntities2 db = new DemoDBEntities2())
            {
                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();
                    }
                }
            }
        }