示例#1
0
 public ActionResult Entry(ExamCreateVm entity)
 {
     if (ModelState.IsValid)
     {
         var exam  = Mapper.Map <Exam>(entity);
         var exams = _examManager.GetAllExams();
         if (exams.FirstOrDefault(x => x.Code == exam.Code) != null)
         {
             ViewBag.Message = "Exist";
             entity.ExamTypeSelectListItems     = GetAllExamTypesSLI();
             entity.OrganizationSelectListItems = GetAllOrganizationSlI();
             return(View(entity));
         }
         else
         {
             bool isAdded = _examManager.Add(exam);
             if (isAdded)
             {
                 ModelState.Clear();
                 ViewBag.Message = "Saved";
                 var examSerial = _examManager.ExamCounter();
                 var model      = new ExamCreateVm()
                 {
                     ExamTypeSelectListItems     = GetAllExamTypesSLI(),
                     OrganizationSelectListItems = GetAllOrganizationSlI(),
                     Serial = ++examSerial
                 };
                 return(View(model));
             }
         }
     }
     ModelState.AddModelError("", "An Unknown Error Occured!");
     entity.ExamTypeSelectListItems     = GetAllExamTypesSLI();
     entity.OrganizationSelectListItems = GetAllOrganizationSlI();
     return(View(entity));
 }