public ActionResult Add(Product product)
        {
            product.Owner = _context.Users.SingleOrDefault(u => u.UserName == User.Identity.Name);
            //_context.Users.Attach(product.Owner);
            product.DatePublished = DateTime.Now.Date;

            SetPictures(product, Request.Files);

            _context.Products.Add(product);

            _context.SaveChanges();

            Messages.Set(AppMessages.ItemAdded);

            return(RedirectToAction("Index", "Home"));
        }
        //
        // GET: ShoppingCart/Remove/?productID={Product ID}
        public ActionResult Remove(int productID)
        {
            var user = _context.Users.SingleOrDefault(u => u.UserName == User.Identity.Name);

            var product = _context.Products.SingleOrDefault(p => p.ID == productID);

            if (product == null)
            {
                return(HttpNotFound());
            }

            product.State  = ProductState.Avaialble;
            product.UserID = null;

            _context.SaveChanges();

            Messages.Set(AppMessages.ItemRemovedFromCart);

            return(RedirectToAction("ShoppingCart"));
        }
Esempio n. 3
0
        public ActionResult Register(User user)
        {
            if (user == null || !ModelState.IsValid)
            {
                return(View());
            }

            using (var ctx = new TradeCenterDB())
            {
                ctx.Users.Add(user);
                ctx.SaveChanges();
            }

            FormsAuthentication.SetAuthCookie(user.UserName, false);
            Session["userName"] = user.ToString();

            return(RedirectToLocal(Request.UrlReferrer.ToString()));
        }