public ActionResult Wishlist() { try { if (Session["Id"] != null) { WishlistDAO wdao = new WishlistDAO(); ApplicationDAO adao = new ApplicationDAO(); CartDAO cdao = new CartDAO(); int UserId = int.Parse(Session["Id"].ToString()); IList <Wishlist> wishs = wdao.GetUserList(UserId); IList <Application> apps = new List <Application>(); foreach (var w in wishs) { apps.Add(adao.SearchById(w.ApplicationId)); } ViewBag.Cart = cdao.SearchCartUser(int.Parse(Session["Id"].ToString())); ViewBag.WishApps = wishs; ViewBag.Apps = apps; return(View()); } return(RedirectToAction("Index", "Home")); } catch { return(RedirectToAction("Index", "Home")); } }
public ActionResult Sell() { try { CartDAO cdao = new CartDAO(); IList <Cart> cart = cdao.GetUserCart(int.Parse(Session["Id"].ToString())); if (Session["Id"] != null && cart.Count() != 0) { SellDAO dao = new SellDAO(); Sell s = new Sell(); s.UserId = int.Parse(Session["Id"].ToString()); s.Date = DateTime.Now; s.TotalPrice = cdao.GetSubtotal(s.UserId); dao.Add(s); foreach (var c in cart) { SellItemDAO sidao = new SellItemDAO(); SellItem si = new SellItem(); si.ApplicationId = c.ApplicationId; si.PriceItem = c.Price; si.SellId = s.Id; sidao.Add(si); cdao.Remove(c); //Removing from Wishlist WishlistDAO wdao = new WishlistDAO(); IList <Wishlist> wishs = wdao.GetUserList(int.Parse(Session["Id"].ToString())); foreach (var w in wishs) { if (w.ApplicationId == c.ApplicationId) { wdao.Remove(w); } } } return(RedirectToAction("Library", "User")); } else { return(RedirectToAction("../Home/Index")); } } catch { return(RedirectToAction("../Home/Index")); } }