Esempio n. 1
0
        public ActionResult Select(SelectOfferViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId = User.Identity.GetUserId();

            var getOffer = _context.Offers.Include(c => c.Merchant).FirstOrDefault(c => c.OfferId == model.OfferId);

            var getUser = _context.Users.Include(c => c.Merchant).FirstOrDefault(c => c.Id == userId);

            var viewModel = new Models.SelectOfferViewModel
            {
                //Offers = _context.Offers.Include(c => c.Merchant).Include(c => c.Categories).Where(c => c.MerchantID == getUser.Merchant.MerchantID),
                Offer   = _context.Offers.Include(c => c.Merchant).Include(c => c.Categories).FirstOrDefault(c => c.MerchantID == getUser.Merchant.MerchantID),
                OfferId = model.OfferId
            };

            return(Edit(viewModel));
        }
Esempio n. 2
0
        //Method called after Offer to edit is selected
        public ActionResult Edit(SelectOfferViewModel model)
        {
            var userId = User.Identity.GetUserId();

            var getUser = _context.Users.Include(c => c.Merchant).FirstOrDefault(c => c.Id == userId);

            var getOffer = _context.Offers
                           .Include(c => c.Merchant)
                           .Include(c => c.Categories)
                           .FirstOrDefault(c => c.OfferId == model.OfferId);

            var viewModel = new Models.EditViewModel
            {
                offer = new MerchantCreateOfferViewModel
                {
                    OfferId = getOffer.OfferId,
                    //CouponDurationInMonths = getOffer.CouponDurationInMonths,
                    //CouponPrice = getOffer.CouponPrice,
                    DiscountRate = getOffer.DiscountRate,
                    MerchantID   = getOffer.Merchant.MerchantID,
                    OfferBegins  = getOffer.OfferBegins,
                    OfferEnds    = getOffer.OfferEnds,
                    OfferDetails = getOffer.OfferDetails,
                    OfferName    = getOffer.OfferName,
                    TotalOffer   = getOffer.TotalOffer,
                    Categories   = new List <Category>(), //Instantiate the category list
                }
            };

            //Sets the categories
            viewModel.offer.Categories    = _context.Categories.ToList();
            viewModel.OfferCategories     = new List <Category>();
            viewModel.OfferCategories     = getOffer.Categories.ToList();
            Session["SelectedCategories"] = getOffer.Categories;
            return(View("Edit", viewModel));
        }