示例#1
0
        public async Task <CourseOverview> Create(CourseOverview overview, Guid authorId)
        {
            var course = new Models.Course(Guid.NewGuid(), overview.Title, overview.PreviewImageUrl, overview.Description, overview.Length, overview.UserLevel, authorId);

            await _context.Courses.AddAsync(course);

            await _context.SaveChangesAsync();


            return(course.ToModel());
        }
示例#2
0
        public async Task CreatesNewCourseSavesToDb()
        {
            var mockRepo = new Mock <ICreateCourseRepo>();
            var request  = new CreateCourseRequest("This is a course", "https://www.google.com", "Most awesome course ever", UserLevel.Beginner);
            var model    = new CourseOverview(Guid.Empty, "", "", "", 2, UserLevel.Beginner, null);

            mockRepo.Setup(p => p.Create(It.IsAny <CourseOverview>())).ReturnsAsync(model);


            var controller = new CreateCourseController(mockRepo.Object);

            controller.ObjectValidator = validator().Object;
            var result = await controller.AddCourse(request);

            mockRepo.Verify(m => m.Create(It.IsAny <CourseOverview>()), Times.Once);
        }
示例#3
0
        public async Task <IActionResult> AddCourse([FromBody] CreateCourseRequest request)
        {
            if (!TryValidateModel(request, nameof(request)))
            {
                return(BadRequest("Invalid Form data"));
            }

            try
            {
                var id    = Guid.Parse(HttpContext.User.Identity.GetSubjectId());
                var model = new CourseOverview(Guid.NewGuid(), request.Title, request.PreviewImageUrl, request.Description, 0, request.UserLevel);

                var data = await _repo.Create(model, id);

                return(Ok(data));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
示例#4
0
 public Task <CourseOverview> Create(CourseOverview overview, Guid authorId)
 {
     throw new NotImplementedException();
 }
示例#5
0
 public async Task <CourseOverview> Create(CourseOverview overview)
 {
     Courses.Add(new Course(overview, new List <Lesson>(), new List <Review>()));
     return(overview);
 }