コード例 #1
0
        public SetPrimaryAddressCommandHandlerFixture()
        {
            Context = TyreKlickerContextFactory.Create();

            CurrentUserId         = Guid.NewGuid();
            CurrentPrimaryAddress = new Domain.Entities.Address {
                UserId = CurrentUserId, PrimaryAddress = true
            };

            Addresses = new List <Domain.Entities.Address>
            {
                new Domain.Entities.Address {
                    UserId = CurrentUserId
                },
                new Domain.Entities.Address {
                    UserId = CurrentUserId
                },
                new Domain.Entities.Address {
                    UserId = CurrentUserId
                },
            };
            Context.Address.Add(CurrentPrimaryAddress);
            Context.Address.AddRange(Addresses);

            Context.SaveChanges();
        }
        public GeoCodedAddress MapToLocation(Domain.Entities.Address location, bool showAnonymousEmployerDetails)
        {
            if (showAnonymousEmployerDetails)
            {
                return(new GeoCodedAddress
                {
                    Town = location.Town
                });
            }

            return(new GeoCodedAddress
            {
                AddressLine1 = location.AddressLine1,
                AddressLine2 = location.AddressLine2,
                AddressLine3 = location.AddressLine3,
                AddressLine4 = location.AddressLine4,
                AddressLine5 = location.AddressLine5,
                GeoPoint = new GeoPoint()
                {
                    Latitude = location.Latitude,
                    Longitude = location.Longitude
                },
                PostCode = location.PostCode,
                Town = location.Town
            });
        }
コード例 #3
0
        public GetPrimaryAddressQueryHandlerFixture()
        {
            Context = TyreKlickerContextFactory.Create();

            CurrentUser       = new Domain.Entities.User();
            UserWithNoAddress = new Domain.Entities.User();
            Context.Add(CurrentUser);
            Context.Add(UserWithNoAddress);

            CurrentPrimaryAddress = new Domain.Entities.Address {
                UserId = CurrentUser.Id, PrimaryAddress = true
            };

            Addresses = new List <Domain.Entities.Address>
            {
                new Domain.Entities.Address {
                    UserId = CurrentUser.Id, PrimaryAddress = true
                },
                new Domain.Entities.Address {
                    UserId = CurrentUser.Id
                }
            };
            Context.Address.Add(CurrentPrimaryAddress);
            Context.Address.AddRange(Addresses);

            Context.SaveChanges();
        }
コード例 #4
0
        public async Task <Unit> Handle(CreateAddressCommand request, CancellationToken cancellationToken)
        {
            var user = await _context.User.FirstOrDefaultAsync(u =>
                                                               u.Id == request.UserId, cancellationToken);

            if (user == null)
            {
                throw new NotFoundException(nameof(user), request.UserId.ToString());
            }

            if (request.PrimaryAddress)
            {
                _context.Address.Where(x =>
                                       x.UserId == request.UserId &&
                                       x.PrimaryAddress)
                .ToList().ForEach(y => y.PrimaryAddress = false);
            }

            var entity = new Domain.Entities.Address
            {
                UserId         = request.UserId,
                City           = request.City,
                PhoneNumber    = request.PhoneNumber,
                Postcode       = request.Postcode,
                Street         = request.Street,
                PrimaryAddress = request.PrimaryAddress,
            };

            _context.Address.Add(entity);

            await _context.SaveChangesAsync(cancellationToken);

            return(Unit.Value);
        }
コード例 #5
0
        public void DeleteAddress(Domain.Entities.Address address)
        {
            if (address == null)
            {
                throw new ArgumentNullException("address");
            }

            _addressRepository.Delete(address);
        }
コード例 #6
0
 private static AddressModel MapAddress(Domain.Entities.Address address)
 {
     return(new AddressModel
     {
         CityName = address.CityName,
         CountryName = address.CountryName,
         StreetName = address.StreetName,
         StreetNumber = address.StreetNumber,
         PostalCode = address.PostalCode
     });
 }
コード例 #7
0
        public async Task <ResponseService> Handle(RemoveBarberShopCommand command, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                var barberShop = await _repositoryBarberShop.GetAsync(command.Id);

                var address          = new Domain.Entities.Address(barberShop.AddressId);
                var barberShopStatus = new Domain.Entities.BarberShopStatus(barberShop.BarberShopStatusId);

                using (TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    bool result;

                    if (!string.IsNullOrEmpty(barberShop.PathLogo))
                    {
                        _imageService.RemoveImage(barberShop.PathLogo);
                    }

                    result = await _repositoryAddress.DeleteAsync(address);

                    if (result)
                    {
                        result = await _repositoryBarberShopStatus.DeleteAsync(barberShopStatus);
                    }
                    if (result)
                    {
                        result = await _repositoryBarberShop.DeleteAsync(barberShop);
                    }

                    if (result)
                    {
                        transaction.Complete();
                        return(new ResponseService(result));
                    }
                    else
                    {
                        return(new ResponseService(messageError: $"Error deleting BarberShop: {barberShop.Name}"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ResponseService(messageError: ex.Message));
            }
        }
コード例 #8
0
        public async Task Create(AddressDto dto)
        {
            var address = new Domain.Entities.Address
            {
                Street       = dto.Street,
                Number       = dto.Number,
                Floor        = dto.Floor,
                Departament  = dto.Departament,
                House        = dto.House,
                Lot          = dto.Lot,
                Apple        = dto.Apple,
                Neighborhood = dto.Neighborhood,
                PostalCode   = dto.PostalCode,
                Observation  = dto.Observation,
                LocationId   = dto.LocationId,
                PersonId     = dto.PersonId
            };

            await _addressRepository.Create(address);
        }
コード例 #9
0
 public static AddressDto Create(Domain.Entities.Address address)
 {
     return(Projection.Compile().Invoke(address));
 }
コード例 #10
0
ファイル: UserBuilder.cs プロジェクト: dionimf/BibliotecaAPI
 public UserBuilder WithAddress(Domain.Entities.Address address)
 {
     _address = address;
     return(this);
 }
コード例 #11
0
        public async Task <ResponseService> Handle(CreateBarberShopCommand command, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                var address = new Domain.Entities.Address
                {
                    PublicPlace  = command.PublicPlace,
                    Number       = command.Number,
                    Neighborhood = command.Neighborhood,
                    Locality     = command.Locality,
                    State        = command.State,
                    Latitude     = command.Latitude,
                    Longitude    = command.Longitude
                };

                var barberShopStatus = new Domain.Entities.BarberShopStatus(DateTime.UtcNow);

                var barberShop = new Domain.Entities.BarberShop
                {
                    IsActive    = false,
                    Name        = command.Name,
                    UserAdminId = _identity.GetUserIdentity()
                };

                using (TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    if (!string.IsNullOrEmpty(command.LogoBase64.Trim()))
                    {
                        string nameFile = Guid.NewGuid().ToString();
                        barberShop.PathLogo = nameFile;

                        _imageService.SaveImage(command.LogoBase64, nameFile);
                    }

                    int?addressId = await _repositoryAddress.CreateAsync(address);

                    int?barberShopStatusId = await _repositoryBarberShopStatus.CreateAsync(barberShopStatus);

                    barberShop.AddressId          = addressId.GetValueOrDefault();
                    barberShop.BarberShopStatusId = barberShopStatusId.GetValueOrDefault();

                    int?barberShopId = await _repositoryBarberShop.CreateAsync(barberShop);

                    if (barberShopId > 0)
                    {
                        transaction.Complete();
                        return(new ResponseService(barberShopId));
                    }
                    else
                    {
                        return(new ResponseService(messageError: $"Error inserting BarberShop: {barberShop.Name}"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ResponseService(messageError: ex.Message));
            }

            // CreateBarberShopNotification addBarberShopNotification = new CreateBarberShopNotification(barberShop);
            // await _mediator.Publish(addBarberShopNotification);
        }
コード例 #12
0
        public async Task <ResponseService> Handle(ChangeBarberShopCommand command, CancellationToken cancellationToken)
        {
            try
            {
                cancellationToken.ThrowIfCancellationRequested();

                var barberShop = await _repositoryBarberShop.GetAsync(command.Id);

                barberShop.Name     = command.Name;
                barberShop.IsActive = command.IsActive;
                barberShop.UpdateAt = DateTime.UtcNow;

                var address = new Domain.Entities.Address
                {
                    Id           = barberShop.AddressId,
                    PublicPlace  = command.PublicPlace,
                    Number       = command.Number,
                    Neighborhood = command.Neighborhood,
                    Locality     = command.Locality,
                    State        = command.State,
                    Latitude     = command.Latitude,
                    Longitude    = command.Longitude,
                    UpdateAt     = DateTime.UtcNow
                };

                using (TransactionScope transaction = new TransactionScope(TransactionScopeAsyncFlowOption.Enabled))
                {
                    bool result;

                    if (command.IsRemovedLogo && !string.IsNullOrEmpty(barberShop.PathLogo))
                    {
                        _imageService.RemoveImage(barberShop.PathLogo);
                    }

                    if (!string.IsNullOrEmpty(command.LogoBase64.Trim()))
                    {
                        string nameFile = Guid.NewGuid().ToString();
                        barberShop.PathLogo = nameFile;

                        _imageService.SaveImage(command.LogoBase64, nameFile);
                    }

                    result = await _repositoryAddress.UpdateAsync(address);

                    if (result)
                    {
                        result = await _repositoryBarberShop.UpdateAsync(barberShop);
                    }

                    if (result)
                    {
                        transaction.Complete();
                        return(new ResponseService(result));
                    }
                    else
                    {
                        return(new ResponseService(messageError: $"Error updating BarberShop: {barberShop.Name}"));
                    }
                }
            }
            catch (Exception ex)
            {
                return(new ResponseService(messageError: ex.Message));
            }
        }