// GET: Buyer public ActionResult Index() { check_stock(); List <BaseCategory_Table> cato = new List <BaseCategory_Table>(); cato = db.BaseCategory_Table.Where(x => x.BaseCatIsDeleted == false).ToList(); Session["filter1"] = 0; Session["filter2"] = 0; List <Product_Table> prods = db.Product_Table.OrderByDescending(x => x.ProductId).Take(3).ToList(); List <Buyer_Product> plist = new List <Buyer_Product>(); foreach (var item in prods) { Buyer_Product obj = new Buyer_Product(); obj.ProductName = item.ProductName; obj.ProductId = item.ProductId; obj.ProductPrice = item.ProductPrice; obj.ProductDesc = item.ProductDesc; Image_Table img = db.Image_Table.Where(x => x.Productid == item.ProductId).FirstOrDefault(); if (img != null) { obj.BinaryImage = img.BinaryImage; plist.Add(obj); } } ViewBag.newpro = plist; return(View(cato)); }
public ActionResult Products_PartialView(int productCatId) { List <Buyer_Product> productList = new List <Buyer_Product>(); var products = (from p in db.Product_Table where p.ProductCatid == productCatId && p.ProductIsDeleted == false select p).ToList(); foreach (var item in products) { Buyer_Product product = new Buyer_Product(); product.ProductName = item.ProductName; product.ProductId = item.ProductId; product.ProductPrice = item.ProductPrice; product.ProductDesc = item.ProductDesc; Image_Table image = db.Image_Table.Where(x => x.Productid == item.ProductId && x.ImageIsDeleted == false).FirstOrDefault(); if (image != null) { product.BinaryImage = image.BinaryImage; productList.Add(product); } } ViewBag.ProductList = productList.DistinctBy(x => x.ProductId).ToList(); return(PartialView("_productsPartialView")); }
public ActionResult upload(Image_Table model) { Image_Table image = new Image_Table(); int j; object[] imgarray = new object[5]; int p = Convert.ToInt32(TempData["ID"]); HttpPostedFileBase file = Request.Files["ImageData"]; for (j = 0; j < Request.Files.Count; j++) { file = Request.Files[j]; ContentRepository service = new ContentRepository(); if (file.ContentType.ToLower() != "image/jpg" && file.ContentType.ToLower() != "image/jpeg" && file.ContentType.ToLower() != "image/pjpeg" && file.ContentType.ToLower() != "image/gif" && file.ContentType.ToLower() != "image/x-png" && file.ContentType.ToLower() != "image/png") { TempData["not_imagedisp"] = "this is not an image file"; return(RedirectToAction("display")); } else if (file.FileName != "") { image = service.UploadImageInDataBase(file, model); Image_Table imageObj = new Image_Table(); imageObj.BinaryImage = image.BinaryImage; imageObj.Productid = Convert.ToInt32(TempData["ID"]); imageObj.ImageCreatedBy = Session["user"].ToString(); imageObj.ImageCreatedDate = DateTime.Now; imageObj.ImageUpdatedBy = Session["user"].ToString(); imageObj.ImageUpdatedDate = DateTime.Now; imageObj.ImageIsDeleted = false; db.Image_Table.Add(imageObj); db.SaveChanges(); } else if (file.FileName == "") { TempData["null_imagedisp"] = "Cannot Upload Null Image"; return(RedirectToAction("display")); } } return(RedirectToAction("display")); }
public JsonResult DeleteImage(int id) { Image_Table image = db.Image_Table.Find(id); image.ImageIsDeleted = true; image.ImageUpdatedBy = Session["user"].ToString(); image.ImageUpdatedDate = DateTime.Now; db.SaveChanges(); bool result = true; return(Json(new { result }, JsonRequestBehavior.AllowGet)); }
public ActionResult cart() { float total = 0; int c = 0; string name = Session["user"].ToString(); List <Buyer_Product> plist = new List <Buyer_Product>(); int uid = db.User_Table.Where(x => x.UserName == name).Select(x => x.UserId).FirstOrDefault(); int oid = db.Order_Table.Where(x => x.Userid == uid & x.OrderStatus == 0 & x.OrderIsDeleted == false).Select(x => x.OrderId).FirstOrDefault(); var pro_id = db.OrderDetail_Table.Where(x => x.Orderid == oid).Select(x => x.Productid).ToList(); List <int> avail_product = new List <int>(); List <int> not_avail_product = new List <int>(); foreach (var item1 in pro_id) { Product_Table pobj = db.Product_Table.Where(x => x.ProductId == item1).FirstOrDefault(); Buyer_Product bobj = new Buyer_Product(); bobj.ProductName = pobj.ProductName; bobj.ProductId = pobj.ProductId; bobj.ProductPrice = pobj.ProductPrice; bobj.ProductDesc = pobj.ProductDesc; if (pobj.ProductStock > 0) { total += (float)pobj.ProductPrice; avail_list.Add(pobj.ProductId); avail_product.Add(pobj.ProductId); c++; } else { not_avail_product.Add(pobj.ProductId); } Image_Table img = db.Image_Table.Where(x => x.Productid == item1 && x.ImageIsDeleted == false).FirstOrDefault(); if (img != null) { bobj.BinaryImage = img.BinaryImage; plist.Add(bobj); } } TempData["count"] = c; TempData["tcart_amt"] = total; ViewBag.avail = avail_product; ViewBag.tcart_amt = total; TempData["avail"] = avail_product; TempData.Keep("avail"); TempData["avail1"] = avail_product; ViewBag.not_avail = not_avail_product; return(View(plist)); }
public ActionResult Product_page() { int id = (int)Session["prod_cat"]; int?f1 = (int)Session["filter1"]; int?f2 = (int)Session["filter2"]; List <Product_Table> prods = new List <Product_Table>(); if (f1 == 1) { prods = db.Product_Table.Where(x => x.ProductCatid == id & x.ProductIsDeleted == false).OrderBy(x => x.ProductPrice).ToList(); } else if (f2 == 1) { prods = db.Product_Table.Where(x => x.ProductCatid == id & x.ProductIsDeleted == false).OrderByDescending(x => x.ProductPrice).ToList(); } else { prods = db.Product_Table.Where(x => x.ProductCatid == id & x.ProductIsDeleted == false).ToList(); } List <int> not_avail_product = new List <int>(); List <Buyer_Product> plist = new List <Buyer_Product>(); foreach (var item in prods) { Buyer_Product obj = new Buyer_Product(); obj.ProductName = item.ProductName; obj.ProductId = item.ProductId; obj.ProductPrice = item.ProductPrice; obj.ProductDesc = item.ProductDesc; if (item.ProductStock <= 0) { not_avail_product.Add(item.ProductId); } Image_Table img = db.Image_Table.Where(x => x.Productid == item.ProductId && x.ImageIsDeleted == false).FirstOrDefault(); if (img != null) { obj.BinaryImage = img.BinaryImage; plist.Add(obj); } } ViewBag.no_stock = not_avail_product; Session["filter1"] = 0; Session["filter2"] = 0; return(View(plist)); }
public Image_Table UploadImageInDataBase(HttpPostedFileBase file, Image_Table image) { image.BinaryImage = ConvertToBytes(file); return(image); }
public ActionResult Create(Image_Table model, Product_Table product) { int j; Notification_Count(); Image_Table image = new Image_Table(); if (ModelState.IsValid) { ShoppingCartDbEntities db = new ShoppingCartDbEntities(); string name = Session["user"].ToString(); int id = (from user in db.User_Table where user.UserName == name select user.UserId).FirstOrDefault(); product.SellerId = id; product.ProductCreatedBy = Session["user"].ToString(); product.ProductCreatedDate = DateTime.Now; product.ProductUpdatedBy = Session["user"].ToString(); product.ProductUpdatedDate = DateTime.Now; product.ProductIsDeleted = false; db.Product_Table.Add(product); db.SaveChanges(); object[] imgarray = new object[5]; int p = product.ProductId; HttpPostedFileBase file = Request.Files["ImageData"]; for (j = 0; j < Request.Files.Count; j++) { file = Request.Files[j]; ContentRepository service = new ContentRepository(); if (file.FileName != "") { image = service.UploadImageInDataBase(file, model); Image_Table imageObj = new Image_Table(); imageObj.BinaryImage = image.BinaryImage; imageObj.Productid = product.ProductId; imageObj.ImageCreatedBy = Session["user"].ToString(); imageObj.ImageCreatedDate = DateTime.Now; imageObj.ImageUpdatedBy = Session["user"].ToString(); imageObj.ImageUpdatedDate = DateTime.Now; imageObj.ImageIsDeleted = false; db.Image_Table.Add(imageObj); db.SaveChanges(); } else if (file.FileName == "") { TempData["null_image"] = "Cannot Upload Null Image"; return(RedirectToAction("Create")); } else { TempData["not_image"] = "this is not an image file"; return(RedirectToAction("Create")); } } } return(RedirectToAction("display")); }