Exemplo n.º 1
0
        public ViewResult List()
        {
            BagListViewModel bagListViewModel = new BagListViewModel();

            bagListViewModel.Bags            = bagRepo.AllBags;
            bagListViewModel.CurrentCategory = "ბეყე";

            return(View(bagListViewModel));
        }
Exemplo n.º 2
0
        //UploadFiles
        private string UploadedFile(BagListViewModel model)
        {
            string uniqueFileName = null;

            if (model.ProfileImage != null)
            {
                string uploadsFolder = Path.Combine(hostEnv.WebRootPath, "images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + model.ProfileImage.FileName;
                string filePath = Path.Combine(uploadsFolder, uniqueFileName);
                using (var fileStream = new FileStream(filePath, FileMode.Create))
                {
                    model.ProfileImage.CopyTo(fileStream);
                }
            }
            return(uniqueFileName);
        }
Exemplo n.º 3
0
        public async Task <IActionResult> Create([Bind("id,Name,Price,IsBagOfTheWeek,ProfilePicture")] BagListViewModel bag)
        {
            if (ModelState.IsValid)
            {
                string uniqueFileName = UploadedFile(bag);

                Bag bagItem = new Bag
                {
                    Name           = bag.BagName,
                    ProfilePicture = uniqueFileName
                };

                _context.Add(bagItem);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(bag));
        }