Example #1
0
 public ActionResult Login(LoginViewModel l, string ReturnUrl = "")
 {
     using (eveningDBEntities db = new eveningDBEntities())
     {
         var users = db.tbluserones.Where(a => a.UserName == l.Username && a.Password == l.Password).FirstOrDefault();
         if (users != null)
         {
             Session.Add("username", users.UserName);
             FormsAuthentication.SetAuthCookie(l.Username, l.RememberMe);
             if (Url.IsLocalUrl(ReturnUrl))
             {
                 return(Redirect(ReturnUrl));
             }
             else
             {
                 return(RedirectToAction("Dashboard", "Admin"));
             }
         }
         else
         {
             ModelState.AddModelError("", "Invalid User");
         }
     }
     return(View());
 }
Example #2
0
        public ActionResult AddOrEdit(int id = 0)
        {
            if (id == 0)
            {
                using (eveningDBEntities db = new eveningDBEntities())
                {
                    ViewBag.Categories = db.tblCategories.ToList();
                    ViewBag.Action     = "Create New Product";
                    return(View(new ProductViewModel()));
                }
            }
            else
            {
                using (eveningDBEntities db = new eveningDBEntities())
                {
                    ViewBag.Action     = "Edit Product";
                    ViewBag.Categories = db.tblCategories.ToList();
                    tblProduct       item   = db.tblProducts.Where(i => i.ProductId == id).FirstOrDefault();
                    ProductViewModel itemvm = new ProductViewModel();
                    itemvm.ProductId    = item.ProductId;
                    itemvm.CategoryId   = Convert.ToInt32(item.CategoryId);
                    itemvm.ProductName  = item.ProductName;
                    itemvm.UnitPrice    = item.UnitPrice;
                    itemvm.SellingPrice = item.SellingPrice;
                    itemvm.Description  = item.Description;
                    itemvm.Photo        = item.Photo;
                    itemvm.IsSpecial    = item.IsSpecial;

                    return(View(itemvm));
                }
            }
        }
Example #3
0
        public ActionResult AddOrEdit(ProductViewModel ivm)
        {
            using (eveningDBEntities db = new eveningDBEntities())
            {
                if (ivm.ProductId == 0)
                {
                    tblProduct itm = new tblProduct();

                    itm.CategoryId   = Convert.ToInt32(ivm.CategoryId);
                    itm.ProductName  = ivm.ProductName;
                    itm.UnitPrice    = ivm.UnitPrice;
                    itm.SellingPrice = ivm.SellingPrice;
                    itm.Description  = ivm.Description;
                    itm.IsSpecial    = ivm.IsSpecial;
                    HttpPostedFileBase fup = Request.Files["Photo"];
                    if (fup != null)
                    {
                        if (fup.FileName != "")
                        {
                            fup.SaveAs(Server.MapPath("~/ProductImages/" + fup.FileName));
                            itm.Photo = fup.FileName;
                        }
                    }



                    db.tblProducts.Add(itm);
                    db.SaveChanges();
                    ViewBag.Message = "Created Successfully";
                }
                else
                {
                    tblProduct itm = db.tblProducts.Where(i => i.ProductId == ivm.ProductId).FirstOrDefault();
                    itm.CategoryId   = Convert.ToInt32(ivm.CategoryId);
                    itm.ProductName  = ivm.ProductName;
                    itm.UnitPrice    = ivm.UnitPrice;
                    itm.SellingPrice = ivm.SellingPrice;
                    itm.Description  = ivm.Description;
                    itm.IsSpecial    = ivm.IsSpecial;
                    HttpPostedFileBase fup = Request.Files["SmallImage"];
                    if (fup != null)
                    {
                        if (fup.FileName != "")
                        {
                            fup.SaveAs(Server.MapPath("~/ProductImages/" + fup.FileName));
                            itm.Photo = fup.FileName;
                        }
                    }



                    db.SaveChanges();
                    ViewBag.Message = "Updated Successfully";
                }
                ViewBag.Categories = db.tblCategories.ToList();
                return(View(new ProductViewModel()));
            }
        }
Example #4
0
 public ActionResult Delete(int id)
 {
     using (eveningDBEntities db = new eveningDBEntities())
     {
         tblProduct sm = db.tblProducts.Where(x => x.ProductId == id).FirstOrDefault();
         db.tblProducts.Remove(sm);
         db.SaveChanges();
         return(Json(new { success = true, message = "Deleted Successfully" }, JsonRequestBehavior.AllowGet));
     }
 }
Example #5
0
 public JsonResult GetData()
 {
     using (eveningDBEntities db = new eveningDBEntities())
     {
         db.Configuration.LazyLoadingEnabled = false;
         List <ProductViewModel> lstitem = new List <ProductViewModel>();
         var lst = db.tblProducts.Include("tblCategory").ToList();
         foreach (var item in lst)
         {
             lstitem.Add(new ProductViewModel()
             {
                 ProductId = item.ProductId, CategoryName = item.tblCategory.CategoryName, ProductName = item.ProductName, UnitPrice = item.UnitPrice, SellingPrice = item.SellingPrice, Photo = item.Photo
             });
         }
         return(Json(new { data = lstitem }, JsonRequestBehavior.AllowGet));
     }
 }
Example #6
0
 public JsonResult GetData()
 {
     using (eveningDBEntities db = new eveningDBEntities())
     {
         db.Configuration.LazyLoadingEnabled = false;
         List <CategoryViewModel> lst = new List <CategoryViewModel>();
         var catList = db.tblCategories.ToList();
         foreach (var item in catList)
         {
             lst.Add(new CategoryViewModel()
             {
                 CategoryId = item.CategoryId, CategoryName = item.CategoryName
             });
         }
         return(Json(new { data = lst }, JsonRequestBehavior.AllowGet));
     }
 }
Example #7
0
 public ActionResult AddOrEdit(CategoryViewModel sm)
 {
     using (eveningDBEntities db = new eveningDBEntities())
     {
         if (sm.CategoryId == 0)
         {
             tblCategory tb = new tblCategory();
             tb.CategoryName = sm.CategoryName;
             db.tblCategories.Add(tb);
             db.SaveChanges();
             return(Json(new { success = true, message = "Saved Successfully" }, JsonRequestBehavior.AllowGet));
         }
         else
         {
             tblCategory tbm = db.tblCategories.Where(m => m.CategoryId == sm.CategoryId).FirstOrDefault();
             tbm.CategoryName = sm.CategoryName;
             db.SaveChanges();
             return(Json(new { success = true, message = "Updated Successfully" }, JsonRequestBehavior.AllowGet));
         }
     }
 }
Example #8
0
 public ActionResult AddOrEdit(int id = 0)
 {
     if (id == 0)
     {
         using (eveningDBEntities db = new eveningDBEntities())
         {
             ViewBag.Action = "New Category";
             return(View(new CategoryViewModel()));
         }
     }
     else
     {
         using (eveningDBEntities db = new eveningDBEntities())
         {
             CategoryViewModel sub = new CategoryViewModel();
             var menu = db.tblCategories.Where(x => x.CategoryId == id).FirstOrDefault();
             sub.CategoryId   = menu.CategoryId;
             sub.CategoryName = menu.CategoryName;
             ViewBag.Action   = "Edit Category";
             return(View(sub));
         }
     }
 }