Beispiel #1
0
        public void InsertPromo(AddPromoModel addPromoModel)
        {
            using (IDbConnection connection = OpenConnection())
            {
                System.TimeSpan midnight = new System.TimeSpan(0, 23, 59, 59);
                addPromoModel.ExpireDate = addPromoModel.ExpireDate.Add(midnight);

                const string query      = "INSERT INTO PromotionalCode (PromoCode, PromoCodeType, Amount, ExpireDate, MultiUse, Description, CreatedBy) VALUES (@PromoCode, @PromoCodeType, @Amount, @ExpireDate, @MultiUse, @Description, @CreatedBy)";
                var          parameters = new
                {
                    PromoCode     = addPromoModel.PromoCode,
                    Amount        = addPromoModel.PromoAmount,
                    PromoCodeType = addPromoModel.PromoTypes,
                    ExpireDate    = addPromoModel.ExpireDate,
                    MultiUse      = addPromoModel.MultipleUse,
                    Description   = addPromoModel.Description,
                    CreatedBy     = addPromoModel.CreatedBy
                };
                try
                {
                    connection.Execute(query, parameters);
                }
                catch
                {
                    throw;
                }

                return;
            }
        }
Beispiel #2
0
 public void CreatePromo(AddPromoModel addPromoModel)
 {
     try
     {
         adminRepository.InsertPromo(addPromoModel);
     }
     catch
     {
         throw;
     }
 }
Beispiel #3
0
        public ActionResult AddPromoCode()
        {
            if (Session["isAdmin"] == null)
            {
                return(RedirectToAction("LogIn", "Account"));
            }

            AddPromoModel model = new AddPromoModel();


            model.PromoCode  = GenPromoCode();
            model.ExpireDate = DateTime.Today.AddDays(1);
            return(View(model));
        }
Beispiel #4
0
        public ActionResult AddPromoCode(AddPromoModel model)
        {
            if (ModelState.IsValid)
            {
                if (Session["isAdmin"] == null)
                {
                    return(RedirectToAction("LogIn", "Account"));
                }

                if (model.Command == "ADD")
                {
                    string PostedPromoCode = model.PromoCode;
                    ModelState.Clear();

                    try
                    {
                        model.CreatedBy = (int)Session["MemberID"];
                        adminService.CreatePromo(model);

                        model.Message = "Promo Code " + PostedPromoCode + " has been saved.  Enter a new Promo or cancel.";

                        Random random = new Random();
                        model.PromoCode  = GenPromoCode();
                        model.ExpireDate = DateTime.Today.AddDays(1);
                        return(View(model));
                    }
                    catch
                    {
                        model.Message = "Error Adding Promo";
                        return(View(model));
                    }
                }
                else if (model.Command == "CANCEL")
                {
                    return(RedirectToAction("Index"));
                }
            }
            return(View(model));
        }