Example #1
0
        public ActionResult Edit(Campaign campaign, string discountcodes)
        {
            if (ModelState.IsValid)
            {
                campaign.SetNumericalPrices();
                db.Entry(campaign).State = EntityState.Modified;

                //remove all discount codes in db first, then we'll re-add the ones 
                //submitted on edit page
                var remove = from r in db.DiscountCodes
                             where r.CampaignID.Equals(campaign.CampaignID)
                             select r;

                if (remove != null)
                {
                    db.DiscountCodes.RemoveRange(remove);
                    db.SaveChanges();
                }

                List<string> codes = discountcodes.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
                foreach (var item in codes)
                {
                    if (!String.IsNullOrEmpty(item))
                    {
                        DiscountCode itemcode = new DiscountCode();
                        itemcode.Code = item;
                        itemcode.CampaignID = campaign.CampaignID;
                        db.DiscountCodes.Add(itemcode);

                    }
                }
                db.SaveChanges();
                return RedirectToAction("Index");
            }

            return View("Index", campaign);
        }
Example #2
0
        public ActionResult ProcessPayment(string token, string PayerID)
        {

            ReviewOrderViewModel newcampaign = Session["NewCampaign"] as ReviewOrderViewModel;
            string result = newcampaign.ProcessPayment(token, PayerID);

            if (result == "success")
            {
                if (ModelState.IsValid)
                {
                    newcampaign.Campaign.SetNumericalPrices();
                    db.Campaigns.Add(newcampaign.Campaign);
                    db.SaveChanges();

                    NotificationLog sellerCreatedCampaign = new NotificationLog();
                    sellerCreatedCampaign.CampaignID = newcampaign.Campaign.CampaignID;
                    sellerCreatedCampaign.LogTimestamp = DateTime.Now;
                    sellerCreatedCampaign.Message = "A seller used the automated tool to create a new campaign!";
                    db.NotificationLog.Add(sellerCreatedCampaign);


                    int id = newcampaign.Campaign.CampaignID;

                    List<string> codes = newcampaign.DiscountCodes.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
                    foreach (var item in codes)
                    {
                        if (!String.IsNullOrEmpty(item))
                        {
                            DiscountCode itemcode = new DiscountCode();
                            itemcode.Code = item;
                            itemcode.CampaignID = id;
                            db.DiscountCodes.Add(itemcode);

                        }
                    }
                    db.SaveChanges();
                }
                return View("Success", newcampaign);
            }

            return View("Index", "Seller");
        }
Example #3
0
        public ActionResult Validated(Campaign campaign, string discountcodes)
        {

            if (ModelState.IsValid)
            {
                campaign.SetNumericalPrices();
                db.Campaigns.Add(campaign);
                db.SaveChanges();

                int id = campaign.CampaignID;

                List<string> codes = discountcodes.Split(new[] { "\r\n" }, StringSplitOptions.None).ToList();
                foreach (var item in codes)
                {
                    if (!String.IsNullOrEmpty(item))
                    {
                        DiscountCode itemcode = new DiscountCode();
                        itemcode.Code = item;
                        itemcode.CampaignID = id;
                        db.DiscountCodes.Add(itemcode);

                    }
                }
                db.SaveChanges();


                return RedirectToAction("Index");
            }

            return View("Validate", campaign);
        }