public async Task <IActionResult> UploadCourseImage(UploadCourseCover model) { if (!ModelState.IsValid) { return(BadRequest()); } var course = _courseData.GetFullCourse(model.CourseId); if (course == null) { return(NotFound()); } string path = _hostingEnv.WebRootPath + $"{Path.DirectorySeparatorChar}images{Path.DirectorySeparatorChar}coursesMainImages{Path.DirectorySeparatorChar}" + model.File.FileName; using (var fileStream = new FileStream(path, FileMode.Create)) { await model.File.CopyToAsync(fileStream); } var urlPath = $"/images/coursesMainImages/{model.File.FileName}"; course.ImageUrl = urlPath; course.LocalImageUrl = path; _courseData.UpdateCourse(course); return(Ok(new { ImageUrl = urlPath })); }
public async Task <IActionResult> Create([FromBody] CoursePostViewModel course) { var courseForSave = _mapper.Map <CoursePostViewModel, Course>(course); courseForSave.Author = await _userManager.GetUserAsync(HttpContext.User); _courseData.AddCourse(courseForSave); var courseFromDb = _courseData.GetCourseByName(course.Name); var category = _courseData.GetCategories().FirstOrDefault(c => c.Name.ToLower() == course.Category.ToLower()); if (category == null) { category = new Category { Name = course.Category }; _courseData.AddCategory(category); } _courseData.AddCategoryToCourse(category, courseFromDb); _courseData.UpdateCourse(courseFromDb); return(Json(new { result = "Redirect", url = Url.Action("UploadContent", "Course", new { id = courseFromDb.Id }) })); }
public IActionResult UpdateCourse(int id, CourseDto course) { if (!ModelState.IsValid) { return(BadRequest()); } var courseFromDb = _data.GetFullCourse(id); var courseForSave = _mapper.Map(course, courseFromDb); _data.UpdateCourse(courseForSave); return(Ok()); }