private AddressModelCreateDto ValidateInsertAddressInsideDto(UserModelUpdateDto user) { AddressModelCreateDto addressDto = new AddressModelCreateDto(); addressDto.Street = !string.IsNullOrEmpty(user.Street) ? user.Street : string.Empty; addressDto.Number = !string.IsNullOrEmpty(user.Number) ? user.Number : string.Empty; addressDto.Neighborhood = !string.IsNullOrEmpty(user.Neighborhood) ? user.Neighborhood : string.Empty; addressDto.Complement = !string.IsNullOrEmpty(user.Complement) ? user.Complement : string.Empty; addressDto.City = !string.IsNullOrEmpty(user.City) ? user.City : string.Empty; addressDto.UserId = user.Id; return(addressDto); }
public Guid AddAddress(AddressModelCreateDto newAddress) { if (newAddress == null) { throw new Exception("Endereço invalido"); } var validate = new AddressModelCreateDtoValidator().Validate(newAddress); if (!validate.IsValid) { throw new Exception("Endereço invalido"); } var userExists = _unitOfWork.Users.Query(x => x.Id == newAddress.UserId); if (userExists == null) { throw new Exception("Usuario invalido"); } var addressExistsForUser = _unitOfWork.Addresses.FindAddressByUserId(newAddress.UserId); if (addressExistsForUser != null) { throw new Exception("Usuario já contém um endereço"); } Address model = new Address { Id = Guid.NewGuid(), City = newAddress.City, UserId = newAddress.UserId, Street = newAddress.Street, Number = newAddress.Number, Complement = newAddress.Complement, Neighborhood = newAddress.Neighborhood, UpdateDate = DateTimeOffset.Now, CreationDate = DateTimeOffset.Now, Active = true, }; _unitOfWork.Addresses.Add(model); _unitOfWork.Commit(); return(model.Id); }
public OperationResponse <Guid> AddAddress([FromBody] AddressModelCreateDto address) { OperationResponse <Guid> response = new OperationResponse <Guid>(); try { var result = _serviceAddress.AddAddress(address); response.Data = result; response.Messages.Add(new OperationMessage { Description = "Sucesso", Type = OperationMessageTypes.Success }); } catch (Exception ex) { response.Messages.Add(new OperationMessage { Description = "Falha: " + ex.Message, Type = OperationMessageTypes.Error }); } return(response); }
private bool VerifyAnyFieldFilled(object dto) { if (dto.GetType() == typeof(AddressModelCreateDto)) { AddressModelCreateDto instance = (AddressModelCreateDto)dto; if (!string.IsNullOrEmpty(instance.Street)) { return(true); } else if (!string.IsNullOrEmpty(instance.Number)) { return(true); } else if (!string.IsNullOrEmpty(instance.Neighborhood)) { return(true); } else if (!string.IsNullOrEmpty(instance.Complement)) { return(true); } else if (!string.IsNullOrEmpty(instance.City)) { return(true); } else { return(false); } } if (dto.GetType() == typeof(AddressModelUpdateDto)) { AddressModelUpdateDto instance = (AddressModelUpdateDto)dto; if (!string.IsNullOrEmpty(instance.Street)) { return(true); } else if (!string.IsNullOrEmpty(instance.Number)) { return(true); } else if (!string.IsNullOrEmpty(instance.Neighborhood)) { return(true); } else if (!string.IsNullOrEmpty(instance.Complement)) { return(true); } else if (!string.IsNullOrEmpty(instance.City)) { return(true); } else { return(false); } } return(false); }