Пример #1
0
        public ActionResult DeleteProduct(Guid id)
        {
            using (var db = new qStoreDBEntities())
            {
                var prod = db.Products.SingleOrDefault(x => x.Id == id);

                if (prod != null)
                {
                    db.Products.Remove(prod);
                    db.SaveChanges();
                }
                else
                {
                    throw new InvalidOperationException("Product not found");
                }
            }

            return RedirectToAction("GetProducts");
        }
Пример #2
0
        public ActionResult DeleteCategory(Guid id)
        {
            using (var db = new qStoreDBEntities())
            {
                var cat = db.Categories.SingleOrDefault(x => x.Id == id);

                if (cat != null)
                {
                    db.Categories.Remove(cat);
                }
                else
                {
                    throw new InvalidOperationException("Category not found");
                }

                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }
Пример #3
0
        public ActionResult SaveProduct(HttpPostedFileBase file, Product model)
        {
            using (var db = new qStoreDBEntities())
            {
                var product = db.Products.SingleOrDefault(x => x.Id == model.Id);
                model.Category = db.Categories.SingleOrDefault(x => x.Id == model.CategoryId);

                if (file != null && file.ContentLength > 0)
                {
                    model.ImageContentType = file.ContentType;
                    model.ImageBase64String = GetByteArrayString(file);
                }

                if (product != null)
                {
                    product.Title = model.Title;
                    product.Description = model.Description;
                    product.Category = model.Category;
                    product.ImageBase64String = model.ImageBase64String;
                    product.ImageContentType = model.ImageContentType;
                    product.Price = model.Price;
                }
                else
                {
                    db.Products.Add(model);
                }

                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }
Пример #4
0
        public ActionResult SaveCategory(Category model)
        {
            using (var db = new qStoreDBEntities())
            {
                var cat = db.Categories.SingleOrDefault(x => x.Id == model.Id);

                if (cat != null)
                {
                    cat.Title = model.Title;
                    cat.IsDisabled = model.IsDisabled;
                }
                else
                {
                    db.Categories.Add(model);
                }

                db.SaveChanges();
            }

            return RedirectToAction("Index");
        }