Exemple #1
0
 public ActionResult ViewProducts(int id)
 {
     using (var entities = new BeerWeb.Models.BeerModel())
     {
         var viewmodel = new ViewModels.ViewProductsViewModel();
         viewmodel.ProductsList.AddRange(entities.Products.Where(x => x.Category_Id == id));
         return(View(viewmodel));
     }
 }
        public ActionResult Index()
        {
            using (var db = new BeerWeb.Models.BeerModel())
            {
                var viewModel = new ViewModels.HomePageViewModel();
                viewModel.CategoryList.AddRange(db.Categories);

                return(View(viewModel));
            }
        }
Exemple #3
0
        void SetupAvailableCatgoriesEdit(EditProductViewModel model)
        {
            using (var entities = new BeerWeb.Models.BeerModel())
            {
                model.Category = new List <SelectListItem>
                {
                    new SelectListItem {
                        Value = null, Text = "Choose a category.."
                    },
                };

                foreach (var item in entities.Categories)
                {
                    var cat = new SelectListItem {
                        Value = item.Id.ToString(), Text = item.Name
                    };
                    model.Category.Add(cat);
                }
                ;
            }
        }
Exemple #4
0
        public ActionResult NewProduct(NewProductViewModel model)
        {
            SetupAvailableCatgoriesNew(model);
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            using (var entities = new BeerWeb.Models.BeerModel())
            {
                var newproduct = new Models.Product
                {
                    Category_Id = model.Category_Id,
                    Name        = model.Name,
                    Description = model.Description,
                    PicURL      = model.PicURL,
                    Price       = model.Price
                };
                entities.Products.Add(newproduct);
                entities.SaveChanges();

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