Ejemplo n.º 1
0
        public LoginModel Post(LoginModel user)       
        {

            if (!string.IsNullOrEmpty(user.UserName) && !string.IsNullOrEmpty(user.Password))
            {
                var service = new Sys_UserServices();
                var model = new LoginModel();
                var status = string.Empty;
                var userInfo = service.Login(user.UserName, user.Password,user.GoogleMail,user.GoogleProfileName,user.IsGoogleSign);

             

                if (userInfo != null)
                {

                    var profileInfo = service.GetData<Hre_ProfileEntity>(userInfo.ProfileID, ConstantSql.hrm_hr_sp_get_ProfileById, UserLogin, ref status).FirstOrDefault();
            
                    model = new LoginModel
                    {
                        UserName = userInfo.UserLogin,
                        Password = userInfo.Password,
                        HasMasterDataGroup = userInfo.HasMasterDataGroup,
                        FullName = profileInfo != null ? profileInfo.ProfileName : string.Empty,
                        UserInfoName = userInfo.UserInfoName,
                        IsActive = userInfo.IsActivate,
                        ProfileID = userInfo.ProfileID,
                        ID = userInfo.ID,
                        IsRunScriptNew = userInfo.IsRunScriptNew,
                        VesionLastName = userInfo.VesionLastName,
                    };
                    if (userInfo.DateChangePasssword == null)
                        model.IsFirstLogin = true;

                    return model;
                }
            }
            return null;
        }
Ejemplo 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;
        }
Ejemplo n.º 3
0
        // GET api/<controller>/5
        public Sys_UserModel Get(Guid id)
        {
            var profileName = string.Empty;
            var service = new Sys_UserServices();
            // var result = service.GetById<Sys_UserInfoEntity>(id, ref status);

            ActionService actionService = new ActionService(UserLogin);
            var result = actionService.GetByIdUseStore<Sys_UserInfoEntity>(id, ConstantSql.hrm_sys_sp_get_UserbyId, ref status);

          

            if (result == null)
            {
                return new Sys_UserModel();
            }

            #region Get ProfileName
            var userService = new Sys_UserServices();
            var profile = userService.GetProfileName(result.ProfileID ?? Guid.Empty);
            var profileID = Guid.Empty;
            if (profile != null)
            {
                profileName = profile.ProfileName;
                profileID = profile.ID;
            }
            #endregion

            var Sys_UserEntity = new Sys_UserModel
            {
                ID = result.ID,
                Code = result.Code,
                UserType = result.UserType,
                UserInfoName = result.UserInfoName,
                UserInfoName1 = result.UserInfoName,
                UserLogin = result.UserLogin,
                FullName = result.FullName,
                Password = result.Password,
                Email = result.Email,
                EffectedDate = result.DateEnd,
                ProfileName = profileName,
                ProfileID = profileID,
                IsActivate = result.IsActivate,
                IsCheckLDAP = result.IsCheckLDAP,
                Description = result.Description,
                LDAPDatasource = result.LDAPDatasource,
            };

            #region Tự động load ds các dự án vào multiSelect control
            var sysUserService = new Sys_UserServices();
            var masterDataGroup = sysUserService.GetMultiCatTableForDashBoard(id);
            var dic = new Dictionary<Guid, string>();
            foreach (var item in masterDataGroup)
            {
                dic.Add(item.ID, item.MasterDataGroupName);
            }
            Sys_UserEntity.MasterDataGroups = dic; 
            #endregion

            return Sys_UserEntity;

        }
Ejemplo n.º 4
0
 // DELETE api/<controller>/5
 public void Delete(Guid ID)
 {
     var service = new Sys_UserServices();
     var result = service.Remove<Sys_UserInfoEntity>(ID);
 }
Ejemplo n.º 5
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;
        }
Ejemplo n.º 6
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;
        }
Ejemplo n.º 7
0
 public JsonResult GetMultiCatTableForDashBoard(Guid userID)
 {
     var service = new Sys_UserServices();
     var lstMasterDataGroupMulti = service.GetMultiCatTableForDashBoard(userID);
     return Json(lstMasterDataGroupMulti, JsonRequestBehavior.AllowGet);
 }