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 }));
        }