예제 #1
0
        public async Task <IActionResult> Index()
        {
            AboutWelcome          aboutWelcome = _db.AboutWelcomes.FirstOrDefault();
            ICollection <Teacher> teachers     = await _db.Teachers.Include(t => t.TeacherContact).Take(4).ToListAsync();

            AboutSlider aboutSlider = await _db.AboutSliders.FirstOrDefaultAsync();

            AboutVideo aboutVideo = await _db.AboutVideos.FirstOrDefaultAsync();

            ICollection <AboutNotice> aboutNotices = await _db.AboutNotices.Take(6).ToListAsync();

            Bio bio = await _db.Bios.FirstOrDefaultAsync();

            AboutVM aboutVM = new AboutVM()
            {
                AboutWelcome = aboutWelcome,
                Teachers     = teachers,
                Bio          = bio,
                AboutSlider  = aboutSlider,
                AboutVideo   = aboutVideo,
                AboutNotices = aboutNotices
            };

            return(View(aboutVM));
        }
        public async Task <IActionResult> Create(AboutSlider slider)
        {
            if (slider.Photo != null)
            {
                if (!slider.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "You can chose only image format");
                    return(View());
                }

                if (!slider.Photo.CheckSize(2))
                {
                    ModelState.AddModelError("Photo", "You can chose only small 2 MB");
                    return(View());
                }


                string createdImage = await slider.Photo.CopyImage(_env.WebRootPath, "team");

                #region
                AboutSlider newslider = new AboutSlider()
                {
                    ImagePath = createdImage
                };
                #endregion



                await _remindb.AboutSliders.AddAsync(newslider);
            }

            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Detail(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider FindaboutSlider = await _db.AboutSliders.FindAsync(id);

            return(View(FindaboutSlider));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider aboutSliderFind = await _db.AboutSliders.FindAsync(id);

            if (aboutSliderFind == null)
            {
                return(NotFound());
            }
            return(View(aboutSliderFind));
        }
        public async Task <IActionResult> Delete(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider slider = _remindb.AboutSliders.FirstOrDefault(a => a.Id == id);;

            if (slider == null)
            {
                return(NotFound());
            }
            return(View(slider));
        }
        public async Task <IActionResult> Update(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider slider = await _remindb.AboutSliders.FirstOrDefaultAsync(x => x.Id == id);

            if (slider == null)
            {
                return(NotFound());
            }
            return(View(slider));
        }
        public async Task <IActionResult> Create(AboutSlider aboutSlider)
        {
            //if (!ModelState.IsValid)
            //{
            //    return View();
            //}
            if (aboutSlider.Photo == null)
            {
                ModelState.AddModelError("", "Please choose a photo");
                return(View());
            }
            if (!aboutSlider.Photo.IsImage())
            {
                ModelState.AddModelError("Photo", "Please select a picture format!");
                return(View());
            }
            if (aboutSlider.Photo.MaxLenght(500))
            {
                ModelState.AddModelError("Photo", "Select the selected image size should be a maximum of 200-kb !");
                return(View());
            }
            //if (aboutSlider.BackgroundPhoto == null)
            //{
            //    ModelState.AddModelError("", "Please choose a photo");
            //    return View();
            //}
            if (aboutSlider.BackgroundPhoto != null)
            {
                if (!aboutSlider.BackgroundPhoto.IsImage())
                {
                    ModelState.AddModelError("Photo", "Please select a picture format!");
                    return(View());
                }
                if (aboutSlider.BackgroundPhoto.MaxLenght(500))
                {
                    ModelState.AddModelError("Photo", "Select the selected image size should be a maximum of 200-kb !");
                    return(View());
                }
            }

            aboutSlider.Image = await aboutSlider.Photo.SaveImage(_env.WebRootPath, "img/testimonial");

            aboutSlider.BackgroundImage = await aboutSlider.BackgroundPhoto.SaveImage(_env.WebRootPath, "img/testimonial");

            _db.AboutSliders.Add(aboutSlider);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider aboutSliderFind = await _db.AboutSliders.FindAsync(id);

            if (aboutSliderFind == null)
            {
                return(NotFound());
            }
            PhotoFileDelete.IsDeletePhoto(_env.WebRootPath, "img/testimonial", aboutSliderFind.Image);
            PhotoFileDelete.IsDeletePhoto(_env.WebRootPath, "img/testimonial", aboutSliderFind.BackgroundImage);
            _db.AboutSliders.Remove(aboutSliderFind);
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Update(int?id, AboutSlider upslider)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider _sliderdb = await _remindb.AboutSliders.FirstOrDefaultAsync(x => x.Id == id);

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


            if (upslider.ChangePhoto != null)
            {
                if (!upslider.ChangePhoto.IsImage())
                {
                    ModelState.AddModelError("ChangePhoto", "You can chose only image format");
                    return(View());
                }

                if (!upslider.ChangePhoto.CheckSize(2))
                {
                    ModelState.AddModelError("ChangePhoto", "You can chose only small 2 MB");
                    return(View());
                }


                string updateimage = await upslider.ChangePhoto.CopyImage(_env.WebRootPath, "team");

                upslider.ImagePath = updateimage;
                DeleteImage.DeleteFromFolder(_env.WebRootPath, _sliderdb.ImagePath);
            }

            _sliderdb.ImagePath = upslider.ImagePath;



            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> DeletePost(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider sliderdb = await _remindb.AboutSliders.FirstOrDefaultAsync(x => x.Id == id);

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


            _remindb.AboutSliders.Remove(sliderdb);
            await _remindb.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
        public async Task <IActionResult> Edit(int?id, AboutSlider aboutSlider)
        {
            if (id == null)
            {
                return(NotFound());
            }
            AboutSlider aboutSliderFind = await _db.AboutSliders.FindAsync(id);

            if (aboutSliderFind == null)
            {
                return(NotFound());
            }
            if (aboutSlider.Photo != null)
            {
                if (!aboutSlider.Photo.IsImage())
                {
                    ModelState.AddModelError("Photo", "Please select a picture format!");
                    return(View());
                }

                PhotoFileDelete.IsDeletePhoto(_env.WebRootPath, "img/testimonial", aboutSliderFind.Image);
                aboutSliderFind.Image = await aboutSlider.Photo.SaveImage(_env.WebRootPath, "img/testimonial");
            }
            if (aboutSlider.BackgroundPhoto != null)
            {
                if (!aboutSlider.BackgroundPhoto.IsImage())
                {
                    ModelState.AddModelError("Photo", "Please select a picture format!");
                    return(View());
                }

                PhotoFileDelete.IsDeletePhoto(_env.WebRootPath, "img/testimonial", aboutSliderFind.BackgroundImage);
                aboutSliderFind.BackgroundImage = await aboutSlider.BackgroundPhoto.SaveImage(_env.WebRootPath, "img/testimonial");
            }

            aboutSliderFind.Name        = aboutSlider.Name;
            aboutSliderFind.Position    = aboutSlider.Position;
            aboutSliderFind.Description = aboutSlider.Description;
            await _db.SaveChangesAsync();

            return(RedirectToAction(nameof(Index)));
        }
예제 #12
0
        public async Task <IActionResult> Index()
        {
            ICollection <HomeSlider> homeSliders = await _db.HomeSliders.ToListAsync();

            ICollection <Course> courses = await _db.Courses.Take(3).ToListAsync();

            ICollection <AboutNotice> aboutNotices = await _db.AboutNotices.Take(5).ToListAsync();

            ICollection <Event> events = await _db.Events.Take(4).ToListAsync();

            AboutSlider aboutSliders = await _db.AboutSliders.FirstOrDefaultAsync();

            ICollection <Blog> blogs = await _db.Blogs.Take(3).ToListAsync();

            AboutVideo aboutVideo = await _db.AboutVideos.FirstOrDefaultAsync();

            ICollection <AppUser> appUser = await _userManager.Users.ToListAsync();

            AboutWelcome aboutWelcome = await _db.AboutWelcomes.FirstOrDefaultAsync();

            Bio bio = await _db.Bios.FirstOrDefaultAsync();

            HomeVM homeVM = new HomeVM()
            {
                HomeSliders  = homeSliders,
                AboutWelcome = aboutWelcome,
                Courses      = courses,
                AboutVideo   = aboutVideo,
                AboutNotices = aboutNotices,
                AboutSliders = aboutSliders,
                Events       = events,
                AppUser      = appUser,
                Blogs        = blogs,
                Bio          = bio
            };

            return(View(homeVM));
        }