コード例 #1
0
        public ActionResult Create(ProductCategory productCategory)
        {
            if (!ModelState.IsValid)
            {
                return(View(productCategory));
            }
            else
            {
                context.Insert(productCategory);
                context.Commit();

                return(RedirectToAction("Index"));
            }
        }
コード例 #2
0
        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"));
            }
        }
コード例 #3
0
 private static void AddEmployees(IRespository <Employee> employeeRespository)
 {
     employeeRespository.Add(new Employee {
         Name = "keep"
     });
     employeeRespository.Add(new Employee {
         Name = "wan"
     });
     employeeRespository.Commit();
 }
コード例 #4
0
ファイル: BasketService.cs プロジェクト: drdws/MyShop
        public void AddToBasket(HttpContextBase httpContext, string productID)
        {
            Basket     basket = GetBasket(httpContext, true);
            BasketItem item   = basket.BasketItemCollection.FirstOrDefault(a => a.ProductID == productID);

            if (item == null)
            {
                item = new BasketItem()
                {
                    BasketID = basket.Id, ProductID = productID, Quanity = 1
                };

                basket.BasketItemCollection.Add(item);
            }
            else
            {
                item.Quanity = item.Quanity + 1;
            }

            basketContext.Commit();
        }