public ActionResult Create()
        {
            var viewmodel = new ViewModels.ProductViewModels.CreateProductViewModel();

            using (var entities = new EntityModel.DatabaseContext())
            {
                viewmodel.AvaiableProductCategories = Management.ActionHandler.SetupAvaiableCategoryTypes(entities.ProductCategorys.ToList());
            }
            return(View(viewmodel));
        }
 public static EntityModel.Product Create(this EntityModel.Product product, ViewModels.ProductViewModels.CreateProductViewModel viewmodel)
 {
     return(new EntityModel.Product()
     {
         Name = viewmodel.Name,
         Description = viewmodel.Description,
         Price = viewmodel.Price,
         ProductCategoryId = viewmodel.ProductCategoryId,
         IsValid = true
     });
 }
        public ActionResult Create(ViewModels.ProductViewModels.CreateProductViewModel viewmodel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewmodel));
            }

            using (var entities = new EntityModel.DatabaseContext())
            {
                viewmodel.ProductCategoryId         = entities.ProductCategorys.SingleOrDefault(x => x.Name == viewmodel.ProductCategoryName).Id;
                viewmodel.AvaiableProductCategories = Management.ActionHandler.SetupAvaiableCategoryTypes(entities.ProductCategorys.ToList());

                entities.Products.Add(Management.ActionHandler.Create(new EntityModel.Product(), viewmodel));
                entities.SaveChanges();

                var lastId = entities.Products.Where(c => c.IsValid).Count();
                return(RedirectToAction("ShowProduct", new { productId = lastId }));
            }
        }