Exemplo n.º 1
0
        public async Task <IActionResult> Update(HamperUpdateViewModel vm)
        {
            Hamper h = _hamperManager.Read(vm.HamperId);

            if (h == null)
            {
                return(NotFound());
            }
            if (vm.File != null)
            {
                var    uploadPath = Path.Combine(environment.WebRootPath, "uploads/hampers/");
                string extension  = Path.GetExtension(vm.File.FileName);
                string fileName   = StringFormatHelper.ToTitleCase(h.HamperName) + "-1" + extension;
                using (var fileStream = new FileStream(Path.Combine(uploadPath, fileName), FileMode.Create))
                {
                    await vm.File.CopyToAsync(fileStream);
                }
                h.Picture = fileName;
            }
            h.HamperDescription = vm.HamperDescription;
            h.HamperName        = vm.HamperName;
            h.HamperPrice       = vm.HamperPrice;
            h.CategoryId        = vm.CategoryId;
            h.Active            = !vm.Retired;

            _hamperManager.Update(h);

            return(Redirect(vm.ReturnUrl));
        }
Exemplo n.º 2
0
        public IActionResult Update(HamperUpdateViewModel vm)
        {
            string uniqueFileName = null;

            if (vm.Image != null)
            {
                string uploadFolder = Path.Combine(_hostingEnvironmentServices.WebRootPath + "\\images");
                uniqueFileName = Guid.NewGuid().ToString() + "_" + vm.Image.FileName;
                string FilePath = Path.Combine(uploadFolder, uniqueFileName);
                vm.Image.CopyTo(new FileStream(FilePath, FileMode.Create));
            }
            //map
            Hamper updatedHamper = new Hamper
            {
                HamperId   = vm.HamperId,
                CategoryId = vm.CategoryId,
                Name       = vm.Name,
                Details    = vm.Details,
                Price      = vm.Price,
                Image      = uniqueFileName
            };

            //call service
            _hamperService.Update(updatedHamper);
            //go to
            return(RedirectToAction("Details", "Category", new { id = vm.CategoryId }));
        }
Exemplo n.º 3
0
        public IActionResult Update(int id)
        {
            //call service
            Hamper hamper = _hamperService.GetSingle(p => p.HamperId == id);

            HamperUpdateViewModel vm = new HamperUpdateViewModel
            {
                HamperId   = id,
                Name       = hamper.Name,
                Details    = hamper.Details,
                Price      = hamper.Price,
                CategoryId = hamper.CategoryId
            };

            return(View(vm));
        }
Exemplo n.º 4
0
        public IActionResult Update(string id, string url = "~/Hamper/")
        {
            Hamper h = _hamperManager.Read(id);

            if (h == null)
            {
                return(NotFound());
            }
            HamperUpdateViewModel vm = new HamperUpdateViewModel
            {
                Categories        = _categoryManager.GetAll(),
                CategoryId        = h.CategoryId,
                HamperDescription = h.HamperDescription,
                HamperName        = h.HamperName,
                HamperPrice       = h.HamperPrice,
                Retired           = !h.Active,
                HamperId          = h.HamperId,
                Picture           = h.Picture,
                ReturnUrl         = url
            };

            return(View(vm));
        }