public ActionResult GenerateCode(Models.PromotionCodes p) { if (p.Code == null || p.Code == "") { p.Code = (string)TempData["PromoCode"]; } ViewModel.PromotionCodes.PromotionCodes promotionCodes = new ViewModel.PromotionCodes.PromotionCodes(); promotionCodes.SavePromoCode(p); return(RedirectToAction("PromoCode")); }
public string SavePromoCode(Models.PromotionCodes p) { string r = string.Empty; try { var db = new Context.ConnectionStringsContext(); if (db.PromotionCodes.Any(m => m.Id == p.Id)) //update { var pro = db.PromotionCodes.Where(m => m.Id == p.Id).SingleOrDefault(); pro.ExpiryDate = p.ExpiryDate; pro.Amount = p.Amount; r = "Successfully Update"; } else //Add { Models.PromotionCodes promotionCodes = new Models.PromotionCodes() { Code = p.Code, CreatedDate = DateTime.Now, ExpiryDate = p.ExpiryDate, IsApplied = false, Status = true, Amount = p.Amount, }; db.PromotionCodes.Add(promotionCodes); r = "Successfully saved"; } db.SaveChanges(); } catch (Exception ex) { r = "Unknown error occur, Please try again."; } return(r); }