示例#1
0
        public ActionResult Create(OfferViewModel offerVM, HttpPostedFileBase uploadBanner)
        {
            if (this.ModelState.IsValid)
            {

                Offer offer = GetOffer(offerVM);

                if (offer.Type == OfferType.Banner)
                {
                    if (uploadBanner != null && uploadBanner.ContentLength > 0)
                    {
                        var newBanner = new Banner(offer)
                        {
                            FileName = System.IO.Path.GetFileName(uploadBanner.FileName),
                            ContentType = uploadBanner.ContentType
                        };

                        using (var reader = new System.IO.BinaryReader(uploadBanner.InputStream))
                        {
                            newBanner.Content = reader.ReadBytes(uploadBanner.ContentLength);
                        }

                        this.db.Banners.Add(newBanner);
                        this.db.SaveChanges();
                        return this.RedirectToAction("Index");
                    }
                }

                this.db.Offers.Add(offer);
                this.db.SaveChanges();
                return this.RedirectToAction("Index");
            }

            return this.View(offerVM);
        }
示例#2
0
        // GET: Offers/Create
        public ActionResult Create()
        {
            var offerVM = new OfferViewModel();

            offerVM.Advertisers = db.Advertisers.ToList();
            offerVM.Categories = db.Categories.ToList();
            offerVM.DealsList = db.Deals.ToList();

            return View(offerVM);
        }
示例#3
0
 private Offer GetOffer(OfferViewModel offerVm)
 {
     var res = new Offer();
     res.Type = offerVm.Type;
     res.active = offerVm.active;
     res.advertiser = db.Advertisers.Find(offerVm.advertiserId);
     res.category = db.Categories.Find(offerVm.categoryId);
     res.lp = offerVm.lp;
     res.offerID = offerVm.offerID;
     res.offername = offerVm.offername;
     res.payouttype = db.Deals.Find(offerVm.payouttypeId);
     res.payoutvalue = offerVm.payoutvalue;
     res.revenuetype = db.Deals.Find(offerVm.revenuetypeId);
     res.revenuevalue = offerVm.revenuevalue;
     res.staticvalues = offerVm.staticvalues;
     return res;
 }
示例#4
0
        // GET: Offers/Edit/5
        public ActionResult Edit(int? id)
        {
            if (id == null)
            {
                return new HttpStatusCodeResult(HttpStatusCode.BadRequest);
            }
            Offer offer = db.Offers.Find(id);
            if (offer == null)
            {
                return HttpNotFound();
            }
            var offerVM = new OfferViewModel(offer);
            offerVM.Advertisers = db.Advertisers.ToList();
            offerVM.Categories = db.Categories.ToList();
            offerVM.DealsList = db.Deals.ToList();

            return View(offerVM);
        }