コード例 #1
0
        public void UpdateTicket(TicketProfileView ticket)
        {
            using (mwdEntities db = new mwdEntities())
            {
                using (var dbContextTransaction = db.Database.BeginTransaction())
                {
                    try
                    {
                        helpdesk HD = db.helpdesks.Find(ticket.ID);
                        HD.UserID               = ticket.UserID;
                        HD.SeverityID           = ticket.SeverityID;
                        HD.StatusID             = ticket.StatusID;
                        HD.DepartmentID         = ticket.DepartmentID;
                        HD.Comments             = ticket.Comments;
                        HD.RowModifiedSYSUserID = ticket.SYSUserID;
                        HD.RowModifiedDateTime  = DateTime.Now;

                        db.SaveChanges();
                        dbContextTransaction.Commit();
                    }
                    catch
                    {
                        dbContextTransaction.Rollback();
                    }
                }
            }
        }
コード例 #2
0
        public void AddUserAccount(UserSignUpView user)
        {
            using (mwdEntities db = new mwdEntities())
            {
                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 DeleteUser(int userID)
        {
            using (mwdEntities db = new mwdEntities())
            {
                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();
                    }
                }
            }
        }
コード例 #4
0
        public void AddTicket(TicketCreateView ticket)
        {
            using (mwdEntities db = new mwdEntities())
            {
                helpdesk HD = new helpdesk();
                HD.UserID               = ticket.UserID;
                HD.StatusID             = ticket.StatusID;
                HD.SeverityID           = ticket.SeverityID;
                HD.DepartmentID         = ticket.DepartmentID;
                HD.Comments             = ticket.Comments;
                HD.RowCreatedSYSUserID  = ticket.UserID > 0 ? ticket.UserID : 1;
                HD.RowModifiedSYSUserID = ticket.UserID > 0 ? ticket.UserID : 1;
                HD.RowCreatedDateTime   = DateTime.Now;
                HD.RowModifiedDateTime  = DateTime.Now;

                db.helpdesks.Add(HD);
                db.SaveChanges();
            }
        }
コード例 #5
0
        public void UpdateUserAccount(UserProfileView user)
        {
            using (mwdEntities db = new mwdEntities())
            {
                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();
                    }
                }
            }
        }