Exemplo n.º 1
0
        public string Post([Bind]Sys_UserModel user)
        {
            #region chuyển string sang list<guid> (MasterDataGroup)
            if (user != null && !string.IsNullOrEmpty(user.MasterDataGroupIDstr))
            {
                var lstDataGroupIDstr = user.MasterDataGroupIDstr.Split(',');
                Guid dataGroupId = Guid.Empty;
                user.MasterDataGroupID = new List<Guid?>();
                foreach (var item in lstDataGroupIDstr)
                {
                    Guid.TryParse(item, out dataGroupId);
                    if (dataGroupId != Guid.Empty)
                    {
                        user.MasterDataGroupID.Add(dataGroupId);
                    }
                }
            }

            #endregion

            var success = string.Empty;
            var passwordEncrypt = string.Empty;

            #region Validate

            string message = string.Empty;
            var checkValidate = ValidatorService.OnValidateData<Sys_UserModel>(user, "Sys_UserInfo", ref message);
            if (!checkValidate)
            {
                user.ActionStatus = message;
                return message;
            }
            else
            {
                user.UserInfoName = user.UserInfoName1;
            }
            #endregion

            if (user == null)
            {
                return string.Empty;
            }

            var model = new Sys_UserInfoEntity
            {
                ID = user.ID,
                Code = user.Code,
                UserType = user.UserType,
                ProfileID = user.ProfileID,
                UserLogin = user.UserLogin,
                UserInfoName = user.UserInfoName,
                Email = user.Email,
                IsActivate = user.IsActivate,
                IsCheckLDAP = user.IsCheckLDAP,
                LDAPDatasource = user.LDAPDatasource,
                DateEnd = user.EffectedDate,
                DateStart = DateTime.Now,
                FullName = user.UserInfoName
            };

            var service = new Sys_UserServices();

            #region change password

            ActionService actionService = new ActionService(UserLogin);
            var userInfo = actionService.GetByIdUseStore<Sys_UserInfoEntity>(user.ID, ConstantSql.hrm_sys_sp_get_UserbyId, ref status);

            if (userInfo != null)
            {
                // neu password nhap vao co su thay doi => change password cho user
                if (user.Password != userInfo.Password)
                {
                    #region Change Password
                    //ma hoa password
                    if (user != null && !string.IsNullOrEmpty(user.Password))
                    {
                        passwordEncrypt = EncryptUtil.MD5(user.Password);//mã hoá giống bản 7
                    }
                    model.Password = passwordEncrypt;
                    #endregion
                }
                else
                {
                    //neu khong co su thay doi password => set giá tri password là password cua db vào model
                    model.Password = userInfo.Password;
                }
            }
            else
            {
                //tạo mới password cho user
                model.Password = passwordEncrypt;
            }
            #endregion

            if (user.ID != Guid.Empty)
            {
                model.ID = user.ID;
                success = service.Edit<Sys_UserInfoEntity>(model) + ",0";
            }
            else
            {
                success = service.Add<Sys_UserInfoEntity>(model) + ",1";
            }

            if (user != null && user.MasterDataGroupID != null)
            {
                service.UpdateUserMasterDataGroup(user.ID, user.MasterDataGroupID);
            }

            return success;
        }
Exemplo n.º 2
0
        public string ChangePassword(ChangePasswordModel model)
        {
            var userId = Session["UserId"];
            var strMessages = string.Empty;
            if (userId != null)
            {
                if (model != null)
                {
                    if (string.IsNullOrEmpty(model.OldPassword))
                    {
                        return ShowMessages(NotificationType.E_NotNull, "OldPassword");
                    }
                    if (string.IsNullOrEmpty(model.NewPassword))
                    {
                        return ShowMessages(NotificationType.E_NotNull, "NewPassword");
                    }
                    if (model.NewPassword != model.ReNewPassword)
                    {
                        return ShowMessages(NotificationType.E_Mismatch, "ReNewPassword");
                    }
                    ActionService actionService = new ActionService(UserLogin);
                    string status = string.Empty;
                    var userInfo = actionService.GetByIdUseStore<Sys_UserInfoEntity>((Guid)userId, ConstantSql.hrm_sys_sp_get_UserbyId, ref status);
                    if (userInfo != null)
                    {
                        var oldPass = userInfo.Password;
                        if (oldPass == EncryptUtil.MD5(model.OldPassword))
                        {
                            var newPass = EncryptUtil.MD5(model.NewPassword);
                            if (oldPass == newPass)
                            {
                                return ShowMessages(NotificationType.E_Messages, ConstantDisplay.NewPassTheSameOldPass);
                            }
                            userInfo.Password = newPass;
                            userInfo.DateChangePasssword = DateTime.Now;
                            var service = new Sys_UserServices();
                            var result = service.Edit<Sys_UserInfoEntity>(userInfo);

                            return ShowMessages(NotificationType.E_ChangePass_Success, ConstantDisplay.ChangePassword);
                        }
                        else
                        {
                            return ShowMessages(NotificationType.E_Incorrect, "OldPassword");
                        }
                    }
                    else
                    {
                        return ShowMessages(NotificationType.E_NotFound, ConstantDisplay.User);
                    }
                }
            }
            return strMessages;
        }
Exemplo n.º 3
0
        public Sys_UserModel Put(Sys_UserModel model)
        {
            var Sys_UserEntity = new Sys_UserInfoEntity
            {
                ID = model.ID,
                Code = model.Code,
                UserType = model.UserType,
                UserInfoName = model.UserInfoName,
                UserLogin = model.UserLogin,
                Password = model.Password,
                IsActivate = model.IsActivate,
                IsCheckLDAP = model.IsCheckLDAP,
                LDAPDatasource = model.LDAPDatasource,
            };
            var service = new Sys_UserServices();
            if (model.ID != Guid.Empty)
            {
                Sys_UserEntity.ID = model.ID;
                service.Edit<Sys_UserInfoEntity>(Sys_UserEntity);
            }
            else
            {
                service.Add<Sys_UserInfoEntity>(Sys_UserEntity);
            }

            return model;
        }