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); }