public ActionResult Edit(CourseInputModel model) { if (model != null && ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var updatedArticle = this.Mapper.Map<Course>(model); var imageUploader = new ImageUplouder(); var images = new HashSet<Image>(); string folderPath = Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId); if (model.Files != null && model.Files.Count() > 0) { foreach (var file in model.Files) { if (file != null && (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) && file.ContentLength < WebConstants.MaxImageFileSize) { images.Add(imageUploader.UploadImage(file, folderPath, currentUserId)); } } } images.ForEach(x => updatedArticle.Images.Add(x)); this.courses.Update(model.Id, updatedArticle); return this.RedirectToAction("Course", "School", new { area = "", id = model.Id }); } return this.View(model); }
public ActionResult Create(CourseInputModel model) { if (model != null && this.ModelState.IsValid) { var currentUserId = this.UserProfile.Id; var newArticle = this.Mapper.Map<Course>(model); var imageUploader = new ImageUplouder(); var images = new HashSet<Image>(); string folderPath = Server.MapPath(WebConstants.ImagesMainPathMap + currentUserId); if (model.Files != null && model.Files.Count() > 0) { foreach (var file in model.Files) { if (file != null && (file.ContentType == WebConstants.ContentTypeJpg || file.ContentType == WebConstants.ContentTypePng) && file.ContentLength < WebConstants.MaxImageFileSize) { images.Add(imageUploader.UploadImage(file, folderPath, currentUserId)); } } } var trainer = this.users.UserById(currentUserId).FirstOrDefault(); newArticle.Trainers.Add(trainer); var result = this.courses.Create(newArticle); return this.RedirectToAction("Course", "School", new { area = "", id = result }); } return this.View(model); }
public ActionResult Create() { var courseInputModel = new CourseInputModel { AllCategories = this.categoryService.All().To<CategoryViewModel>().To<SelectListItem>().ToList() }; return this.View(courseInputModel); }
public ActionResult Create() { var courseInputModel = new CourseInputModel { AllCategories = this.categoryService.All().To <CategoryViewModel>().To <SelectListItem>().ToList() }; return(this.View(courseInputModel)); }
public ActionResult AddCourse(int id, CourseInputModel model) { if (!this.ModelState.IsValid) { return this.View(model); } int courseId = this.coursesService.AddCourse(model.Name, model.Description, model.SemesterId); return this.RedirectToAction("Details", "Courses", new { area = "Public", id = courseId }); }
public ActionResult AddCourseConfirm(CourseInputModel input) { Domain.Dto.Request.DtoCourse course = input.ConvertTo <Domain.Dto.Request.DtoCourse>(); course.CurrentUser = CurrentUserID; CourseBll bll = new CourseBll(); bll.AddCourse(course); return(Json(new SuccessJsonResponse(Url.Action(nameof(ListCurriculums))))); }
public ActionResult AddCourse(int id) { var specialty = this.specialtiesService.GetAll().FirstOrDefault(s => s.Id == id); if (specialty == null) { return this.RedirectToAction("NotFound"); } var model = new CourseInputModel() { SpecialtyName = specialty.Name, Semesters = specialty.Semesters.AsQueryable().To<SemesterViewModel>().ToList(), }; return this.View(model); }
public ActionResult Create(CourseInputModel courseInputModel) { if (this.ModelState.IsValid) { var course = this.Mapper.Map<Course>(courseInputModel); course.AuthorId = this.User.Identity.GetUserId(); this.courseService.Add(course); return this.RedirectToAction("Details", new { Id = course.Id }); } courseInputModel.AllCategories = this.categoryService.All().To<CategoryViewModel>().To<SelectListItem>().ToList(); return this.View(courseInputModel); }
public ActionResult Create(CourseInputModel courseInputModel) { if (this.ModelState.IsValid) { var course = this.Mapper.Map <Course>(courseInputModel); course.AuthorId = this.User.Identity.GetUserId(); this.courseService.Add(course); return(this.RedirectToAction("Details", new { Id = course.Id })); } courseInputModel.AllCategories = this.categoryService.All().To <CategoryViewModel>().To <SelectListItem>().ToList(); return(this.View(courseInputModel)); }
public ActionResult Edit(CourseInputModel courseInputModel) { if (this.ModelState.IsValid) { var course = this.courseService.GetById(courseInputModel.Id); course.Name = courseInputModel.Name; course.Description = courseInputModel.Description; course.CategoryId = courseInputModel.CategoryId; this.courseService.Update(course); return(this.RedirectToAction("Details", new { Id = course.Id })); } courseInputModel.AllCategories = this.categoryService.All().To <CategoryViewModel>().To <SelectListItem>().ToList(); return(this.View(courseInputModel)); }
public IHttpActionResult Create(CourseInputModel course) { if (!this.ModelState.IsValid) { return(BadRequest(this.ModelState)); } this.data .Courses .Add(new Course { Name = course.Name, Description = course.Description }); this.data.Courses.SaveChanges(); return(Ok(course)); }
public async Task <IActionResult> CreateCourse(CourseInputModel inputModel) { if (!this.ModelState.IsValid) { return(this.View(inputModel)); } var imageUri = string.Empty; if (inputModel.Thumbnail != null) { imageUri = this.coursesService.UploadImageToCloudinary(inputModel.Thumbnail.OpenReadStream()); } var userId = this.userManager.GetUserId(this.User); var course = await this.coursesService.CreateCourseAsync(inputModel.Name, inputModel.Category, inputModel.Difficulty, imageUri, inputModel.Description, userId); return(this.RedirectToAction(actionName: "CreateLesson", controllerName: "Lessons", routeValues: new CourseIdViewModel { CourseId = course.Id })); }
public ActionResult Edit(CourseInputModel courseInputModel) { if (this.ModelState.IsValid) { var course = this.courseService.GetById(courseInputModel.Id); course.Name = courseInputModel.Name; course.Description = courseInputModel.Description; course.CategoryId = courseInputModel.CategoryId; this.courseService.Update(course); return this.RedirectToAction("Details", new { Id = course.Id }); } courseInputModel.AllCategories = this.categoryService.All().To<CategoryViewModel>().To<SelectListItem>().ToList(); return this.View(courseInputModel); }
public async Task Update(CourseInputModel courseInputModel) => await mediator.Send(UpdateCourseCommand.Create( courseInputModel.Id, courseInputModel.Name, courseInputModel.Description, courseInputModel.Price, courseInputModel.Video));
public void ExpectToEditTestWithNoProblems() { var autoMapperConfig = new AutoMapperConfig(); autoMapperConfig.Execute(typeof(CoursesController).Assembly); var courseServiceMock = new Mock<ICoursesService>(); const string ExpectedResult = "Changed"; const int CourseId = 3; courseServiceMock.Setup(c => c.GetAll()).Returns(new List<Course> { new Course() { Id = CourseId, Description = "Test course description", Name = "Test Course", } }.AsQueryable()); courseServiceMock.Setup(c => c.Edit(It.IsAny<Course>())) .Callback<Course>((course) => { Assert.AreEqual(ExpectedResult, course.Description); Assert.AreEqual(ExpectedResult, course.Name); }); var coursesController = new CoursesController(null, courseServiceMock.Object); var inputModel = new CourseInputModel() { Description = ExpectedResult, Name = ExpectedResult }; coursesController.WithCallTo(c => c.Edit(CourseId, inputModel)) .ShouldRedirectTo<Web.Areas.Public.Controllers.CoursesController>(c => c.Details(CourseId)); }
public async Task Register(CourseInputModel courseInputModel) => await mediator.Send(RegisterCourseCommand.Create( courseInputModel.Name, courseInputModel.Description, courseInputModel.Price, courseInputModel.Video));
public ActionResult Edit(int id, CourseInputModel model) { if (!this.ModelState.IsValid) { return this.View(model); } var modelFromDb = this.courseService.GetAll().FirstOrDefault(c => c.Id == id); if (modelFromDb == null) { return this.RedirectToAction("NotFound"); } this.Mapper.Map(model, modelFromDb); this.courseService.Edit(modelFromDb); return this.RedirectToAction("Details", "Courses", new { area = "Public", id = id }); }