public void Create_ValidInputModel_ReturnsCreatedLesson() { var lesson = new Lesson() { OrderId = 1, StartTime = new DateTime(2018, 12, 11, 12, 00, 00), EndTime = new DateTime(2018, 12, 11, 13, 0, 0), ThemeColor = "green", IsFullDay = false, Subject = "first lesson", Description = "asdfg" }; this.repository.Setup(r => r.AddAsync(lesson)).Returns(Task.FromResult(lesson)); var model = new CreateLessonInputModel() { OrderId = 1, StartTime = new DateTime(2018, 12, 11, 12, 00, 00), EndTime = new DateTime(2018, 12, 11, 13, 0, 0), ThemeColor = "green", IsFullDay = false, Subject = "first lesson", Description = "asdfg" }; var result = this.lessonService.Create(model).GetAwaiter().GetResult(); Assert.That(result, Is.TypeOf <Lesson>()); Assert.That(result.OrderId, Is.EqualTo(1)); }
public async Task <IActionResult> Create() { var viewModel = new CreateLessonInputModel { CategoriesItems = await this.categoriesService.AllAsync <CategoriesItemsViewModel>(), }; return(this.View(viewModel)); }
public async Task <Lesson> Create(CreateLessonInputModel model) { var lesson = Mapper.Map <Lesson>(model); await this.lessonRepository.AddAsync(lesson); await this.lessonRepository.SaveChangesAsync(); return(lesson); }
public ActionResult Create(CreateLessonInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var lesson = this.lessonService.Create(model).GetAwaiter().GetResult(); return(this.RedirectToAction("Details", "Lessons", new { lessonId = lesson.Id })); }
public async Task <IActionResult> Create(CreateLessonInputModel model) { if (!this.ModelState.IsValid) { model.CategoriesItems = await this.categoriesService.AllAsync <CategoriesItemsViewModel>(); return(this.View(model)); } var userId = this.User.FindFirst(ClaimTypes.NameIdentifier).Value; await this.lessonsService.CreateAsync(model.Title, model.Description, model.VideoUrl, userId, model.CategoryId); return(this.RedirectToAction("MyResources", "Users")); }