Beispiel #1
0
        public async Task <ResponseApi> Handle(CreateEnterpriseCommand request, CancellationToken cancelationToken)
        {
            try
            {
                request.Validate();
                if (request.Invalid)
                {
                    return(new ResponseApi(false, "Ops... Something is wrong", request.Notifications));
                }

                var enterpriseExists = await _enterpriseRepository.GetEnterpriseByFiscalNr(request.FiscalNr);

                if (enterpriseExists != null)
                {
                    return(new ResponseApi(false, "The enterprise already exists.", enterpriseExists));
                }

                Enterprise enterprise = _mapper.Map <Enterprise>(request);
                await _enterpriseRepository.Insert(enterprise);

                var response = new EnterpriseViewModel
                {
                    Id            = enterprise.Id,
                    Name          = enterprise.Name,
                    FiscalNr      = enterprise.FiscalNr,
                    Email         = enterprise.Email,
                    Phone         = enterprise.Phone,
                    Street        = enterprise.Street,
                    StateProvince = enterprise.StateProvince,
                    City          = enterprise.City,
                    Country       = enterprise.Country,
                    Active        = enterprise.Active,
                    Excluded      = enterprise.Excluded,
                    CreationDate  = enterprise.CreationDate,
                    LastUpdate    = enterprise.LastUpdate
                };

                return(new ResponseApi(true, "Enterprise created sucessfuly", response));
            }
            catch (Exception e)
            {
                return(new ResponseApi(true, "Error...", e));
            }
        }
Beispiel #2
0
        public async Task <IActionResult> GetEnterprises([FromBody] CreateEnterpriseCommand createEnterprise)
        {
            var result = await _mediator.Send(createEnterprise);

            return(Ok(result));
        }
Beispiel #3
0
        public async Task <IActionResult> Create(CreateEnterpriseCommand command)
        {
            await Mediator.Send(command);

            return(NoContent());
        }