Esempio n. 1
0
        public OperationResult Register(RegisterAccount command)
        {
            var operationResult = new OperationResult();

            if (string.IsNullOrWhiteSpace(command.Mobile) ||
                string.IsNullOrWhiteSpace(command.FullName) ||
                string.IsNullOrWhiteSpace(command.Username) ||
                string.IsNullOrWhiteSpace(command.Password) ||
                string.IsNullOrWhiteSpace(command.RePassword))
            {
                return(operationResult.Failed(ApplicationMessage.RegisterErrorMessage));
            }

            if (_accountRepo.Exists(c => c.Username == command.Username || c.Mobile == command.Mobile))
            {
                return(operationResult.Failed(ApplicationMessage.duplicated));
            }
            if (command.Password != command.RePassword)
            {
                return(operationResult.Failed(ApplicationMessage.PasswordsNotMatch));
            }

            var path        = $"ProfileImage";
            var Picturepath = _fileUploader.Upload(command.ProfilePicture, path);

            var password = PasswordHelper.EncodePasswordMd5(command.Password);

            var Account = new Account(command.FullName, command.Username, command.Mobile,
                                      password, command.RoleId, Picturepath);

            _accountRepo.Create(Account);
            _accountRepo.Save();
            return(operationResult.Succeeded("ثبت نام شما در فروشگاه انجام شد میتواند در فروشگاه لاگین کنید"));
        }
        public AccountModel SignUp(SignUpDto dto)
        {
            return(ProtectedExecute <SignUpDto, AccountModel>(accountDto =>
            {
                accountDto.Password = Hasher.GetHash(accountDto.Password);
                AccountModel model = Mapper.Map <SignUpDto, AccountModel>(accountDto);

                if (AccountRepo.GetByLogin(model.Login) != null)
                {
                    throw new ConflictException("Login");
                }

                if (AccountRepo.GetByEmail(model.Email) != null)
                {
                    throw new ConflictException("Email");
                }

                return AccountRepo.Create(model);
            }, dto));
        }