Beispiel #1
0
        public async Task <IActionResult> CreateCampaign([FromBody] CampaignSaveDto campaignSaveDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (await campaignService.IsOnCampaignInProgress(campaignSaveDto.UserId))
            {
                return(BadRequest("You can't create a new campaign, because this agent already have one in progress."));
            }

            var campaign = mapper.Map <CampaignSaveDto, Campaign>(campaignSaveDto);
            await campaignService.CreateCampaignAsync(campaign);

            var customers = mapper.Map <IEnumerable <CustomerDto>, IEnumerable <Customer> >(campaignSaveDto.Customers);

            await campaignService.AddCampaignDetailAsync(campaign.Id, customers);

            var result = mapper.Map <Campaign, CampaignSaveDto>(campaign);

            return(Ok(result));
        }