public ActionResult CreateAd(tabelproduct pvm, HttpPostedFileBase imgfile) { List <tabelcategory> li = db.tabelcategories.ToList(); ViewBag.categorylist = new SelectList(li, "cat_id", "cat_name"); string path = uploadimgfile(imgfile); if (path.Equals("-1")) { ViewBag.error = "Image could not be uploaded...."; } else { tabelproduct p = new tabelproduct(); p.pro_name = pvm.pro_name; p.pro_price = pvm.pro_price; p.pro_image = path; p.pro_fk_cat = pvm.pro_fk_cat; p.pro_des = pvm.pro_des; p.pro_fk_user = Convert.ToInt32(Session["u_id"].ToString()); db.tabelproducts.Add(p); db.SaveChanges(); Response.Redirect("index"); } return(View()); }
public ActionResult DeleteAd(int?id) { tabelproduct p = db.tabelproducts.Where(x => x.pro_id == id).SingleOrDefault(); db.tabelproducts.Remove(p); db.SaveChanges(); return(RedirectToAction("Index")); }
public ActionResult ViewAd(int?id) { Adviewmodel ad = new Adviewmodel(); tabelproduct p = db.tabelproducts.Where(x => x.pro_id == id).SingleOrDefault(); ad.pro_id = p.pro_id; ad.pro_name = p.pro_name; ad.pro_image = p.pro_image; ad.pro_price = p.pro_price; ad.pro_des = p.pro_des; tabelcategory cat = db.tabelcategories.Where(x => x.cat_id == p.pro_fk_cat).SingleOrDefault(); ad.cat_name = cat.cat_name; tabeluser u = db.tabelusers.Where(x => x.u_id == p.pro_fk_user).SingleOrDefault(); ad.u_name = u.u_name; ad.u_image = u.u_image; ad.u_contact = u.u_contact; ad.pro_fk_user = u.u_id; return(View(ad)); }