Esempio n. 1
0
        public IActionResult Create(int id)
        {
            Hamper hamper = new Hamper();

            if (id != 0)
            {
                hamper = _hamperRepo.GetSingle(h => h.HamperId == id);
            }

            CreateHamperViewModel vm = new CreateHamperViewModel();

            vm.HamperGifts = _hamperGiftRepo.Query(hg => hg.HamperId == hamper.HamperId);
            vm.Categories  = _categoryRepo.Query(c => c.Active == true);
            vm.Hamper      = hamper;

            return(View(vm));
        }
Esempio n. 2
0
        public IActionResult Create(CreateHamperViewModel vm, int id, IFormFile PhotoPath)
        {
            IEnumerable <HamperGift> hamperGifts = vm.HamperGifts;
            Category category     = _categoryRepo.GetSingle(c => c.CategoryId == vm.SelectedCategoryId);
            string   categoryName = _categoryRepo.GetSingle(c => c.CategoryId == vm.SelectedCategoryId).Name;

            Hamper hamper = new Hamper();

            if (id != 0)
            {
                hamper = _hamperRepo.GetSingle(h => h.HamperId == id);
            }

            hamper.Name        = vm.Name;
            hamper.Price       = vm.Price;
            hamper.HamperGifts = vm.HamperGifts;
            hamper.CategoryId  = vm.SelectedCategoryId;
            hamper.Active      = true;

            if (PhotoPath != null)
            {
                string uploadPath = Path.Combine(_hostingEnviro.WebRootPath, "Media\\Hamper");
                string filename   = hamper.Name + Path.GetExtension(PhotoPath.FileName);
                uploadPath = Path.Combine(uploadPath, filename);


                using (FileStream fs = new FileStream(uploadPath, FileMode.Create))
                {
                    PhotoPath.CopyTo(fs);
                }
                string SaveFilename = Path.Combine("Media\\Hamper", filename);
                hamper.PhotoPath = SaveFilename;
            }
            else
            {
                hamper.PhotoPath = hamper.PhotoPath;
            }

            _hamperRepo.Create(hamper);


            return(RedirectToAction("Index"));
        }