public async Task <ActionResult> AddAsync(AddExamDTO model)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    ViewBag.Notification = new SuccessResult(false, "All fields are required!");
                    return(View(model));
                }
                var result = await _examsRepository.Add(model);

                if (result.Item1)
                {
                    TempData["SuccessResultF"] = result.Item1;
                    TempData["SuccessResultM"] = result.Item2;

                    return(RedirectToAction("Index", "Students"));
                }
                else
                {
                    ViewBag.Notification = new SuccessResult((bool)result.Item1, (string)result.Item2);


                    var professors = _professorsRepository.GetAll();
                    var students   = _studentsRepository.GetAll();
                    var subjects   = _subjectsRepository.GetAll();

                    await Task.WhenAll(professors, students, subjects);

                    ViewBag.ProfessorId = new SelectList(professors.Result.Item2, "Id", "ProfessorName");
                    ViewBag.StudentId   = new SelectList(students.Result.Item2, "Id", "Name");
                    ViewBag.SubjectId   = new SelectList(subjects.Result.Item2, "Id", "SubjectName");

                    return(View(model));
                }
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
Esempio n. 2
0
        public async Task <IActionResult> AddExamAsync(AddExamDto addExamDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var examModel = _mapper.Map <Exam>(addExamDto);
                    await _context.Add(examModel);

                    var readExamDto = _mapper.Map <ReadExamDto>(examModel);

                    return(Ok("Provimi u regjistrua me sukses"));
                }
                catch (Exception ex)
                {
                    return(BadRequest(new DataError("Insetimi deshtoi " + ex.Message)));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }
Esempio n. 3
0
        public async Task <IActionResult> AddExamAsync(AddExamDTO addExamDto)
        {
            if (ModelState.IsValid)
            {
                try
                {
                    var examModel = _mapper.Map <Exam>(addExamDto);
                    await _context.Add(examModel);

                    var readExamDto = _mapper.Map <ReadExamDTO>(examModel);
                    _log.AddLog(Request, _httpContextAccessor, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "Eshte regjistruar nje provim");
                    return(Ok(new DataMessage("Provimi u regjistrua me sukses")));
                }
                catch (Exception ex)
                {
                    _log.AddLog(Request, _httpContextAccessor, this.ControllerContext.RouteData.Values["controller"].ToString(), this.ControllerContext.RouteData.Values["action"].ToString(), "Deshtim ne regjistrimin e nje provimi.");
                    return(BadRequest(new DataMessage("Insetimi deshtoi " + ex.Message)));
                }
            }
            else
            {
                return(BadRequest(ModelState));
            }
        }