Example #1
0
        public IResult Delete(CarImage carImage)
        {
            var deletedImage = _carImageDal.Get(c => c.Id == carImage.Id);
            var existingPath = ExistingPath(deletedImage.ImagePath);

            FileManagerHelper.Delete(existingPath);
            _carImageDal.Delete(deletedImage);
            return(new SuccessResult(Messages.Success));
        }
        public async Task <IActionResult> Edit(Testimonial testimonial)
        {
            Testimonial existTestimonial = await _context.Testimonials.FirstOrDefaultAsync(s => s.Id == testimonial.Id);

            #region CheckTestimonial

            if (existTestimonial == null)
            {
                return(NotFound());
            }
            #endregion

            existTestimonial.Fullname   = testimonial.Fullname;
            existTestimonial.Desc       = testimonial.Desc;
            existTestimonial.Occupation = testimonial.Occupation;
            existTestimonial.Place      = testimonial.Place;

            #region ModelStateCheck
            if (!ModelState.IsValid)
            {
                return(View(testimonial));
            }
            #endregion

            if (testimonial.File != null)
            {
                #region CheckPhotoLength
                if (testimonial.File.Length > 3 * (1024 * 1024))
                {
                    ModelState.AddModelError("File", "Cannot be more than 3MB");
                    return(View());
                }
                #endregion
                #region CheckPhotoContentType
                if (testimonial.File.ContentType != "image/png" && testimonial.File.ContentType != "image/jpeg")
                {
                    ModelState.AddModelError("File", "Only jpeg and png files accepted");
                    return(View());
                }
                #endregion

                string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/testimonials", existTestimonial.File);

                if (!string.IsNullOrWhiteSpace(existTestimonial.ProfilePhoto))
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/testimonials", existTestimonial.ProfilePhoto);
                }

                existTestimonial.ProfilePhoto = filename;
            }


            await _context.SaveChangesAsync();

            return(RedirectToAction("index"));
        }
Example #3
0
        public async Task <IActionResult> Edit(Slider slider)
        {
            Slider existSlider = await _context.Sliders.FirstOrDefaultAsync(s => s.Id == slider.Id);

            #region CheckSlider

            if (existSlider == null)
            {
                return(NotFound());
            }
            #endregion

            existSlider.Title       = slider.Title;
            existSlider.Desc        = slider.Desc;
            existSlider.RedirectUrl = slider.RedirectUrl;
            existSlider.Order       = slider.Order;

            #region ModelStateCheck
            if (ModelState.IsValid)
            {
                return(View(slider));
            }
            #endregion

            if (slider.File != null)
            {
                #region CheckPhotoLength
                if (slider.File.Length > 3 * (1024 * 1024))
                {
                    ModelState.AddModelError("File", "Cannot be more than 3MB");
                    return(View());
                }
                #endregion
                #region CheckPhotoContentType
                if (slider.File.ContentType != "image/png" && slider.File.ContentType != "image/jpeg")
                {
                    ModelState.AddModelError("File", "Only jpeg and png files accepted");
                    return(View());
                }
                #endregion

                string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/sliders", slider.File);

                if (!string.IsNullOrWhiteSpace(existSlider.Photo))
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/sliders", existSlider.Photo);
                }

                existSlider.Photo = filename;
            }


            await _context.SaveChangesAsync();

            return(RedirectToAction("index"));
        }
Example #4
0
        public async Task <IActionResult> Edit(Teacher teacher)
        {
            Teacher existTeacher = await _context.Teachers.FirstOrDefaultAsync(s => s.Id == teacher.Id);

            #region CheckSlider

            if (existTeacher == null)
            {
                return(NotFound());
            }
            #endregion

            existTeacher.FullName                = teacher.FullName;
            existTeacher.Desc                    = teacher.Desc;
            existTeacher.Degree                  = teacher.Degree;
            existTeacher.Faculty                 = teacher.Faculty;
            existTeacher.TeachingStatus          = teacher.TeachingStatus;
            existTeacher.Experience              = teacher.Experience;
            existTeacher.Hobby                   = teacher.Hobby;
            existTeacher.Email                   = teacher.Email;
            existTeacher.PhoneNumber             = teacher.PhoneNumber;
            existTeacher.Skype                   = teacher.Skype;
            existTeacher.FacebookUrl             = teacher.FacebookUrl;
            existTeacher.PinterestUrl            = teacher.PinterestUrl;
            existTeacher.VimeoUrl                = teacher.VimeoUrl;
            existTeacher.TwitterUrl              = teacher.TwitterUrl;
            existTeacher.PinterestUrl            = teacher.PinterestUrl;
            existTeacher.LanguagePercentage      = teacher.LanguagePercentage;
            existTeacher.TeamLeaderPercentage    = teacher.TeamLeaderPercentage;
            existTeacher.DevelopmentPercentage   = teacher.DevelopmentPercentage;
            existTeacher.DesignPercentage        = teacher.DesignPercentage;
            existTeacher.InnovationPercentage    = teacher.InnovationPercentage;
            existTeacher.ModifiedAt              = DateTime.UtcNow;
            existTeacher.CommunicationPercentage = teacher.CommunicationPercentage;

            #region ModelStateCheck
            if (!ModelState.IsValid)
            {
                return(View(teacher));
            }
            #endregion

            if (teacher.File != null)
            {
                #region CheckPhotoLength
                if (teacher.File.Length > 3 * (1024 * 1024))
                {
                    ModelState.AddModelError("File", "Cannot be more than 3MB");
                    return(View());
                }
                #endregion
                #region CheckPhotoContentType
                if (teacher.File.ContentType != "image/png" && teacher.File.ContentType != "image/jpeg")
                {
                    ModelState.AddModelError("File", "Only jpeg and png files accepted");
                    return(View());
                }
                #endregion

                string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/teachers", teacher.File);

                if (!string.IsNullOrWhiteSpace(existTeacher.Photo))
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/teachers", existTeacher.Photo);
                }

                existTeacher.Photo = filename;
            }


            await _context.SaveChangesAsync();

            return(RedirectToAction("index"));
        }
        public async Task <IActionResult> Edit(Setting setting)
        {
            Setting existSetting = await _context.Settings.FirstOrDefaultAsync(s => s.Id == setting.Id);

            #region CheckSlider

            if (existSetting == null)
            {
                return(NotFound());
            }
            #endregion


            existSetting.SupportPhone = setting.SupportPhone;
            existSetting.FooterDesc   = setting.FooterDesc;
            existSetting.ServicePhone = setting.ServicePhone;
            existSetting.Address      = setting.Address;
            existSetting.SupportEmail = setting.SupportEmail;
            existSetting.Webname      = setting.Webname;
            existSetting.FacebookUrl  = setting.FacebookUrl;
            existSetting.TwitterUrl   = setting.TwitterUrl;
            existSetting.VimeoUrl     = setting.VimeoUrl;
            existSetting.PinterestUrl = setting.PinterestUrl;
            existSetting.AboutTitle   = setting.AboutTitle;
            existSetting.AboutDesc    = setting.AboutDesc;



            #region ModelStateCheck
            if (!ModelState.IsValid)
            {
                return(View(setting));
            }
            #endregion

            setting.Files.Add(setting.Header);
            setting.Files.Add(setting.Footer);
            setting.Files.Add(setting.AboutFile);

            if (setting.Header != null || setting.Footer != null || setting.AboutFile != null)
            {
                if (setting.Header != null)
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/setting", existSetting.HeaderLogo);
                    setting.Files.Add(setting.Header);
                }

                if (setting.Footer != null)
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/setting", existSetting.FooterLogo);
                    setting.Files.Add(setting.Footer);
                }

                if (setting.AboutFile != null)
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/setting", existSetting.AboutPhoto);
                    setting.Files.Add(setting.AboutFile);
                }


                foreach (var file in setting.Files)
                {
                    #region CheckPhotoLength
                    if (file.Length > 3 * (1024 * 1024))
                    {
                        ModelState.AddModelError("File", "Cannot be more than 3MB");
                        return(View());
                    }
                    #endregion
                    #region CheckPhotoContentType
                    if (file.ContentType != "image/png" && file.ContentType != "image/jpeg")
                    {
                        ModelState.AddModelError("File", "Only jpeg and png files accepted");
                        return(View());
                    }
                    #endregion
                    if (setting.Header != null)
                    {
                        if (file.Name.Trim().ToLower() == setting.Header.Name.Trim().ToLower())
                        {
                            string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/setting", file);
                            existSetting.HeaderLogo = filename;
                        }
                    }
                    if (setting.Footer != null)
                    {
                        if (file.Name.Trim().ToLower() == setting.Footer.Name.Trim().ToLower())
                        {
                            string fileName = FileManagerHelper.Save(_env.WebRootPath, "uploads/setting", file);
                            existSetting.FooterLogo = fileName;
                        }
                    }

                    if (setting.AboutFile != null)
                    {
                        if (file.Name.Trim().ToLower() == setting.AboutFile.Name.Trim().ToLower())
                        {
                            string fileName = FileManagerHelper.Save(_env.WebRootPath, "uploads/setting", file);
                            existSetting.AboutPhoto = fileName;
                        }
                    }
                }
            }



            await _context.SaveChangesAsync();

            return(RedirectToAction("index"));
        }
Example #6
0
        public async Task <IActionResult> Edit(Course course)
        {
            Course existCourse = await _context.Courses
                                 .Include(x => x.CourseTags)
                                 .FirstOrDefaultAsync(x => x.Id == course.Id);

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

            if (!await _context.Categories.AnyAsync(x => x.Id == course.CategoryId))
            {
                return(NotFound());
            }

            if (await _context.Courses.AnyAsync(x => x.Slug.ToLower() == course.Slug.Trim().ToLower() && x.Id != course.Id))
            {
                return(NotFound());
            }

            existCourse.CourseTags = await _getUpdatedCourseTagsAsync(existCourse.CourseTags, course.TagIds, course.Id);

            if (course.File != null)
            {
                #region PhotoLengthChecking
                if (course.File.Length > 3 * (1024 * 1024))
                {
                    ModelState.AddModelError("File", "Cannot be more than 3MB");
                    return(View());
                }
                #endregion
                #region PhotoContentTypeChecking
                if (course.File.ContentType != "image/png" && course.File.ContentType != "image/jpeg")
                {
                    ModelState.AddModelError("File", "Only jpeg and png files accepted");
                    return(View());
                }
                #endregion

                string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/courses", course.File);

                if (!string.IsNullOrWhiteSpace(existCourse.Photo))
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/courses", existCourse.Photo);
                }

                existCourse.Photo = filename;
            }

            existCourse.Name              = course.Name.Trim();
            existCourse.Slug              = course.Slug.Trim();
            existCourse.Desc              = course.Desc;
            existCourse.AboutText         = course.AboutText;
            existCourse.ApplyText         = course.ApplyText;
            existCourse.CertificationText = course.CertificationText;
            existCourse.CategoryId        = course.CategoryId;
            existCourse.Price             = course.Price;
            existCourse.Start             = course.Start;
            existCourse.Duration          = course.Duration;
            existCourse.Hours             = course.Hours;
            existCourse.SkillLevel        = course.SkillLevel;
            existCourse.StudentCount      = course.StudentCount;
            existCourse.Language          = course.Language;
            existCourse.ModifiedAt        = DateTime.UtcNow;

            await _context.SaveChangesAsync();

            return(RedirectToAction("index"));
        }
        public async Task <IActionResult> Edit(Event eventModel)
        {
            Event existEvent = await _context.Events
                               .Include(x => x.EventTags).Include(x => x.EventTeachers)
                               .FirstOrDefaultAsync(x => x.Id == eventModel.Id);

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

            if (!await _context.Categories.AnyAsync(x => x.Id == eventModel.CategoryId))
            {
                return(NotFound());
            }

            if (await _context.Events.AnyAsync(x => x.Title.ToLower() == eventModel.Title.Trim().ToLower() && x.Id != eventModel.Id))
            {
                return(NotFound());
            }

            existEvent.EventTags = await _getUpdatedEventTagsAsync(existEvent.EventTags, eventModel.TagIds, eventModel.Id);

            if (eventModel.File != null)
            {
                #region PhotoLengthChecking
                if (eventModel.File.Length > 3 * (1024 * 1024))
                {
                    ModelState.AddModelError("File", "Cannot be more than 3MB");
                    return(View());
                }
                #endregion
                #region PhotoContentTypeChecking
                if (eventModel.File.ContentType != "image/png" && eventModel.File.ContentType != "image/jpeg")
                {
                    ModelState.AddModelError("File", "Only jpeg and png files accepted");
                    return(View());
                }
                #endregion

                string filename = FileManagerHelper.Save(_env.WebRootPath, "uploads/events", eventModel.File);

                if (!string.IsNullOrWhiteSpace(existEvent.Photo))
                {
                    FileManagerHelper.Delete(_env.WebRootPath, "uploads/events", existEvent.Photo);
                }

                existEvent.Photo = filename;
            }

            existEvent.Title      = eventModel.Title.Trim();
            existEvent.Venue      = eventModel.Venue;
            existEvent.Desc       = eventModel.Desc;
            existEvent.StartDate  = eventModel.StartDate;
            existEvent.EndDate    = eventModel.EndDate;
            existEvent.EventDate  = eventModel.EventDate;
            existEvent.ModifiedAt = DateTime.UtcNow;

            await _context.SaveChangesAsync();

            return(RedirectToAction("index"));
        }