コード例 #1
0
ファイル: MateriaController.cs プロジェクト: lulzzz/Inafocam
        public IActionResult Crear(int scholarshipProgramUniversityId)
        {
            var universityId = _scholarshipProgramUniversity.GetUniversityIdByScholarshipProgramUniversityId(scholarshipProgramUniversityId);
            var model        = new SubjectMatterModel();

            model.ScholarshipProgramUniversityId = scholarshipProgramUniversityId;
            model.UniversityId = universityId;

            var teachers = _teacher.GetTeachersByUSerUniversityId(universityId);

            ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
            ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
            return(View(model));
        }
コード例 #2
0
        public IActionResult Guardar(SubjectMatterModel model)
        {
            try
            {
                var data = CopyPropierties.Convert <SubjectMatterModel, SubjectMatter>(model);

                _subjectMatter.Save(data);
            }
            catch (Exception e)
            {
                return(View("Index", _subjectMatter.GetAll));
            }

            return(View("Index", _subjectMatter.GetAll));
        }
コード例 #3
0
 public IActionResult Crear(SubjectMatterModel model)
 {
     ViewBag.Status = new SelectList(_status.Status, "StatusId", "StatusName");
     return(View(model));
 }
コード例 #4
0
ファイル: MateriaController.cs プロジェクト: lulzzz/Inafocam
        public IActionResult Guardar(SubjectMatterModel model)
        {
            var universityId          = _scholarshipProgramUniversity.GetUniversityIdByScholarshipProgramUniversityId(model.ScholarshipProgramUniversityId);
            MensajesViewModel mensaje = new MensajesViewModel();
            var data = CopyPropierties.Convert <SubjectMatterModel, SubjectMatter>(model);

            if (CheckIfSubjectMatterCodeExits(data))
            {
                EnviarMensaje.Enviar(TempData, "red", "Este programa ya contiene un registro de una materia con este código");

                //if (model.SubjectMatterId != 0)
                //{
                //    ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                //    return RedirectToAction("Editar", new { id = model.SubjectMatterId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId });
                //}


                ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                return(View("Crear", model));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _subjectMatter.Save(data);
                }
                catch (Exception e)
                {
                    if (model.SubjectMatterId != 0)
                    {
                        ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                        return(RedirectToAction("Editar", new { id = model.SubjectMatterId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
                    }
                    else
                    {
                        ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
                        ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                        return(View("Crear"));
                    }
                }
            }
            else
            {
                var errors = ModelState.Select(x => x.Value.Errors).FirstOrDefault(x => x.Count > 0).First();



                EnviarMensaje.Enviar(TempData, "red", errors.ErrorMessage);

                if (model.SubjectMatterId != 0)
                {
                    ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                    return(RedirectToAction("Editar", new { id = model.SubjectMatterId, scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
                }
                ViewBag.Status   = new SelectList(_status.Status, "StatusId", "StatusName");
                ViewBag.Teachers = new SelectList(TeachersByUniverityIdList(universityId), "TeacherId", "TeacherFullName");
                return(View("Crear"));
            }


            return(RedirectToAction("Index", new { scholarshipProgramUniversityId = model.ScholarshipProgramUniversityId }));
        }