public ActionResult Index(string UsernameTB, string PasswordTB) { if (UsernameTB != null || PasswordTB != null) { string username = UsernameTB; string password = PasswordTB; AlliedEntities db = new AlliedEntities(); var q = (from p in db.LoginInfos where p.username.Equals(username) && p.password.Equals(password) select p); if (q.Count() == 1) { Session["user"] = q.FirstOrDefault().username.ToString(); return RedirectToAction("Index", "Home"); } else { @ViewBag.msg = "Incorrect Username/Password"; return View(); } } else { @ViewBag.msg = "Incorrect Username/Password"; return View(); } }
// // GET: /Manage/ public ActionResult Index(string search) { if (Session["user"] != null) { using (AlliedEntities db = new AlliedEntities()) { if (search != null) { var q = from p in db.Products where p.title.Contains(search) orderby p.id descending select p; return View("Index", q.ToList()); } var m = from p in db.Products orderby p.id descending select p; return View(m.ToList()); } } else { return RedirectToAction("Index", "Home"); } }
public ActionResult Index(Product product, HttpPostedFileBase FileUpload) { using (AlliedEntities db = new AlliedEntities()) { try { if (ModelState.IsValid) { ViewBag.Msg = null; if (FileUpload != null) { if (FileUpload.ContentLength <= (512 * 512) && (FileUpload.ContentType.Contains("/jpg") || FileUpload.ContentType.Contains("/jpeg") || FileUpload.ContentType.Contains("/png") || FileUpload.ContentType.Contains("/bmp"))) { product.imagetype = FileUpload.ContentType; product.imagebytes = ConverToByte(FileUpload); ViewBag.Msg = null; } else { ViewBag.Msg = "Invalid File"; } } if (ViewBag.Msg == null) { db.Products.Attach(product); db.ObjectStateManager.ChangeObjectState(product, System.Data.EntityState.Modified); db.SaveChanges(); return RedirectToAction("Index", "Manage"); } else { var q = (from p in db.Products where p.id == product.id select p).FirstOrDefault(); ViewBag.Msg = "Something went wrong"; return View(q); } } else { var q = (from p in db.Products where p.id == product.id select p).FirstOrDefault(); ViewBag.Msg = "Something went wrong"; return View(q); } } catch (Exception e) { var q = (from p in db.Products where p.id == product.id select p).FirstOrDefault(); ViewBag.Msg = "Something went wrong"; return View(q); } } }
// // GET: /Home/ public ActionResult Index() { using (AlliedEntities db = new AlliedEntities()) { var q = (from p in db.Products orderby p.id descending select p).Take(6); return View(q.ToList()); } }
public FileContentResult GetImage(int id) { AlliedEntities db = new AlliedEntities(); var q = from p in db.Products where p.id == id select p; byte[] byteArray = q.FirstOrDefault().imagebytes; if (byteArray != null) { return new FileContentResult(byteArray, q.FirstOrDefault().imagetype); } else { return null; } }
// // GET: /Edit/ public ActionResult Index(int id) { if (Session["user"] != null) { using (AlliedEntities db = new AlliedEntities()) { var q = (from p in db.Products where p.id == id select p).FirstOrDefault(); return View(q); } } else { return RedirectToAction("Index", "Home"); } }
public ActionResult Delete(int id) { if (Session["user"] != null) { using (AlliedEntities db = new AlliedEntities()) { Product p = db.Products.Single(e => e.id == id); db.Products.DeleteObject(p); db.SaveChanges(); return RedirectToAction("Index", "Manage"); } } else { return RedirectToAction("Index", "Home"); } }
public ActionResult Index(Product item, HttpPostedFileBase FileUpload) { if (ModelState.IsValid){ try{ using(AlliedEntities db = new AlliedEntities()){ if (FileUpload != null) { if (FileUpload.ContentLength <= (512 * 512) && (FileUpload.ContentType.Contains("/jpg") || FileUpload.ContentType.Contains("/jpeg") || FileUpload.ContentType.Contains("/png") || FileUpload.ContentType.Contains("/bmp"))) { item.imagetype = FileUpload.ContentType; item.imagebytes = ConverToByte(FileUpload); ViewBag.Msg = null; } else { ViewBag.Msg = "Invalid File"; } } if (ViewBag.Msg == null) { item.dateadded = DateTime.Now.Date; db.Products.AddObject(item); db.SaveChanges(); ViewBag.Msg = "Successfully Added"; return View(); } else { return View(); } } } catch (Exception) { return View(); } } return View(); }
// // GET: /Products/ public ActionResult Index(string category, string search) { using(AlliedEntities db = new AlliedEntities()) { if (search != null) { ViewBag.Title = "Allied - " + search; var q = from p in db.Products where p.title.Contains(search) orderby p.id descending select p; return View("Index", q.ToList()); } if (category != null) { string Category = category; ViewBag.Title = "Allied - " + category; var m = from p in db.Products where p.category.Equals(Category) orderby p.id descending select p; return View(m.ToList()); } else { ViewBag.Title = "Allied - Products"; var m = from p in db.Products orderby p.id descending select p; return View(m.ToList()); } } }