Пример #1
0
        public IHttpActionResult ProcessCampaign(int campaignId)
        {
            int accountId = this.GetAccountId();

            // @todo: do the following asynconously

            // Get the campaign requested, if owned by user and not deleted
            Campaign campaign = db.Campaigns.Where(c => c.AccountId == accountId && c.Id == campaignId).FirstOrDefault();

            if (campaign == null || campaign.IsDeleted == true || !campaign.CanEditCampaign())
            {
                return(BadRequest());
            }

            this.db.GenerateCampaignSentItems(campaign);
            db.SetModified(campaign);

            db.SaveChanges();
            return(Ok());
        }
Пример #2
0
        public IHttpActionResult PutCampaign(int id, Campaign campaign)
        {
            int accountId = this.GetAccountId();

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

            if (id != campaign.Id || accountId != campaign.AccountId || !campaign.CanEditCampaign())
            {
                return(BadRequest());
            }

            // Reset the price set state as it needs to be recalculated
            campaign.CampaignStateId = CampaignState.DefaultState;

            db.SetModified(campaign);

            try
            {
                db.SaveChanges();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!CampaignExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
Пример #3
0
        public IHttpActionResult HasCampaignBeenProcessed(int campaignId)
        {
            int accountId = this.GetAccountId();
            // Get the campaign requested, if owned by user and not deleted
            Campaign campaign = db.Campaigns.Where(c => c.AccountId == accountId && c.Id == campaignId).FirstOrDefault();

            if (campaign == null || campaign.IsDeleted == true || !campaign.CanEditCampaign())
            {
                return(BadRequest());
            }

            if (campaign.CampaignStateId == CampaignState.PriceSet)
            {
                return(Ok(new CampaignProgressModel {
                    HasCampaignBeenProcessed = true
                }));
            }
            else
            {
                return(Ok(new CampaignProgressModel {
                    HasCampaignBeenProcessed = false
                }));
            }
        }