public ActionResult Create(ProductCategory productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(View(productCategory));
            }
            else
            {
                context.Insert(productCategory);
                context.Commit();

                return(RedirectToAction("Index"));
            }
        }
Exemplo n.º 2
0
        private Basket CreateNewBasket(HttpContextBase httpContext)
        {
            Basket basket = new Basket();

            basketContext.Insert(basket);
            basketContext.Commit();

            HttpCookie cookie = new HttpCookie(BasketSessionName)
            {
                Value   = basket.Id,
                Expires = DateTime.Now.AddDays(1)
            };

            httpContext.Response.Cookies.Add(cookie);

            return(basket);
        }
        public ActionResult Create(Product product, HttpPostedFileBase file)
        {
            if (!ModelState.IsValid)
            {
                return(View(product));
            }
            else
            {
                if (file != null)
                {
                    product.Image = product.Id + Path.GetExtension(file.FileName);
                    file.SaveAs(Server.MapPath(@"/Content/ProductImages/") + product.Image);
                }
                context.Insert(product);
                context.Commit();

                return(RedirectToAction("Index"));
            }
        }