Exemple #1
0
        public async Task <IHttpActionResult> Put(PlacementPutViewModel model)
        {
            if (model == null)
            {
                return(BadRequest());
            }

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var strategy = await _strategyService.GetStrategy(model.StrategyUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

            if (strategy == null)
            {
                return(BadRequest("The specified strategy was not found."));
            }

            var creative = await _creativeService.GetCreative(model.CreativeUuid.GetValueOrDefault(Guid.Empty)).ConfigureAwait(false);

            if (creative == null)
            {
                return(BadRequest("The specified creative was not found."));
            }

            var placementModifyOptions = _mapping.Map <PlacementModifyOptions>(model);
            await _placementService.ModifyPlacement(placementModifyOptions).ConfigureAwait(false);

            return(Ok());
        }
        public async Task ModifyPlacement(PlacementModifyOptions options)
        {
            var placement = await _placementRepositoryAsync.Queryable()
                            .FirstOrDefaultAsync(x => x.Creative.CreativeUuid == options.CreativeUuid && x.AdGroup.AdGroupUuid == options.StrategyUuid);

            if (options.IsLinking)
            {
                // link
                if (placement == null)
                {
                    // create
                    var creative = await _creativeService.GetCreative(options.CreativeUuid);

                    var strategy = await _strategyService.GetStrategy(options.StrategyUuid);

                    placement = new Placement
                    {
                        PlacementUuid       = IdentityValue.GenerateNewId(),
                        CreativeId          = creative.CreativeId,
                        AdGroupId           = strategy.AdGroupId,
                        BuyerAccountId      = strategy.BuyerAccountId,
                        PlacementStatusId   = (int)CreativeStatusEnum.Live,
                        UtcCreatedDateTime  = _clock.UtcNow,
                        UtcModifiedDateTime = _clock.UtcNow
                    };
                    _placementRepositoryAsync.Insert(placement);
                }
                else
                {
                    // update
                    placement.IsDeleted           = false;
                    placement.PlacementStatusId   = (int)CreativeStatusEnum.Live;
                    placement.UtcModifiedDateTime = _clock.UtcNow;
                    _placementRepositoryAsync.Update(placement);
                }
                await _brandscreenContext.SaveChangesAsync();

                return;
            }

            // unlink
            if (placement != null && (!placement.IsDeleted || placement.PlacementStatusId != (int)CampaignStatusEnum.Deleted))
            {
                placement.IsDeleted           = true;
                placement.PlacementStatusId   = (int)CampaignStatusEnum.Deleted;
                placement.UtcModifiedDateTime = _clock.UtcNow;
                _placementRepositoryAsync.Update(placement);
                await _brandscreenContext.SaveChangesAsync();
            }
        }
Exemple #3
0
        public async Task <IHttpActionResult> Get(Guid id)
        {
            var creative = await _creativeService.GetCreative(id).ConfigureAwait(false);

            if (creative == null)
            {
                return(NotFound());
            }

            var retVal = _mapping.Map <CreativeViewModel>(creative);

            return(Ok(retVal));
        }