//return product and all categorys for adding product or editing it
        public async Task <AdminCreateProductViewModel> GetProduct(int?id)
        {
            if (id == null)
            {
                return(null);
            }

            var product = await db.Products.Where(x => x.Id == id).Include(x => x.ProductTags)
                          .FirstOrDefaultAsync();

            var categories = await db.Categories.Where(x => !x.RemoveDate.HasValue).ToListAsync();

            if (product == null)
            {
                return(null);
            }

            AdminCreateProductViewModel respons = new AdminCreateProductViewModel()
            {
                Product    = product,
                categories = categories
            };

            return(respons);
        }
Beispiel #2
0
        public async Task <IActionResult> Create()
        {
            var createProductViewModel = new AdminCreateProductViewModel {
                Categories = await GetCategoriesAsync()
            };

            return(View(createProductViewModel));
        }
        public async Task <IActionResult> AddCategoryToProduct(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AdminCreateProductViewModel vm = await adminServices.GetProduct(id);

            return(View(vm));
        }
        // GET: AdminProducts/Create
        public async Task <IActionResult> Create()
        {
            AdminCreateProductViewModel adminProductViewModel = new AdminCreateProductViewModel()
            {
                Product    = new Product(),
                categories = await adminServices.GetCategoriesAsync()
            };

            return(View(adminProductViewModel));
        }
        // GET: AdminProducts/Details/5
        public async Task <IActionResult> Details(int?id)
        {
            AdminCreateProductViewModel product = await adminServices.GetProduct(id);

            if (product == null)
            {
                return(NotFound());
            }
            return(View(product.Product));
        }
Beispiel #6
0
        public async Task <IActionResult> Create(AdminCreateProductViewModel createProductViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(new AdminCreateProductViewModel {
                    Categories = await GetCategoriesAsync()
                }));
            }

            var product        = _mapper.Map <Product>(createProductViewModel.Product);
            var uploadedImages = UploadedImages(createProductViewModel.Product.ProductImages);

            product.Image         = uploadedImages.FirstOrDefault().ImageUrl.ToString();
            product.ProductImages = _mapper.Map <ICollection <ProductImage> >(uploadedImages);

            await _productService.AddAsnyc(product);

            return(RedirectToAction("Index"));
        }