示例#1
0
        public async Task <IActionResult> EditPost(int?id, SliderHome s)
        {
            SliderHome sliderdb = await _context.SliderHomes.FindAsync(id);

            if (sliderdb == null)
            {
                return(RedirectToAction(nameof(Slider)));
            }
            if (s.UpPhoto != null)
            {
                if (!s.UpPhoto.IsImage())
                {
                    ModelState.AddModelError("UpPhoto", "Plase PHOTO file choose");
                    return(View());
                }
                if (!s.UpPhoto.IsSmaller(1))
                {
                    ModelState.AddModelError("UpPhoto", "Plase PHOTO size maximum 1 mb must be");
                    return(View());
                }
                string filName = await s.UpPhoto.SaveFileAsync(_env.WebRootPath, "img", "slider");

                Utilities.Utility.DeleteImgFromFolder(_env.WebRootPath, @"img", @"slider", sliderdb.SImage);
                sliderdb.SImage = filName;
            }
            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Slider)));
        }
示例#2
0
        public async Task <IActionResult> Create(SliderHome photo)
        {
            if (ModelState.IsValid)
            {
                return(View(photo));
            }
            //Save photo
            if (!photo.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "Image type is not valid");
                return(View());
            }

            //image type is ok, chek size
            if (!photo.Photo.IsSmaller(1))
            {
                ModelState.AddModelError("Photo", "Image type can be maximom 1mb");
                return(View());
            }
            //image size is ok ,  save the image
            photo.SImage = await photo.Photo.SaveFileAsync(_env.WebRootPath, "img", "slider");

            await _context.SliderHomes.AddRangeAsync(photo);

            await _context.SaveChangesAsync();

            return(RedirectToAction(nameof(Slider)));
        }
示例#3
0
        //Slider Edit Page Start
        public async Task <IActionResult> Edit(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SliderHome slider = await _context.SliderHomes.FindAsync(id);

            if (slider == null)
            {
                return(NotFound());
            }

            return(View(slider));
        }
示例#4
0
        //Slider Delete Page Start
        public async Task <IActionResult> Delete(int?Id)
        {
            if (_context.SliderHomes.Count() <= 2)
            {
                return(RedirectToAction(nameof(Slider)));
            }
            if (Id == null)
            {
                return(NotFound());
            }

            SliderHome sliderHome = await _context.SliderHomes.FindAsync(Id);

            if (sliderHome == null)
            {
                return(NotFound());
            }

            return(View(sliderHome));
        }
示例#5
0
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            SliderHome sliderHome = await _context.SliderHomes.FindAsync(id);

            if (sliderHome == null)
            {
                return(NotFound());
            }


            Utilities.Utility.DeleteImgFromFolder(_env.WebRootPath, @"img", @"slider", sliderHome.SImage);

            _context.SliderHomes.Remove(sliderHome);

            await _context.SaveChangesAsync();

            TempData["success_message"] = "Slider was removed successfully";
            return(RedirectToAction(nameof(Slider)));
        }