示例#1
0
        public EwhAccount ToEntity(EwhAccount ewhAccount, AddAccountDto account)
        {
            ewhAccount.AccountType = account.AccountType;
            ewhAccount.UserName    = account.UserName;
            ewhAccount.Info        = account.Info;

            return(ewhAccount);
        }
示例#2
0
 public bool Create(AddAccountDto dto)
 {
     if (!ValidateHelper.Validate(dto, out ValidateResults))
     {
         EwhStatus = core.Enums.GlobalStatus.InvalidData;
         return(false);
     }
     ewhMapper.ToEntity(this, dto);
     this.PasswordSaft = StringUtils.CreateSalt(20);
     this.Password     = StringUtils.GenerateSaltedHash(dto.Password, this.PasswordSaft);
     return(Save());
 }
示例#3
0
        public bool CreateAccount(AddAccountDto dto)
        {
            var ewhAccount = entityFactory.InitAccount();
            var check      = false;

            if (ewhAccount.Create(dto))
            {
                check           = true;
                EwhAccountAdded = ewhAccount;
            }
            SyncStatus(this, ewhAccount);
            return(check);
        }
        public IHttpActionResult CreateUser(AddAccountDto dto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_accountManager.CreateAccount(dto))
            {
                return(Ok(_accountManager.EwhAccountAdded));
            }
            else
            {
                return(ServerError(_accountManager as EwhEntityBase));
            }
        }
        public async Task <IActionResult> AddRegularAccount([FromForm][Required] string username,
                                                            [FromForm][Required] string password,
                                                            [FromForm][Required] string phone_number,
                                                            [FromForm][Required] string email)
        {
            var _account = new AddAccountDto()
            {
                Name        = username,
                Password    = password,
                PhoneNumber = phone_number,
                Email       = email,
                AccountRole = AccountRoles.Regular
            };
            var serviceResponse = await accountService.AddAccount(_account);

            var controllerResponse = mapper.Map <ServiceResponse, ControllerResponse>(serviceResponse);

            return(StatusCode(serviceResponse.StatusCode, controllerResponse));
        }
示例#6
0
        public IActionResult CreateAccount(Guid userId, AddAccountDto addAccountDto)
        {
            if (!_userRepo.UserExists(userId)) //check if user exist
            {
                return(BadRequest($"User with Id {userId} does not exist"));
            }

            lock (_lockAccount)
            {
                var user    = _userRepo.GetEntities(x => x.Id == userId).SingleOrDefaultAsync().Result;
                var userDto = _mapper.Map <AddUserDto>(user);
                addAccountDto.UserEntity = userDto;
                var result = _accountRepo.CreateByDTOAsync(addAccountDto).GetAwaiter().GetResult();
                if (result)
                {
                    _logger.LogInformation($"user {userId} Create account successfully");
                    return(Ok("Create account successfully"));
                }
            }

            throw new Exception();
        }
示例#7
0
        public async Task <ServiceResponse <GetAccountDto> > AddAccount(AddAccountDto _account)
        {
            var serviceResponse = new ServiceResponse <GetAccountDto>();

            Account account = mapper.Map <Account>(_account);

            account.SecurityStamp = Guid.NewGuid().ToString();
            var result = await userManager.CreateAsync(account, _account.Password);

            if (result.Succeeded)
            {
                result = await userManager.AddToRoleAsync(account, _account.AccountRole);

                var savedUser = await userManager.FindByNameAsync(_account.Name);

                if (result.Succeeded)
                {
                    serviceResponse.Message = $"User sucessfully created!";
                    serviceResponse.Data    = mapper.Map <GetAccountDto>(savedUser);
                }
                else
                {
                    serviceResponse.Message    = GetErrorsString(result.Errors, "Failed to add user to the role! ");
                    serviceResponse.Successful = false;
                    serviceResponse.StatusCode = StatusCodes.Status400BadRequest;
                    await userManager.DeleteAsync(savedUser);
                }
            }
            else
            {
                serviceResponse.Message    = GetErrorsString(result.Errors, "User creation failed! ");
                serviceResponse.Successful = false;
                serviceResponse.StatusCode = StatusCodes.Status400BadRequest;
            }

            return(serviceResponse);
        }
        public ActionResult <AccountDto> AddAccount(AddAccountDto addAccount)
        {
            var accounts = _context.Accounts;

            var isValidGuid           = Guid.TryParse(addAccount.Id.ToString(), out var id);
            var ibanAlreadyRegistered = accounts.Any(a => a.Iban == addAccount.Iban);
            var idAlreadyUsed         = accounts.Any(a => a.Id == addAccount.Id);

            if (!isValidGuid)
            {
                return(BadRequest("Ïnvalid ID"));
            }

            if (idAlreadyUsed)
            {
                return(BadRequest("Id already in use"));
            }

            if (ibanAlreadyRegistered)
            {
                return(BadRequest("IBAN already assigned to account"));
            }


            var newAccount = new AccountEntity()
            {
                Id            = id,
                Name          = addAccount.Name,
                Iban          = addAccount.Iban,
                FavoriteQuote = addAccount.FavoriteQuote,
            };

            _context.Accounts.Add(newAccount);
            _context.SaveChanges();

            return(CreatedAtAction(nameof(GetAccountById), new { id = addAccount.Id }, addAccount));
        }
        public void Seed()
        {
            var account = new AddAccountDto()
            {
                Name        = "bob",
                Email       = "*****@*****.**",
                PhoneNumber = "222333444",
                Password    = "******",
                AccountRole = AccountRoles.Regular
            };

            if (!AccountService.AddAccount(account).Result.Successful)
            {
                throw new ApplicationException("Could not seed the database with a user");
            }

            var saveDogDog = new LostDog()
            {
                Breed       = "dogdog",
                Age         = 5,
                Size        = "Large, very large",
                Color       = "Orange but a bit yellow and green dots",
                SpecialMark = "tattoo of you on the neck",
                Name        = "Cat",
                Picture     = new PictureDog()
                {
                    FileName = "photo",
                    FileType = "png",
                    Data     = new byte[] { 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1, 1 }
                },
                HairLength = "Long",
                EarsType   = "Short",
                TailLength = "None",
                Behaviors  = new List <DogBehavior>()
                {
                    new DogBehavior()
                    {
                        Behavior = "Angry"
                    }
                },
                Location = new LocationDog()
                {
                    City = "Biała", District = "Lol ther's none"
                },
                DateLost = new DateTime(2021, 3, 20),
                OwnerId  = 1,
                Comments = new List <LostDogComment>()
            };

            if (LostDogRepository.AddLostDog(saveDogDog).Result == null)
            {
                throw new ApplicationException("Could not seed the database with a dog assigned to user");
            }

            var shelter = new Shelter()
            {
                IsApproved  = true,
                Name        = $"VeryNiceShelter-1",
                PhoneNumber = $"2111111111",
                Email       = $"*****@*****.**",
                Address     = new Address
                {
                    City           = "Gdańsk",
                    PostCode       = "12-345",
                    Street         = "Bursztynowa",
                    BuildingNumber = "123"
                }
            };

            if (ShelterRepository.AddShelter(shelter).Result == null)
            {
                throw new ApplicationException("Could not seed the database with a shelter");
            }
        }
示例#10
0
 protected override SharedAccount MapEntity(AddAccountDto addItemDto)
 {
     return(new SharedAccount(addItemDto.Id, addItemDto.FirstName, addItemDto.LastName, addItemDto.Email));
 }
示例#11
0
        protected override async Task <GetAccountDto> ExecuteAsync(CreateAccountCommand request, CancellationToken ct)
        {
            AddAccountDto accountDto = _mapper.Map <AddAccountDto>(request);

            return(await _accountService.AddAsync(accountDto, ct));
        }
示例#12
0
        public AddAccountDto ToEntity(AddAccountDto dto, EwhAccount ewhAccount)
        {
            dto.AccountType = ewhAccount.AccountType;

            return(dto);
        }