Esempio n. 1
0
        public async Task <ActionResult> Create(
            [FromRoute] long userId,
            [FromBody] CreateEventRequest createEventRequest)
        {
            InvoiceService invoiceService = new InvoiceService(_invoiceRepository);

            //Get charge domain service
            ChargeService chargeService = new ChargeService(
                _chargeRepository,
                _eventTypeRepository,
                _userRepository,
                invoiceService);

            try
            {
                //Create new charge and attach event to it
                Charge createdCharge = await chargeService.CreateChargeWithEvent(
                    createEventRequest.Amount,
                    createEventRequest.Currency,
                    userId,
                    createEventRequest.EventTypeName);

                await _dbContext.SaveChangesAsync();

                return(Ok(createdCharge));
            }
            catch (InvalidEntityException ex)
            {
                return(BadRequest(_mapper.Map <CreateEventFailedResponse>(ex.Model)));
            }
        }