示例#1
0
        public void AddUserAccount(UserSignUpView user)
        {
            using (BonesAndFlowersDBEntities db = new BonesAndFlowersDBEntities())
            {
                SYSUser SU = new SYSUser
                {
                    UserName = user.UserName,
                    PasswordEncryptedText = user.Password,
                    RowCreatedSYSUserID   = user.SYSUserID > 0 ? user.SYSUserID : 1,
                    RowModifiedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1,
                    RowCreatedDateTime    = DateTime.Now,
                    RowModifiedDateTime   = DateTime.Now
                };

                db.SYSUsers.Add(SU);
                db.SaveChanges();

                SYSUserProfile SUP = new SYSUserProfile
                {
                    SYSUserID            = SU.SYSUserID,
                    Race                 = user.Race,
                    Class                = user.Class,
                    Country              = user.Country,
                    Gender               = user.Gender,
                    RowCreatedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1,
                    RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1,
                    RowCreatedDateTime   = DateTime.Now,
                    RowModifiedDateTime  = DateTime.Now
                };

                db.SYSUserProfiles.Add(SUP);
                db.SaveChanges();

                if (user.LOOKUPRoleID > 0)
                {
                    SYSUserRole SUR = new SYSUserRole
                    {
                        LOOKUPRoleID         = user.LOOKUPRoleID,
                        SYSUserID            = user.SYSUserID,
                        IsActive             = true,
                        RowCreatedSYSUserID  = user.SYSUserID > 0 ? user.SYSUserID : 1,
                        RowModifiedSYSUserID = user.SYSUserID > 0 ? user.SYSUserID : 1,
                        RowCreatedDateTime   = DateTime.Now,
                        RowModifiedDateTime  = DateTime.Now
                    };

                    db.SYSUserRoles.Add(SUR);
                    db.SaveChanges();
                }
            }
        }
示例#2
0
        public void DeleteUser(int userID)
        {
            using (BonesAndFlowersDBEntities db = new BonesAndFlowersDBEntities())
            {
                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 void UpdateUserAccount(UserProfileView user)
        {
            using (BonesAndFlowersDBEntities db = new BonesAndFlowersDBEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        SYSUser SU = db.SYSUsers.Find(user.SYSUserID);
                        SU.UserName = user.UserName;
                        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.Race                 = user.Race;
                            SUP.Class                = user.Class;
                            SUP.Country              = user.Country;
                            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();
                    }
                }
            }
        }