public ActionResult report(NameValueCollection nvclc) { nvclc = Request.Form; string cat = nvclc["cat"]; using (FantasticContext BookDb = new FantasticContext()) { var x = (from r in BookDb.checkouts select r.quantity); int p = x.Sum(); ViewBag.bag = p; var dataset2 = (from recordset in BookDb.checkouts where recordset.categoryName == cat select recordset.quantity); int p1 = dataset2.Sum(); ViewBag.cat = p1; return(View(BookDb.categories.ToList())); } }
public ActionResult Delete(string id) { using (FantasticContext BookDb = new FantasticContext()) { string name = Convert.ToString(Session["name"]); if (name == "admin") { Book book = BookDb.books.SingleOrDefault(b => b.bookId == id); return(View(book)); } else { return(RedirectToAction("Login", "home")); } } }
public ActionResult AddTocart() { string name = Convert.ToString(Session["name"]); if (name == "") { return(RedirectToAction("Login", "home")); } else { using (FantasticContext BookDb = new FantasticContext()) { return(View(BookDb.carts.ToList())); } } }
public ActionResult userIndex(NameValueCollection nvclc) { nvclc = Request.Form; string id = nvclc["bid"]; string bname = nvclc["bname"]; double price = Convert.ToDouble(nvclc["price"]); string aname = nvclc["aname"]; string userid = Convert.ToString(Session["id"]); string category = nvclc["category"]; string publishYear = nvclc["publishYear"]; using (FantasticContext BookDb = new FantasticContext()) { cart cat = BookDb.carts.SingleOrDefault(c => c.cartId == id); if (cat == null) { cart cart = new cart(); cart.cartId = id; cart.bookId = id; cart.bookName = bname; cart.authorName = aname; cart.categoryName = category; cart.userId = userid; cart.price = price; BookDb.carts.Add(cart); BookDb.SaveChanges(); return(RedirectToAction("AddTocart", "Home")); } else { ViewBag.Message = "Already Added"; return(View(BookDb.books.ToList())); } } using (FantasticContext BookDb = new FantasticContext()) { return(View(BookDb.books.ToList())); // return View(data); } }
public ActionResult Index(NameValueCollection nvclc) { using (FantasticContext BookDb = new FantasticContext()) { string name = Convert.ToString(Session["name"]); if (name == "") { return(RedirectToAction("Index", "home")); } else { //ServiceReference.TestWcfClient client = null; return(View(BookDb.books.ToList())); //return View(client.GetuserTypeDetails()); } } }
public ActionResult AdminIndex(HttpPostedFileBase file) { if (file != null) { NameValueCollection nvclc = Request.Form; string pic = nvclc["bkid"] + ".jpg"; //string pic = System.IO.Path.GetFileName(file.FileName); string path = System.IO.Path.Combine( Server.MapPath("~/images/"), pic); // file is uploaded file.SaveAs(path); // save the image path path to the database or you can send image // directly to database // in-case if you want to store byte[] ie. for DB using (MemoryStream ms = new MemoryStream()) { file.InputStream.CopyTo(ms); byte[] array = ms.GetBuffer(); } using (FantasticContext BookDb = new FantasticContext()) { Book books = new Book(); books.bookId = nvclc["bkid"]; books.bookName = nvclc["bkname"]; books.authorName = nvclc["atname"]; books.catId = nvclc["cat"]; books.publishYear = nvclc["pbyear"]; books.quantity = Convert.ToInt32(nvclc["quantity"]); books.price = Convert.ToDouble(nvclc["price"]); BookDb.books.Add(books); BookDb.SaveChanges(); return(RedirectToAction("List", "Admin")); } } // after successfully uploading redirect the user return(RedirectToAction("List", "Admin")); }
public ActionResult AddTocart(NameValueCollection nvclc) { nvclc = Request.Form; string a = nvclc["quantity"]; int quantity = Convert.ToInt32(a); //int quantity = 1; string userId = nvclc["userId"]; string bookId = nvclc["bookId"]; string categoryName = nvclc["categoryName"]; double price = Convert.ToDouble(nvclc["price"]); string authorName = nvclc["authorName"]; string bookName = nvclc["bookName"]; using (FantasticContext context = new FantasticContext()) { checkout check = new checkout(); check.bookId = bookId; check.userId = userId; check.price = price * quantity; check.quantity = quantity; check.authorName = authorName; check.categoryName = categoryName; check.bookName = bookName; context.checkouts.Add(check); context.SaveChanges(); //cart cart = context.carts.SingleOrDefault(d => d.cartId == bookId); //context.carts.Remove(cart); //context.SaveChanges(); return(Redirect("/home/checkout")); } return(RedirectToAction("checkout", "home")); }
public ActionResult report() { string name = Convert.ToString(Session["name"]); if (name == "admin") { using (FantasticContext BookDb = new FantasticContext()) { var x = (from r in BookDb.checkouts select r.quantity); if (x != null) { int p = x.Sum(); ViewBag.bag = p; return(View(BookDb.categories.ToList())); } else { return(View(BookDb.categories.ToList())); } } } return(RedirectToAction("Login", "home")); }