コード例 #1
0
 public ActionResult Checkout()
 {
     try
     {
         CartDAO      cardao = new CartDAO();
         IList <Cart> cart   = cardao.GetUserCart(int.Parse(Session["Id"].ToString()));
         if (Session["Id"] != null && cart.Count() != 0)
         {
             UserDAO    udao = new UserDAO();
             CountryDAO cdao = new CountryDAO();
             User       u    = udao.SearchById(int.Parse(Session["Id"].ToString()));
             ViewBag.User        = u;
             ViewBag.CountryUser = cdao.SearchById(u.CountryId);
             ViewBag.Cart        = cardao.SearchCartUser(int.Parse(Session["Id"].ToString()));
             ViewBag.FullCart    = cart;
             return(View());
         }
         else
         {
             return(RedirectToAction("../Home/Index"));
         }
     }
     catch
     {
         return(RedirectToAction("../Home/Index"));
     }
 }
コード例 #2
0
        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"));
            }
        }
コード例 #3
0
 public ActionResult Cart()
 {
     try
     {
         CartDAO dao = new CartDAO();
         if (Session["Id"] != null)
         {
             ViewBag.Cart = dao.SearchCartUser(int.Parse(Session["Id"].ToString()));
         }
         if (Session["Id"] != null)
         {
             ViewBag.FullCart = dao.GetUserCart(int.Parse(Session["Id"].ToString()));
             return(View());
         }
         return(RedirectToAction("../Home/Index"));
     }
     catch
     {
         return(RedirectToAction("Index", "Home"));
     }
 }