Example #1
0
        public async Task <ActionResult <ClassroomViewModel> > GetClassroom(int id)
        {
            var classRoom = _classroomService.GetById(id);

            if (classRoom == null)
            {
                return(NotFound("Không tìm thấy id = " + id));
            }

            return(await Task.FromResult(classRoom));
        }
Example #2
0
        public ActionMessage Create(int classroomId, string subjectTitle, DateTime examStart, DateTime examEnd, string userId)
        {
            ActionMessage      response = new ActionMessage();
            ClassroomViewModel model    = classroomService.GetById(classroomId);

            if (model.Exams.Count > 0)
            {
                bool isValid = model.Exams.Where(x => examStart > x.ExamEnd || examEnd < x.ExamDate).Any();
                if (!isValid)
                {
                    response.Error = "This time is already scheduled. Please check the classroom details";
                    return(response);
                }
            }

            if (examStart <= DateTime.Now.AddDays(14))
            {
                response.Error = "Invalid date! Exam must be scheduled 14 days in advance";
            }
            else if (examStart > examEnd)
            {
                response.Error = "Invalid date! Your end time is before your start time !!!";
            }
            else
            {
                Exam exam = new Exam()
                {
                    ClassroomId = classroomId,
                    SubjectId   = subjectService.GetByTitle(subjectTitle).Id,
                    ExamDate    = examStart,
                    ExamEnd     = examEnd,
                    CreatedBy   = userId,
                };

                examRepositoty.Add(exam);
                response.Message = "Exam successfully created";
            }

            return(response);
        }