Exemple #1
0
        public List <MUserVM> ReadListUser(ref string message)
        {
            List <MUserVM> lstRet      = new List <MUserVM>();
            MUserRPO       usrRPO      = new MUserRPO(imap_);
            TUserRoleRPO   tusrRoleRPO = new TUserRoleRPO(imap_);

            usrRPO.BeginTrans();
            if (usrRPO.ReadList(ref exec))
            {
                tusrRoleRPO.SetObjConn(usrRPO.ObjConn);
                foreach (var _objUser in usrRPO.Result.Collection)
                {
                    tusrRoleRPO.Conditions(nameof(TuserRole.Username), Operator.Equals(_objUser.Username));
                    //tusrRoleRPO.Where(nameof(TUserRole.Username)).Equals(_objUser.Username);
                    if (tusrRoleRPO.ReadList(ref exec))
                    {
                        _objUser.Password = "";
                        lstRet.Add(new MUserVM()
                        {
                            objUser  = _objUser,
                            ListRole = tusrRoleRPO.Result.Collection
                        });
                    }
                    else
                    {
                        break;
                    }
                }
            }
            message = exec.Message;
            usrRPO.EndTrans(exec);

            return(lstRet);
        }
Exemple #2
0
        private string AddOrUpdateUser(bool isUpdate, MUserVM objMuservm, string ConfirmationPassword = "")
        {
            MUserRPO muserRPO  = new MUserRPO(imap_);
            MUser    objMuser  = objMuservm.objUser;
            string   message   = "";
            bool     validPass =
                objMuser.Password.Any(c => char.IsLetter(c)) &&
                objMuser.Password.Any(c => char.IsDigit(c));

            message   = validPass ? "" : "Password must contain at least one letter and one numeric digit";
            validPass = objMuser.Password == ConfirmationPassword;
            message   = validPass ? "" : "Password didn't match";

            if (validPass)
            {
                objMuser.Password = Helpers.Crypto.EncryptPassword(objMuser.Password);
                if (objMuser.Password == "")
                {
                    //todo log
                    return("Error Encrypt");
                }
                muserRPO.BeginTrans();
                if (isUpdate)
                {
                    muserRPO.Conditions(nameof(objMuser.IsActive), Operator.Equals("true"));
                    muserRPO.Update(objMuser, ref exec);
                    AddUpdateUserRole(isUpdate, objMuservm, muserRPO.ObjConn, ref exec);
                }
                else
                {
                    muserRPO.Conditions(nameof(objMuser.Username), Operator.Equals(objMuser.Username));
                    if (muserRPO.ReadList(ref exec))
                    {
                        if (muserRPO.Result.AffectedRow > 0)
                        {
                            message = "username already Exist!";
                        }
                        else
                        {
                            muserRPO.Insert(objMuser, ref exec);
                            AddUpdateUserRole(isUpdate, objMuservm, muserRPO.ObjConn, ref exec);
                        }
                    }
                }
                message = exec.Message;
                muserRPO.EndTrans(exec);
            }
            return(message);
        }