예제 #1
0
        public async Task <bool> AddCourseAsync(CourseForCreation courseForCreation)
        {
            var courseToAdd = _mapper.Map <Course>(courseForCreation);
            await _courseRepository.AddCourseAsync(courseToAdd);

            return(await _courseRepository.SaveChanges());
        }
예제 #2
0
        public async Task <int> AddCourseAsync(CourseForAddDTO courseForAddDTO)
        {
            var course = _mapper.Map <Course>(courseForAddDTO);
            await _repository.AddCourseAsync(course);

            return(course.Id);
        }
예제 #3
0
        public void AddCourse()
        {
            var t = Task.Run(async() =>
            {
                await CourseRepository.AddCourseAsync(Course);
                Course = new Course();
                refreshService.CallRefresh();
            });

            t.Wait();
        }
예제 #4
0
        // POST api/values
        public async Task <IHttpActionResult> Post(CourseViewModel viewModel)
        {
            var author = await _authorRepository.GetAuthorByIdAsync(viewModel.AuthorId);

            if (author == null)
            {
                return(BadRequest());
            }

            Course newCourse = new Course(viewModel.Title, viewModel.Length, author.Id);
            await _courseRepository.AddCourseAsync(newCourse);

            return(Created($"{Request.RequestUri}/{newCourse.Id}", newCourse));
        }
예제 #5
0
        public async Task AddCourse([Remainder] string arg)
        {
            string[] arguments = arg.Split(' ');

            if (arguments.Length < 4)
            {
                await ReplyAsync("Invalid argument count (at least 4)! Usage: " +
                                 "``$create course [Language] [LevelOfExperienceRequired] [MaxStudents] [Description]``");

                return;
            }


            ProgrammingLanguages language;
            CompetenceLevels     level;
            int maxStudents;

            try
            {
                language    = (ProgrammingLanguages)Enum.Parse(typeof(ProgrammingLanguages), arguments[0], true);
                level       = (CompetenceLevels)Enum.Parse(typeof(CompetenceLevels), arguments[1], true);
                maxStudents = Int32.Parse(arguments[2]);
            }
            catch
            {
                await ReplyAsync("Invalid language or level of experience! Usage: " +
                                 "``$create course [Language] [LevelOfExperienceRequired] [MaxStudents] [Description]``");

                return;
            }

            string description = string.Join(' ', arguments.Skip(3));
            Course course      = new Course()
            {
                MaximumEnrolled     = maxStudents,
                CompetenceLevels    = level,
                ProgrammingLanguage = language,
                Description         = description,
            };

            try
            {
                await _courseRepository.AddCourseAsync(course);
                await ReplyAsync($"You have successfully added the course with ID {course.Id}");
            }
            catch (Exception ex)
            {
                await ReplyAsync($"There was an error processing your request: {ex.Message}.");
            }
        }