Exemplo n.º 1
0
        public async Task CreateAsync(
            string title,
            string content,
            string authorId)
        {
            var article = new Article
            {
                Title       = title,
                Content     = content,
                PublishDate = DateTime.UtcNow,
                AuthorId    = authorId
            };

            db.Add(article);

            await db.SaveChangesAsync();
        }
        public async Task Create(
            string name,
            string description,
            DateTime startDate,
            DateTime endDate,
            string trainerId)
        {
            var course = new Course
            {
                Name        = name,
                Description = description,
                StartDate   = startDate,
                EndDate     = endDate,
                TrainerId   = trainerId
            };

            db.Add(course);

            await db.SaveChangesAsync();
        }
Exemplo n.º 3
0
        public async Task <bool> SignUpStudentAsync(int courseId, string studentId)
        {
            var courseInfo = await GetCourseInfo(courseId, studentId);

            if (courseInfo is null ||
                courseInfo.StartDate < DateTime.UtcNow ||
                courseInfo.UserIsEnrolledInCourse)
            {
                return(false);
            }

            var studentInCourse = new StudentCourse
            {
                CourseId  = courseId,
                StudentId = studentId
            };

            db.Add(studentInCourse);

            await db.SaveChangesAsync();

            return(true);
        }