Beispiel #1
0
 public CreateBarberShopNotification(Domain.Entities.BarberShop barberShop)
 {
     BarberShop = barberShop;
 }
Beispiel #2
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);
        }