public async Task <ActionResult> Purchase(PurchaseCouponViewModel model) { if (!ModelState.IsValid) { return(RedirectToAction("Index", model)); } var getOffer = _context.Offers.FirstOrDefault(c => c.OfferId == model.OfferId); var getRandomProductionCode = _context.ProductionCodes.Where(c => c.IsActive == false && c.IsUsed == false && c.OfferId == null).OrderBy(c => Guid.NewGuid()).FirstOrDefault(); if (getRandomProductionCode != null) { getRandomProductionCode.OfferId = model.OfferId; getRandomProductionCode.IsActive = true; _context.SaveChanges(); } var details = new GenCouponViewModel() { OfferDetails = getOffer, CouponCode = getRandomProductionCode.CouponCode }; //return View(); return(GenerateCoupon(details)); }
//Render the Purchase Coupon Page //Allow All merchant to be listed public async Task <ActionResult> Index() { var getMerchants = _context.Merchants.ToList(); var viewModel = new PurchaseCouponViewModel() { Merchants = getMerchants, Offer = new List <Offer>() }; return(View(viewModel)); }