public ActionResult GetDetails(ProductsModel p, HttpPostedFileBase img1, HttpPostedFileBase img2, HttpPostedFileBase img3) { if (ModelState.IsValid) { FindUserRepository find = new FindUserRepository(); Product prod = new Product() { ProductID = p.ID, Date = DateTime.Now, State = (int)p.status, Title = p.title, ShortDescription = p.shortDescription, LongDescription = p.longDescription, Price = p.price }; if (Request.Cookies["userName"].Value != null) { prod.OwnerID = find.FindUserId(Request.Cookies["userName"].Value); p.ownerID = find.FindUserId(Request.Cookies["userName"].Value); } if (img1 != null || img2 != null || img3 != null) { string fileName1, fileName2, fileName3; if (img1 != null) { fileName1 = Path.GetFileName(img1.FileName); string fullPath = Path.Combine(Server.MapPath("~/uploads"), fileName1); img1.SaveAs(fullPath); p.image1 = ($"/uploads/" + fileName1); prod.Picture1 = p.image1; } if (img2 != null) { fileName2 = Path.GetFileName(img2.FileName); string fullPath = Path.Combine(Server.MapPath("~/uploads"), fileName2); img2.SaveAs(fullPath); p.image2 = ($"/uploads/" + fileName2); prod.Picture2 = p.image2; } if (img3 != null) { fileName3 = Path.GetFileName(img3.FileName); string fullPath = Path.Combine(Server.MapPath("~/uploads"), fileName3); img3.SaveAs(fullPath); p.image3 = ($"/uploads/" + fileName3); prod.Picture3 = p.image3; } } AddToDBRepository add = new AddToDBRepository(); add.AddProduct(prod); return(Content("Youre product has been added to our site" + "<br>" + "<a href=http://localhost:64245/Home/Index> Home Page</a>")); } else { return(View()); } }
public ActionResult UserExist() { FindUserRepository find = new FindUserRepository(); long id = find.FindUserId(Request.Cookies["userName"].Value); AddToCartRepository add = new AddToCartRepository(); List <ProductsModel> list = add.ProductsInCart(id).ToList(); foreach (var product in list) { product.price = product.price * Convert.ToDecimal(0.9); } return(View("Cart", list)); }
public override bool IsValid(Object userName) { if (userName != null) { FindUserRepository use = new FindUserRepository(); string uName = (string)userName; if (use.FindIfUserExist(uName)) { return(true); } } return(false); }
// GET: ProductDetails public ActionResult MoreDetails(long id) { FindProductRepository f = new FindProductRepository(); FindUserRepository find = new FindUserRepository(); ProductsModel pr = f.FindProductModelByID(id); pr.owner = find.FindUserModelByID(pr.ownerID); if (Request.Cookies["userName"] != null && Request.Cookies["userName"].Value != null) { pr.price = pr.price * Convert.ToDecimal(0.9); } return(View(pr)); }
public ActionResult GetDetails() { if (Request.Cookies["userName"] != null && Request.Cookies["userName"].Value != null) { FindUserRepository get = new FindUserRepository(); UsersModel use = get.FindUserModelByUserName(Request.Cookies["userName"].Value); return(View(use)); } else { return(View()); } }
public ActionResult GetDetails(UsersModel user) { if (ModelState.IsValid) { AddToDBRepository add = new AddToDBRepository(); add.AddUser(user); HttpCookie cookie = new HttpCookie("userName"); cookie.Value = user.userName.ToString(); Response.Cookies.Add(cookie); FindUserRepository get = new FindUserRepository(); UsersModel use = get.FindUserModelByUserName(Request.Cookies["userName"].Value); return(View(use)); } else { return(View()); } }
public ActionResult BuyAllProducts() { UpdateProductState update = new UpdateProductState(); FindUserRepository find = new FindUserRepository(); if (Request.Cookies["userName"] != null && Request.Cookies["userName"].Value != null) { long userId = find.FindUserId(Request.Cookies["userName"].Value); update.ChangeProductStateToBoughtUser(userId); } else { foreach (var item in (List <ProductsModel>)Session["cart"]) { update.ChangeProductStateToBoughtGuest(item.ID); var list = (List <ProductsModel>)Session["cart"]; Session["cart"] = list.Where(x => x.ID != item.ID).ToList(); } } return(RedirectToAction("Index", "Home")); }
public ActionResult AddToCart(long ID) { FindAllProductsByState product = new FindAllProductsByState(); UpdateProductState update = new UpdateProductState(); foreach (var p in product.GetAvailableProducts()) { if (p.ID == ID) { if (Request.Cookies["userName"] != null && Request.Cookies["userName"].Value != null) { FindUserRepository find = new FindUserRepository(); p.userID = find.FindUserId(Request.Cookies["userName"].Value); update.ChangeProductStateToCart(ID, p.userID); SetTimer(p); } else { if (Session["cart"] == null) { List <ProductsModel> list = new List <ProductsModel>(); list.Add(p); Session["cart"] = list; } else { List <ProductsModel> list = (List <ProductsModel>)Session["cart"]; list.Add(p); Session["cart"] = list; } update.ChangeStateToCartGuest(p.ID); } } } return(RedirectToAction("Index", "Home")); }