示例#1
0
 private async Task <CommandResult> CreateBasicReceipt(
     AddBasicReceiptViewModel model, string campaignId)
 {
     return(await _mediator.Send(
                new CreateBasicReceiptCommand
     {
         CampaignId = campaignId,
         Tags = model.Tags,
         Date = model.Date,
         TotalAmount = model.TotalAmount,
         Description = model.Description
     }));
 }
示例#2
0
        public async Task <IActionResult> AddBasicReceipt(
            [FromBody] AddBasicReceiptViewModel model)
        {
            await _mediator.Send(
                new AddDefaultTagCommand
            {
                Tags   = model.Tags,
                UserId = HttpContext.GetUserId()
            });

            var campaignResult = await _mediator
                                 .Send(new CampaignIdByNameQuery
            {
                CampaignName = model.Campaign
            });

            if (campaignResult.IsSuccess())
            {
                var receiptResult = await CreateBasicReceipt(
                    model, campaignResult.Value);

                return(receiptResult.ToHttpActionResult());
            }

            if (campaignResult.NotFound())
            {
                var campaignCreateResult = await _mediator
                                           .Send(new CreateMonthlyCampaignCommand
                {
                    Name = model.Campaign
                });

                if (campaignCreateResult.IsSuccess())
                {
                    var receiptResult = await CreateBasicReceipt(
                        model, campaignCreateResult.Value);

                    return(receiptResult.ToHttpActionResult());
                }

                return(campaignCreateResult.ToHttpActionResult());
            }

            return(campaignResult.ToHttpActionResult());
        }