Example #1
0
        public async Task <CreateEstablishmentResponse> Handle(
            CreateEstablishmentRequest request,
            CancellationToken cancellationToken)
        {
            var establishment = new Establishment(new Name(request.Name),
                                                  new CNPJ(request.CNPJ),
                                                  new Address(request.Address.Street,
                                                              request.Address.Number,
                                                              request.Address.Neighbourhood,
                                                              request.Address.City,
                                                              request.Address.State,
                                                              request.Address.ZipCode,
                                                              request.Address.Complement),
                                                  new Phone(request.Phone.CodeArea,
                                                            request.Phone.Number),
                                                  request.CarsCapacity,
                                                  request.MotorcyclesCapacity);

            var result = await _repository.Create(establishment.ToDataEntity());

            var test = establishment.Address.ToString();

            _repository.CommitChanges();

            return(new CreateEstablishmentResponse(
                       result.Id,
                       result.Name,
                       result.CNPJ,
                       establishment.Address.ToString(),
                       result.Phone,
                       result.CarsCapacity,
                       result.MotorcyclesCapacity
                       ));
        }
        public IActionResult AddEstablishment([FromBody] AddEstablishmentViewModel viewModel)
        {
            var address = new Address
            {
                Street = viewModel.Street,
                Number = viewModel.Number
            };

            var establishment = new Establishment {
                Address = address
            };

            try
            {
                var ret = _establishmentRepository.Create(establishment, viewModel.StoreId, viewModel.Image,
                                                          viewModel.FileName);
                return(Ok(ret));
            }
            catch (EstablishmentException e)
            {
                return(BadRequest(new { message = e.Message }));
            }
        }