예제 #1
0
 public ShoesController(ApplicationDbContext db, HostingEnvironment HostingEnvironment)
 {
     _db = db;
     _HostingEnvironment = HostingEnvironment;
     shoeVM = new ShoesViewModel()
     {
         shoeTypes = _db.ShoeTypes.ToList(),
         brands    = _db.Brands.ToList(),
         Shoes     = new Models.Shoes(),
     };
 }
예제 #2
0
 public ShoesController(ApplicationDbContext db, IWebHostEnvironment hostingEnvironment)
 {
     _db = db;
     _hostingEnvironment = hostingEnvironment;
     ShoesVM             = new ShoesViewModel
     {
         ProductTypes = _db.ProductTypes.ToList(),
         Brands       = _db.Brands.ToList(),
         SpecialTags  = _db.SpecialTags.ToList(),
         Shoes        = new Models.Shoes()
     };
 }
예제 #3
0
        public List <ShoesViewModel> GetAll()
        {
            List <Shoes> lsShoes = _shoesRepository
                                   .GetAll()
                                   .Where(s => s.IsAvaiable == true)
                                   .Include(s => s.ShoesHasSize)
                                   .Include(a => a.Brand)
                                   .ToList();

            List <ShoesViewModel> lsShoesVM      = new List <ShoesViewModel>();
            ShoesViewModel        shoesVM        = null;
            ShoesHasSizeViewModel shoesHasSizeVM = null;

            foreach (var shoes in lsShoes)
            {
                shoesVM = new ShoesViewModel()
                {
                    Id          = shoes.Id,
                    BrandId     = shoes.BrandId,
                    BrandName   = shoes.Brand.Name,
                    Color       = shoes.Color,
                    IsAvaiable  = shoes.IsAvaiable,
                    Name        = shoes.Name,
                    Description = shoes.Description,
                    Price       = shoes.Price,
                    Sex         = shoes.Sex
                };

                foreach (var shs in shoes.ShoesHasSize)
                {
                    ShoesHasSize shoesHasSize = _shoesHasSizeRepository.GetAll()
                                                .Where(h => h.Id == shs.Id).Include(h => h.Size).FirstOrDefault();
                    shoesHasSizeVM = new ShoesHasSizeViewModel()
                    {
                        Id       = shoesHasSize.Id,
                        Quantity = shoesHasSize.Quantity,
                        Scale    = shoesHasSize.Size.Scale,
                        ShoesId  = shoesHasSize.ShoesId,
                        SizeId   = shoesHasSize.SizeId
                    };
                    shoesVM.ShoesHasSizes.Add(shoesHasSizeVM);
                }

                List <Image> images = _imageRepository.GetAll().Where(i => i.IsShoes == true && i.OwnId == shoes.Id).ToList();
                shoesVM.Images = images;
                lsShoesVM.Add(shoesVM);
            }
            return(lsShoesVM);
        }
        private string UploadedFile(ShoesViewModel model)
        {
            string uniqueFileName = null;

            if (model.ProductImage != null)
            {
                string uploadsFolder = Path.Combine(_webHostEnvironment.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProductImage.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ProductImage.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
        public IActionResult Create([FromForm] ShoesViewModel model)
        {
            string uniqueFileName = UploadedFile(model);

            var productDto = new ProductDto
            {
                Id        = model.Id,
                BrandName = model.BrandName,
                Title     = model.Title,
                Genre     = model.Genre,
                Size      = model.Size,
                Price     = model.Price,
                Image     = uniqueFileName
            };

            _productService.Add(productDto);

            return(RedirectToAction("Details", new { id = productDto.Id }));
            //return RedirectToAction(nameof(Index));
        }
        public IActionResult Details(int id)
        {
            var productDto = _productService.Get(id);

            if (productDto == null)
            {
                return(View("NotFound"));
            }
            var model = new ShoesViewModel
            {
                Id        = productDto.Id,
                Image     = productDto.Image,
                BrandName = productDto.BrandName,
                Title     = productDto.Title,
                Genre     = productDto.Genre,
                Price     = productDto.Price,
                Size      = productDto.Size
            };

            return(View(model));
        }
        public IActionResult Edit(int id)
        {
            ViewBag.Test = _brandService.GetAll();
            var product = _productService.Get(id);

            if (product == null)
            {
                return(RedirectToAction("Index"));
            }
            var model = new ShoesViewModel
            {
                Id        = product.Id,
                Image     = product.Image,
                BrandName = product.BrandName,
                Title     = product.Title,
                Genre     = product.Genre,
                Price     = product.Price,
                Size      = product.Size
            };

            return(View(model));
        }
        public IActionResult Edit([FromForm] ShoesViewModel shoesViewModel)
        {
            string uniqueFileName = UploadedFile(shoesViewModel);
            var    product        = _productService.Get(shoesViewModel.Id);

            if (product == null)
            {
                return(RedirectToAction("Index"));
            }
            if (ModelState.IsValid)
            {
                product.Id        = shoesViewModel.Id;
                product.Image     = uniqueFileName;
                product.BrandName = shoesViewModel.BrandName;
                product.Title     = shoesViewModel.Title;
                product.Genre     = shoesViewModel.Genre;
                product.Price     = shoesViewModel.Price;
                product.Size      = shoesViewModel.Size;

                _productService.Update(product);
            }
            return(RedirectToAction("Details", new { id = shoesViewModel.Id }));
            //return RedirectToAction("Index");
        }
예제 #9
0
        public ShoesViewModel GetShoesById(int id)
        {
            ShoesViewModel shoesVM = _shoesService.GetShoesById(id);

            return(shoesVM);
        }