public void UpdateStatusUser(string id, UserModel model)
        {
            db = new TimeAttendanceEntities();
            var objectUpdate = db.User.Find(id);

            if (objectUpdate == null)
            {
                throw new BusinessException(ErrorMessage.ERR002);
            }

            var group = (from a in db.Group.AsNoTracking()
                         where a.Status == Constants.Lock
                         join b in db.UserGroup.AsNoTracking() on a.GroupId equals b.GroupId
                         where b.UserId.Equals(id)
                         select a).ToList();

            if (group.Count() > 0 && objectUpdate.Status.HasValue && objectUpdate.Status.Value == Constants.Lock)
            {
                throw new BusinessException(ErrorMessage.ERR004);
            }


            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    objectUpdate.Status = (objectUpdate.Status.HasValue && objectUpdate.Status.Value == Constants.Lock ? Constants.UnLock : Constants.Lock);

                    //Xóa Tokens khi khóa tài khoản
                    if (objectUpdate.Status == Constants.Lock)
                    {
                        var deleteAuth = authContext.RefreshTokens.Where(r => r.Subject.Equals(objectUpdate.Name));
                        authContext.RefreshTokens.RemoveRange(deleteAuth);
                        authContext.SaveChanges();
                    }
                    db.SaveChanges();
                    trans.Commit();

                    //luu Log lich su
                    string decription = "Cập nhật trạng thái có tên là: " + objectUpdate.Name;
                    LogBusiness.SaveLogEvent(db, model.UserId, decription, null);
                    //xóa cache
                    //   var RedisConnection = System.Configuration.ConfigurationManager.AppSettings["RedisConnection"];

                    var redis = RedisService <LoginCacheModel> .GetInstance(RedisConnection);

                    LoginCacheModel RefreshToken;
                    RefreshToken = redis.Get <LoginCacheModel>(Constants.ATLogin + objectUpdate.Name);
                    if (RefreshToken != null)
                    {
                        redis.Remove(Constants.ATLogin + objectUpdate.Name);
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
        public void SelfUpdateInfo(UserModel model)
        {
            db = new TimeAttendanceEntities();
            var modelEdit = db.User.Where(r => r.UserId.Equals(model.UserId) && r.DeleteFlg == Constants.DeleteFalse).FirstOrDefault();

            if (modelEdit == null)
            {
                throw new BusinessException(ErrorMessage.ERR003);
            }
            if (modelEdit.Name != model.Name)
            {
                if (this.IsExistedUser(model.Name))
                {
                    throw new BusinessException(ErrorMessage.ERR002);
                }
            }

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var userNameOld = modelEdit.Name;

                    modelEdit.FullName    = model.FullName;
                    modelEdit.BirthDay    = model.BirthDay;
                    modelEdit.Email       = model.Email;
                    modelEdit.PhoneNumber = model.PhoneNumber;
                    modelEdit.Role        = model.Role;
                    modelEdit.Agency      = model.Agency;
                    modelEdit.ImageLink   = model.ImageLink;
                    modelEdit.UpdateBy    = model.UpdateBy;
                    modelEdit.UpdateDate  = DateTime.Now;

                    if (!string.IsNullOrEmpty(model.GroupId))
                    {
                        var itemDelete = db.UserGroup.Where(r => r.UserId.Equals(model.UserId));
                        db.UserGroup.RemoveRange(itemDelete);
                        UserGroup userGroup = new UserGroup()
                        {
                            UserGroupId = Guid.NewGuid().ToString(),
                            GroupId     = model.GroupId,
                            UserId      = model.UserId,
                        };
                        db.UserGroup.Add(userGroup);
                    }

                    string decription = "Cập nhật thông tin cá nhân";
                    LogBusiness.SaveLogEvent(db, model.LogUserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
Exemplo n.º 3
0
        public void CreateGroup(GroupModel model)
        {
            db = new TimeAttendanceEntities();

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    Group modelCreate = new Group()
                    {
                        GroupId     = Guid.NewGuid().ToString(),
                        Name        = model.Name,
                        HomePage    = model.HomePage,
                        Status      = Constants.UnLock,
                        Description = model.Description,
                        CreateBy    = model.CreateBy,
                        CreateDate  = DateTime.Now,
                    };
                    db.Group.Add(modelCreate);

                    //Thêm dánh sách quyền cho nhóm
                    List <GroupPermission> listPermission = new List <GroupPermission>();
                    GroupPermission        modelPermission;
                    if (model.ListPermission != null && model.ListPermission.Count() > 0)
                    {
                        foreach (var item in model.ListPermission)
                        {
                            modelPermission = new GroupPermission()
                            {
                                GroupPermissionId = Guid.NewGuid().ToString(),
                                GroupId           = modelCreate.GroupId,
                                FunctionId        = item.FunctionId,
                            };
                            listPermission.Add(modelPermission);
                        }
                        db.GroupPermission.AddRange(listPermission);
                    }

                    //luu Log lich su
                    string decription = "Thêm mới nhóm quyền có tên là : " + modelCreate.Name;
                    LogBusiness.SaveLogEvent(db, model.UserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
Exemplo n.º 4
0
        public void UpdateStatusGroup(string id, GroupModel model)
        {
            db = new TimeAttendanceEntities();

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var objectUpdate = db.Group.Find(id);
                    if (objectUpdate != null)
                    {
                        //Cập nhật trạng thái nhóm
                        objectUpdate.Status = (objectUpdate.Status.HasValue && objectUpdate.Status.Value == Constants.Lock ? Constants.UnLock : Constants.Lock);

                        //Cập nhật trạng thái thành viên trong nhóm
                        var  userGroupsUpdate = db.UserGroup.Where(r => r.GroupId.Equals(id));
                        var  listUser         = db.User;
                        User userUpdate;
                        foreach (var item in userGroupsUpdate)
                        {
                            userUpdate = listUser.Where(r => r.UserId.Equals(item.UserId)).FirstOrDefault();
                            if (userUpdate != null)
                            {
                                userUpdate.Status = objectUpdate.Status;
                            }

                            //Xóa Tokens khi khóa tài khoản
                            if (objectUpdate.Status == Constants.Lock)
                            {
                                var deleteAuth = authContext.RefreshTokens.Where(r => r.Subject.Equals(userUpdate.Name));
                                authContext.RefreshTokens.RemoveRange(deleteAuth);
                                authContext.SaveChanges();
                            }
                        }
                    }

                    //luu Log lich su
                    string decription = "Cập nhật trạng thái nhóm có tên là: " + objectUpdate.Name;
                    LogBusiness.SaveLogEvent(db, model.UserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
        public void DeleteUser(string id, UserModel model)
        {
            db = new TimeAttendanceEntities();
            var objectDelete = db.User.Where(r => r.UserId.Equals(id) && r.DeleteFlg == Constants.DeleteFalse);

            if (objectDelete == null)
            {
                throw new BusinessException(ErrorMessage.ERR003);
            }
            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var type     = objectDelete.FirstOrDefault().Type;
                    var userName = objectDelete.FirstOrDefault().Name;

                    //Xóa Tokens
                    var deleteAuth = authContext.RefreshTokens.Where(r => r.Subject.Equals(userName));
                    authContext.RefreshTokens.RemoveRange(deleteAuth);
                    authContext.SaveChanges();

                    //Xóa logic tài khoản, gán lại cờ Delete = true
                    objectDelete.First().DeleteFlg = Constants.DeleteTrue;

                    //luu Log lich su
                    string decription = "Xóa thông tin có tên là: " + userName;
                    LogBusiness.SaveLogEvent(db, model.LogUserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();

                    //xóa cache
                    // var RedisConnection = System.Configuration.ConfigurationManager.AppSettings["RedisConnection"];
                    var redis = RedisService <LoginCacheModel> .GetInstance(RedisConnection);

                    LoginCacheModel RefreshToken;
                    RefreshToken = redis.Get <LoginCacheModel>(Constants.ATLogin + userName);
                    if (RefreshToken != null)
                    {
                        redis.Remove(Constants.ATLogin + userName);
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
        public void ChangePass(UserModel model)
        {
            db = new TimeAttendanceEntities();

            var modelChange = db.User.Where(r => r.UserId.Equals(model.UserId)).FirstOrDefault();

            //Kiểm tra tồn tại
            if (modelChange == null)
            {
                throw new BusinessException(ErrorMessage.ERR003);
            }

            //Check mật khẩu cũ nhập
            var securityStamp = PasswordUtil.ComputeHash(model.OldPassword + modelChange.Password);

            if (!modelChange.PasswordHash.Equals(securityStamp))
            {
                throw new BusinessException(ErrorMessage.ERR007);
            }
            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    modelChange.PasswordHash = PasswordUtil.ComputeHash(model.NewPassword + modelChange.Password);

                    //luu Log lich su
                    string decription = "Thay đổi mật khẩu cá nhân";
                    LogBusiness.SaveLogEvent(db, model.UserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();
                    //xóa cache
                    var redis = RedisService <LoginCacheModel> .GetInstance(RedisConnection);

                    LoginCacheModel RefreshToken;
                    RefreshToken = redis.Get <LoginCacheModel>(Constants.ATLogin + modelChange.Name);
                    if (RefreshToken != null)
                    {
                        redis.Remove(Constants.ATLogin + modelChange.Name);
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
Exemplo n.º 7
0
        public void DeleteGroupUser(string id, GroupModel model)
        {
            db = new TimeAttendanceEntities();

            //Xóa nhóm
            var objectDelete = db.Group.Where(r => r.GroupId.Equals(id));
            var nameGroup    = string.Empty;

            if (objectDelete == null)
            {
                throw new BusinessException(ErrorMessage.ERR005);
            }

            //Xóa thành viên trong bảng liên kết
            var userGroupsDelete = db.UserGroup.AsNoTracking().Where(r => r.GroupId.Equals(id)).ToList();

            if (userGroupsDelete.Count() > 0)
            {
                throw new BusinessException(ErrorMessage.ERR006);
            }

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    nameGroup = objectDelete.FirstOrDefault().Name;
                    //Xóa quyền của nhóm
                    var groupPermissionsDelete = db.GroupPermission.Where(r => r.GroupId.Equals(id));
                    db.GroupPermission.RemoveRange(groupPermissionsDelete);

                    //Xóa nhóm quyền
                    db.Group.RemoveRange(objectDelete);

                    //luu Log lich su
                    string decription = "Xóa thông tin nhóm quyền có tên là: " + nameGroup;
                    LogBusiness.SaveLogEvent(db, model.UserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
        public void ResetPass(string userId)
        {
            db = new TimeAttendanceEntities();

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var modelReset = db.User.Where(r => r.UserId.Equals(userId)).FirstOrDefault();
                    var name       = string.Empty;
                    if (modelReset != null)
                    {
                        modelReset.Password     = PasswordUtil.CreatePasswordHash();
                        modelReset.PasswordHash = PasswordUtil.ComputeHash(Constants.PasswordDefault + modelReset.Password);
                        name = modelReset.Name;
                    }

                    db.SaveChanges();
                    trans.Commit();

                    //luu Log lich su
                    string decription = "Lấy lại mật khẩu của user tên là: " + name;
                    LogBusiness.SaveLogEvent(db, userId, decription, null);
                    //xóa cache
                    // var RedisConnection = System.Configuration.ConfigurationManager.AppSettings["RedisConnection"];

                    var redis = RedisService <LoginCacheModel> .GetInstance(RedisConnection);

                    LoginCacheModel RefreshToken;
                    RefreshToken = redis.Get <LoginCacheModel>(Constants.ATLogin + modelReset.Name);
                    if (RefreshToken != null)
                    {
                        redis.Remove(Constants.ATLogin + modelReset.Name);
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
        public void UpdateUser(UserModel model)
        {
            db = new TimeAttendanceEntities();
            var modelEdit = db.User.Where(r => r.UserId.Equals(model.UserId) && r.DeleteFlg == Constants.DeleteFalse).FirstOrDefault();

            if (modelEdit == null)
            {
                throw new BusinessException(ErrorMessage.ERR003);
            }
            if (modelEdit.Name != model.Name)
            {
                if (this.IsExistedUser(model.Name))
                {
                    throw new BusinessException(ErrorMessage.ERR002);
                }
            }

            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    var userNameOld = modelEdit.Name;

                    modelEdit.FullName    = model.FullName;
                    modelEdit.BirthDay    = model.BirthDay;
                    modelEdit.Agency      = model.Agency;
                    modelEdit.Email       = model.Email;
                    modelEdit.UnitId      = model.UnitId;
                    modelEdit.Role        = model.Role;
                    modelEdit.Type        = model.Type;
                    modelEdit.PhoneNumber = model.PhoneNumber;
                    modelEdit.Address     = model.Address;
                    modelEdit.Description = model.Description;
                    modelEdit.ImageLink   = model.ImageLink;
                    modelEdit.UpdateBy    = model.UpdateBy;
                    modelEdit.UpdateDate  = DateTime.Now;

                    if (!string.IsNullOrEmpty(model.GroupId))
                    {
                        var itemDelete = db.UserGroup.Where(r => r.UserId.Equals(model.UserId));
                        db.UserGroup.RemoveRange(itemDelete);
                        UserGroup userGroup = new UserGroup()
                        {
                            UserGroupId = Guid.NewGuid().ToString(),
                            GroupId     = model.GroupId,
                            UserId      = model.UserId,
                        };
                        db.UserGroup.Add(userGroup);
                    }

                    //Thêm dánh sách quyền cho tài khoản
                    List <UserPermission> listPermission = new List <UserPermission>();
                    UserPermission        modelPermission;
                    //Xóa quyền cũ
                    var listPermissionDelete = db.UserPermission.Where(r => r.UserId.Equals(model.UserId));
                    db.UserPermission.RemoveRange(listPermissionDelete);

                    //Thêm quyền mới
                    if (model.ListPermission != null && model.ListPermission.Count() > 0)
                    {
                        foreach (var item in model.ListPermission)
                        {
                            modelPermission = new UserPermission()
                            {
                                UserPermissionId = Guid.NewGuid().ToString(),
                                UserId           = model.UserId,
                                FunctionId       = item.FunctionId,
                            };
                            listPermission.Add(modelPermission);
                        }
                        db.UserPermission.AddRange(listPermission);
                    }

                    //luu Log lich su
                    string decription = String.Empty;
                    if (userNameOld.ToLower() == modelEdit.Name.ToLower())
                    {
                        decription = "Cập nhật thông tin có tên là: " + userNameOld;
                    }
                    else
                    {
                        decription = "Cập nhật thông tin có tên ban đầu là:  " + userNameOld + " thành " + model.Name;;
                    }
                    LogBusiness.SaveLogEvent(db, model.LogUserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();

                    //xóa cache
                    var redis = RedisService <LoginCacheModel> .GetInstance(RedisConnection);

                    LoginCacheModel RefreshToken;
                    RefreshToken = redis.Get <LoginCacheModel>(Constants.ATLogin + userNameOld);
                    if (RefreshToken != null)
                    {
                        redis.Remove(Constants.ATLogin + userNameOld);
                    }
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
Exemplo n.º 10
0
        public void CreateUser(UserModel model)
        {
            db = new TimeAttendanceEntities();
            if (this.IsExistedUser(model.Name))
            {
                throw new BusinessException(ErrorMessage.ERR002);
            }
            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    User modelCreate = new User()
                    {
                        UserId      = Guid.NewGuid().ToString(),
                        Name        = model.Name,
                        FullName    = model.FullName,
                        BirthDay    = model.BirthDay,
                        Agency      = model.Agency,
                        Email       = model.Email,
                        UnitId      = model.UnitId,
                        Role        = model.Role,
                        Type        = model.Type,
                        PhoneNumber = model.PhoneNumber,
                        Address     = model.Address,
                        Status      = Constants.UnLock,
                        Description = model.Description,
                        ImageLink   = model.ImageLink,
                        CreateBy    = model.CreateBy,
                        CreateDate  = DateTime.Now,
                    };
                    modelCreate.Password     = PasswordUtil.CreatePasswordHash();
                    modelCreate.PasswordHash = PasswordUtil.ComputeHash(Constants.PasswordDefault + modelCreate.Password);

                    db.User.Add(modelCreate);

                    if (!string.IsNullOrEmpty(model.GroupId))
                    {
                        UserGroup userGroup = new UserGroup()
                        {
                            UserGroupId = Guid.NewGuid().ToString(),
                            GroupId     = model.GroupId,
                            UserId      = modelCreate.UserId,
                        };
                        db.UserGroup.Add(userGroup);
                    }

                    //Thêm dánh sách quyền cho tài khoản
                    List <UserPermission> listPermission = new List <UserPermission>();
                    UserPermission        modelPermission;
                    if (model.ListPermission != null && model.ListPermission.Count() > 0)
                    {
                        foreach (var item in model.ListPermission)
                        {
                            modelPermission = new UserPermission()
                            {
                                UserPermissionId = Guid.NewGuid().ToString(),
                                UserId           = modelCreate.UserId,
                                FunctionId       = item.FunctionId,
                            };
                            listPermission.Add(modelPermission);
                        }
                        db.UserPermission.AddRange(listPermission);
                    }

                    //luu Log lich su
                    string decription = "Thêm mới có tên là: " + model.Name;
                    LogBusiness.SaveLogEvent(db, model.LogUserId, decription, model.ViolationEventId);

                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }
Exemplo n.º 11
0
        public LoginEntity Login(string userName, string password)
        {
            db = new TimeAttendanceEntities();
            LoginEntity loginEntity = new LoginEntity();

            try
            {
                var userLogin = (from a in db.User.AsNoTracking()
                                 where a.Name.Equals(userName) && a.DeleteFlg == 0
                                 //join b in db.UserGroups.AsNoTracking() on a.UserId equals b.UserId into ab
                                 //from abv in ab.DefaultIfEmpty()
                                 select new
                {
                    a.UserId,
                    // a.UnitId,
                    a.Name,
                    a.FullName,
                    a.BirthDay,
                    // a.Agency,
                    a.Email,
                    a.Role,
                    a.PhoneNumber,
                    a.Password,
                    a.PasswordHash,
                    a.Status,
                    a.Type,
                    a.Description,
                    a.ImageLink,
                    a.CreateBy,
                    a.CreateDate,
                    a.UpdateBy,
                    a.UpdateDate,
                    a.IsAdmin,
                    //abv.GroupId,
                }).FirstOrDefault();
                if (userLogin != null)
                {
                    if (userLogin.Status == Constants.Lock)
                    {
                        //Tài khoản bị khóa. Lên hệ quản trị để kích hoạt lại
                        loginEntity.ResponseCode = -6;
                    }
                    else
                    {
                        var securityStamp = PasswordUtil.ComputeHash(password + userLogin.Password);
                        if (userLogin.PasswordHash.Equals(securityStamp))
                        {
                            UserEntity userEntity = new UserEntity()
                            {
                                UserName = userLogin.Name,
                                UserId   = userLogin.UserId,
                                FullName = userLogin.FullName,
                                Role     = "1",
                                //UnitId = userLogin.UnitId,
                                //GroupId = userLogin.GroupId,
                                ImageLink = userLogin.ImageLink,
                                //Agency = userLogin.Agency,
                                Type        = userLogin.Type,
                                IsAdmin     = userLogin.IsAdmin.ToString(),
                                securityKey = PasswordUtil.CreatePasswordHash(),
                            };
                            userEntity.ListPermission = new List <string>();
                            userEntity.ListPermission = (from c in db.UserPermission.AsNoTracking()
                                                         where c.UserId.Equals(userLogin.UserId)
                                                         join d in db.Function.AsNoTracking() on c.FunctionId equals d.FunctionId
                                                         select d.Code).ToList <string>();

                            userEntity.HomePage = (from r in db.Group.AsNoTracking()
                                                   join a in db.UserGroup on r.GroupId equals a.GroupId
                                                   where a.UserId.Equals(userEntity.UserId)
                                                   select r.HomePage).FirstOrDefault();

                            loginEntity.UserInfor = userEntity;

                            LogBusiness.SaveLogLogin(db, userEntity.UserId);
                        }
                        else
                        {
                            // Mật khẩu không đúng
                            loginEntity.ResponseCode = -5;
                        }
                    }
                }
                else
                {
                    // tài khoản không có trong hệ thống
                    loginEntity.ResponseCode = -4;
                }
            }
            catch (Exception e)
            {
                Console.Write(e.ToString());
            }

            return(loginEntity);
        }
Exemplo n.º 12
0
        public void UpdateGroupUser(GroupModel model)
        {
            db = new TimeAttendanceEntities();
            var modelEdit    = db.Group.Where(r => r.GroupId.Equals(model.GroupId)).FirstOrDefault();
            var groupNameOld = string.Empty;

            if (modelEdit == null)
            {
                throw new BusinessException(ErrorMessage.ERR005);
            }
            using (var trans = db.Database.BeginTransaction())
            {
                try
                {
                    groupNameOld = modelEdit.Name;

                    modelEdit.Name        = model.Name;
                    modelEdit.HomePage    = model.HomePage;
                    modelEdit.Description = model.Description;
                    modelEdit.UpdateBy    = model.UpdateBy;
                    modelEdit.UpdateDate  = DateTime.Now;

                    //Thêm dánh sách quyền cho nhóm
                    List <GroupPermission> listPermission = new List <GroupPermission>();
                    GroupPermission        modelPermission;
                    //Xóa quyền cũ
                    var listPermissionDelete = db.GroupPermission.Where(r => r.GroupId.Equals(model.GroupId));
                    db.GroupPermission.RemoveRange(listPermissionDelete);

                    //Thêm quyền mới
                    if (model.ListPermission != null && model.ListPermission.Count() > 0)
                    {
                        foreach (var item in model.ListPermission)
                        {
                            modelPermission = new GroupPermission()
                            {
                                GroupPermissionId = Guid.NewGuid().ToString(),
                                GroupId           = model.GroupId,
                                FunctionId        = item.FunctionId,
                            };
                            listPermission.Add(modelPermission);
                        }
                        db.GroupPermission.AddRange(listPermission);
                    }

                    //luu Log lich su
                    string decription = String.Empty;
                    if (groupNameOld.ToLower() == modelEdit.Name.ToLower())
                    {
                        decription = "Cập nhật thông tin nhóm quyền có tên là: " + groupNameOld;
                    }
                    else
                    {
                        decription = "Cập nhật thông tin nhóm quyền có tên ban đầu là:  " + groupNameOld + " thành " + model.Name;;
                    }
                    LogBusiness.SaveLogEvent(db, model.UserId, decription, null);

                    db.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw new ErrorException(ErrorMessage.ERR001, ex.InnerException);
                }
            }
        }