public ActionResult Save(CoupanModel obj)
 {
     bool check = true;
     if (Request.IsAuthenticated)
     {
         if (obj.id > 0)
         {
             check = CoupanDal.Update(obj);
         }
         else
         {
             check = CoupanDal.Create(obj);
         }
         if (check)
         {
             TempData["message"] = "Saved successfully";
         }
         else
         {
             TempData["message"] = "Error while saving data";
         }
         return RedirectToAction("Create", "Category");
     }
     else
     {
         return RedirectToAction("index", "home");
     }
 }
Beispiel #2
0
 public static CoupanModel GetById(int id)
 {
     var context = new Ecommerce.DbEntity.ecommerceEntities();
     var cat = context.coupans.Where(m => m.id == id).FirstOrDefault();
     var Coupan = new CoupanModel();
     Coupan.id = cat.id;
     Coupan.code = cat.code;
     Coupan.fromDate = Convert.ToDateTime(cat.fromDate);
     Coupan.toDate = Convert.ToDateTime(cat.toDate);
     Coupan.DiscountPercentage = (decimal)cat.discountpercentage;
     return Coupan;
 }
 public ActionResult Create()
 {
     if (Request.IsAuthenticated)
     {
         ViewBag.PageTittle = "Add Coupan";
         CoupanModel obj = new CoupanModel();
         return View(obj);
     }
     else
     {
         return RedirectToAction("index", "home");
     }
 }
Beispiel #4
0
 public static bool Create(CoupanModel obj)
 {
     bool check = true;
     try
     {
         var context = new Ecommerce.DbEntity.ecommerceEntities();
         context.coupans.Add(new DbEntity.coupan { code = obj.code, discountpercentage = ((decimal)obj.DiscountPercentage), fromDate = obj.fromDate, toDate = obj.toDate });
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         check = false;
     }
     return check;
 }
        public ActionResult Edit(int id)
        {
            if (Request.IsAuthenticated)
            {
                ViewBag.PageTittle = "Edit Coupan";

                CoupanModel obj = new CoupanModel();
                obj = CoupanDal.GetById(id);
                return View("Create", obj);
            }
            else
            {
                return RedirectToAction("index", "home");
            }
        }
Beispiel #6
0
 public static bool Update(CoupanModel obj)
 {
     bool check = true;
     try
     {
         var context = new Ecommerce.DbEntity.ecommerceEntities();
         var Coupan = context.coupans.Where(m => m.id == obj.id).FirstOrDefault();
         Coupan.code = obj.code;
         Coupan.fromDate = Convert.ToDateTime(obj.fromDate);
         Coupan.toDate = Convert.ToDateTime(obj.toDate);
         Coupan.discountpercentage = Convert.ToDecimal(obj.DiscountPercentage);
         context.SaveChanges();
     }
     catch (Exception ex)
     {
         check = false;
     }
     return check;
 }
Beispiel #7
0
 public static CoupanModel ValidateCoupan(string code)
 {
     CoupanModel Coupan = null;
     var context = new Ecommerce.DbEntity.ecommerceEntities();
     var cat = context.coupans.Where(m => m.code == code && m.fromDate < DateTime.Now && m.toDate > DateTime.Now).FirstOrDefault();
     if (cat != null)
     {
         Coupan = new CoupanModel();
         Coupan.id = cat.id;
         Coupan.code = cat.code;
         Coupan.fromDate = Convert.ToDateTime(cat.fromDate);
         Coupan.toDate = Convert.ToDateTime(cat.toDate);
         Coupan.DiscountPercentage = (decimal)cat.discountpercentage;
     }
     return Coupan;
 }