public IActionResult Create([FromBody] Exam exam)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }

            _service.Create(exam);
            return(Ok(exam));
        }
예제 #2
0
        public IActionResult Post([FromForm] ExamViewModel exam)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            var status = _examService.Create(exam);

            return(Ok(status));
        }
예제 #3
0
        public IActionResult Create(int classroomId, string subjectTitle, DateTime examStart, DateTime examEnd, string userId)
        {
            if (examStart == default || examEnd == default)
            {
                return(RedirectToAction("ActionMessage", "Dashboard", new { Error = "All input fields are required" }));
            }
            ActionMessage response = examService.Create(classroomId, subjectTitle, examStart, examEnd, userId);

            return(RedirectToAction("ActionMessage", "Dashboard", response));
        }
예제 #4
0
 public IActionResult Create([FromBody] Exam exam)
 {
     try
     {
         _examService.Create(exam);
         return(Ok());
     }
     catch (Exception ex)
     {
         return(BadRequest(ex.Message));
     }
 }
예제 #5
0
        public async Task <IActionResult> CreateExam([FromBody] ExamCreatingDto examCreatingDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            try
            {
                var exam = await examService.Create(examCreatingDto);

                return(CreatedAtRoute("FindExamById", new { id = exam.Id }, exam));
            }
            catch (CourseNotFoundException courseNotFoundException)
            {
                return(NotFound(courseNotFoundException.Message));
            }
        }
예제 #6
0
        public IActionResult Create([FromBody] ExamCreateDto examDto)
        {
            // map dto to entity and set id
            Exam c = _mapper.Map <Exam>(examDto);

            try
            {
                c.ExamCriterea = null;
                // save
                c = _examService.Create(c);
                return(Ok(_mapper.Map <ExamDto>(c)));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(ex.Message));
            }
        }
        public async Task <IActionResult> Create(ExamModel model)
        {
            var token       = CookieEncoder.DecodeToken(Request.Cookies["access_token_cookie"]);
            var lstCategory = await _categoryService.GetAll();

            ViewData["lstCategory"] = lstCategory.data;
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            var newExam = await _examService.Create(model, Int32.Parse(User.FindFirst("UserID").Value), token);

            if (newExam != null && newExam.data != null)
            {
                ViewData["msg"] = "Successfully";
                return(View());
            }
            ViewData["msg"] = "Create failed";
            return(View());
        }
예제 #8
0
        public IActionResult SaveEntity(ExamViewModel examVm)
        {
            if (!ModelState.IsValid)
            {
                IEnumerable <ModelError> allErrors = ModelState.Values.SelectMany(v => v.Errors);
                return(new BadRequestObjectResult(allErrors));
            }

            if (examVm.Id == 0)
            {
                _examService.Create(examVm);
            }
            else
            {
                _examService.Update(examVm);
            }

            _examService.SaveChanges();
            return(new OkObjectResult(examVm));
        }
예제 #9
0
        public async Task SaveAddExam()
        {
            ValidationErrors = null;
            try
            {
                await _examService.Create(NewExam);

                Exams.RowEditOptions.EditRowId = null;
                Exams.RequestRefresh();
                NewExam = null;
            }
            catch (ValidationPropertyException vpe)
            {
                ValidationErrors = vpe.ErrorsList.ToList();
            }
            catch (ValidationException ve)
            {
                ValidationErrors = ve.Errors.ToList();
            }
        }