Exemplo n.º 1
0
 public void Save_Invalid_Client()
 {
     try
     {
         Client client = new Client();
         _clientsRepository.Insert(client);
     }
     catch (Exception)
     {
         Assert.Pass();
     }
 }
Exemplo n.º 2
0
        public Task <object> InsertAsync(ClientsModel model)
        {
            if (model == null)
            {
                throw new ArgumentNullException("Client ArgumentNullException Insert Async");
            }

            Clients dto = AutoMapperGenericHelper <ClientsModel, Clients> .Convert(model);

            var id = _clientRepository.Insert(dto);

            return(Task.FromResult <object>(id));
        }
Exemplo n.º 3
0
        public async Task <ActionResult <ClientViewModel> > PostClient(ClientInputModel clientInput)
        {
            Client client = _mapper.Map <Client>(clientInput);

            IdentityResult result =
                await _applicationUserRepository.CreateAsync(client.User, clientInput.User.Password);

            if (!result.Succeeded)
            {
                return(this.IdentityResultErrors(result));
            }

            IdentityResult roleResult = await _applicationUserRepository.AddToRoleAsync(client.User, "Client");

            if (!roleResult.Succeeded)
            {
                return(this.IdentityResultErrors(roleResult));
            }

            client.PublishEvent(new SavedPerson(client));
            _clientsRepository.Insert(client);

            try
            {
                await _unitWork.SaveAsync();
            }
            catch (DbUpdateException)
            {
                if (ClientExists(clientInput.Id))
                {
                    return(Conflict($"El cliente con identificación {clientInput.Id} ya se encuentra registrado."));
                }

                throw;
            }

            return(_mapper.Map <ClientViewModel>(client));
        }