Example #1
0
        public JsonResult Salvar(Student student)
        {
            var login    = GetFormatedUserLoginAndPassword(student.Person);
            var mensagem = student.Id == 0
                ? Messages.SUCCESSFULLY_INSERTED_RECORD + login
                : Messages.SUCCESSFULLY_UPDATED_RECORD + login;

            try
            {
                var usuario = _servicoUser.SelectWithFilter(a => a.Person.Id == student.Person.Id).FirstOrDefault() ??
                              new User {
                    Person = new Person()
                };
                BuildLoggedUser(student.Person, usuario, (int)AccessProfileEnum.Discente);

                _servicoPerson.ValidadePerson(student.Person);

                if (_servicoStudent.IsEducationFieldFilled(student))
                {
                    student.RegistrationNumber = _servicoStudent.BuildRegistrationNumber(student);
                    _servicoStudent.SaveAndReturn(student);
                    usuario.Person = _servicoPerson.GetById(student.Person.Id);
                    _servicoUser.SaveAndReturn(usuario);
                }
            }
            catch (Exception ex)
            {
                mensagem = GetErrorMessageFromExceptionType(ex);
            }

            return(Json(new { mensagem, studentID = student.Id }));
        }
 public IActionResult Get(int id)
 {
     try
     {
         var _result =
             _personBusiness.GetById(id).CreateVO <Person, PersonOutVO>() ??
             throw new KeyNotFoundException($"Person {id} not found")
         ;
         return(Ok(_result));
     }
     catch (Exception ex)
     {
         return(this.ReturnActionResult(ex));
     }
 }
Example #3
0
        public JsonResult Salvar(Teacher teacher)
        {
            var retorno = 1;

            var login    = GetFormatedUserLoginAndPassword(teacher.Person);
            var mensagem = teacher.Id == 0
                ? Messages.SUCCESSFULLY_INSERTED_RECORD + login
                : Messages.SUCCESSFULLY_UPDATED_RECORD + login;

            try
            {
                var disciplinas = TempData[DISCIPLINA] as List <Courses>;
                foreach (var item in disciplinas)
                {
                    teacher.Courses.Add(_servicoCourse.GetById(item.Id));
                }

                var usuario = _servicoUser.SelectWithFilter(a => a.Person.Id == teacher.Person.Id).FirstOrDefault() ??
                              new User {
                    Person = new Person()
                };
                BuildLoggedUser(teacher.Person, usuario, (int)AccessProfileEnum.Docente);

                _servicoPerson.ValidadePerson(teacher.Person);

                if (_servicoTeacher.IsRequiredFieldsFilled(teacher))
                {
                    _servicoTeacher.SaveAndReturn(teacher);
                    usuario.Person = _servicoPerson.GetById(teacher.Person.Id);
                    _servicoUser.SaveAndReturn(usuario);
                }
            }
            catch (Exception ex)
            {
                mensagem = GetErrorMessageFromExceptionType(ex);
            }

            return(Json(new { retorno, msg = mensagem, docenteID = teacher.Id }));
        }
 public IActionResult Get(int id)
 {
     return(Ok(_personBusiness.GetById(id)));
 }
 public IActionResult Get(int id) => Ok(_personBusiness.GetById(id));