Ejemplo n.º 1
0
        public ActionResult ProductCategories_Destroy([DataSourceRequest]DataSourceRequest request, ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                var entity = new ProductCategory
                {
                    ProductCategoryID = productCategory.ProductCategoryID,
                    Name = productCategory.Name,
                    rowguid = productCategory.rowguid,
                    ModifiedDate = productCategory.ModifiedDate
                };

                db.ProductCategories.Attach(entity);
                db.ProductCategories.Remove(entity);

                var orderDetails = from cc in db.ProductSubcategories where cc.ProductCategoryID == entity.ProductCategoryID select cc;

                foreach (var orderDetail in orderDetails)
                {
                    db.ProductSubcategories.Remove(orderDetail);
                }
                db.SaveChanges();
            }

            return Json(new[] { productCategory }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 2
0
        public ActionResult ProductCategories_Create([DataSourceRequest]DataSourceRequest request, ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                var entity = new ProductCategory
                {
                    Name = productCategory.Name,
                    rowguid = productCategory.rowguid,
                    ModifiedDate = DateTime.Now
                };

                db.ProductCategories.Add(entity);
                db.SaveChanges();
                productCategory.ProductCategoryID = entity.ProductCategoryID;
            }

            return Json(new[] { productCategory }.ToDataSourceResult(request, ModelState));
        }
Ejemplo n.º 3
0
        public ActionResult ProductCategories_Update([DataSourceRequest]DataSourceRequest request, ProductCategory productCategory)
        {
            if (ModelState.IsValid)
            {
                var entity = new ProductCategory
                {
                    ProductCategoryID = productCategory.ProductCategoryID,
                    Name = productCategory.Name,
                    rowguid = Guid.NewGuid(),
                    ModifiedDate = DateTime.Now
                };

                db.ProductCategories.Attach(entity);
                db.Entry(entity).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            return Json(new[] { productCategory }.ToDataSourceResult(request, ModelState));
        }