Example #1
0
        public async Task <ActionResult <V1DTO.CampaignDTO> > PostCampaign(V1DTO.CampaignDTO campaignDTO)
        {
            // Create campaign
            var bllEntity = _mapper.Map(campaignDTO);

            _logger.LogInformation($"Id: {User.UserGuidId()}");
            _bll.Campaigns.Add(bllEntity, User.UserGuidId());

            // Save to db
            await _bll.SaveChangesAsync();

            campaignDTO.Id = bllEntity.Id;
            return(CreatedAtAction(
                       "GetCampaign",
                       new { id = campaignDTO.Id, version = HttpContext.GetRequestedApiVersion()?.ToString() ?? "0" },
                       campaignDTO));

            // Create UserCampaign table entry to connect campaign to user
            // var userCampaign = new UserCampaign
            // {
            //     AppUserId = User.UserGuidId(),
            //     CampaignId = campaign.Id
            // };
            // _uow.UserCampaigns.Add(userCampaign);
        }
Example #2
0
        public async Task <IActionResult> PutCampaign(Guid id, V1DTO.CampaignDTO campaignDTO)
        {
            // Don't allow wrong data
            if (id != campaignDTO.Id)
            {
                return(BadRequest(new V1DTO.MessageDTO("id and campaign.id do not match")));
            }
            var campaign = await _bll.Campaigns.GetPersonalAsync(campaignDTO.Id, User.UserGuidId());

            if (campaign == null)
            {
                _logger.LogError($"EDIT. No such campaign for id: {campaignDTO.Id} and user: {User.UserGuidId()}");
                return(NotFound(new V1DTO.MessageDTO($"No Campaign found for this user with id {id}")));
            }
            // Update existing campaign
            await _bll.Campaigns.UpdateAsync(_mapper.Map(campaignDTO), User.UserGuidId());

            await _bll.SaveChangesAsync();

            return(NoContent());
        }