/// <summary>
        ///     Método Responsavel por Popular as DropDownList com os valores cadastrados na base de dados
        /// </summary>
        /// <param name="model">Teacher Atual</param>
        private void CarregarDropDowns(Student model)
        {
            if (model.Id > 0)
            {
                ViewBag.EstadoCivil = BuildListItemfromEnum<MaritalStatusEnum>(model.Person.MaritalState.ToString());
                ViewBag.Sexo = BuildListItemfromEnum<SexEnum>(model.Person.Sex.ToString());

                var cidades =
                    _servicoCity.SelectWithFilter(a => a.State.Code.Equals(model.Person.Address.State)).ToList();
                ViewBag.Cidades = BuildListSelectListItemWith(cidades, "Name", "Id",
                    model.Person.Address.CityId.ToString());

                var estados = _servicoState.GetAll().ToList();
                ViewBag.Estados = BuildListSelectListItemWith(estados, "Name", "Code", model.Person.Address.State);

                ViewBag.Escolaridades = BuildListItemfromEnum<EducationEnum>(model.Education.ToString());
            }
            else
            {
                ViewBag.EstadoCivil = BuildListItemfromEnum<MaritalStatusEnum>(string.Empty);
                ViewBag.Sexo = BuildListItemfromEnum<SexEnum>(string.Empty);
                ViewBag.Cidades = BuildListSelectListItemWith(new List<City>(), "Description", "Id");
                ViewBag.Estados = BuildListSelectListItemWith(_servicoState.GetAll().ToList(), "Name", "Code");
                ViewBag.Escolaridades = BuildListItemfromEnum<EducationEnum>(model.Education.ToString());
            }
        }
        public ActionResult Manter(int? id)
        {
            var model = new Student();

            if (id.HasValue)
            {
                model = _servicoStudent.GetById(id.Value);
            }

            CarregarDropDowns(model);

            return View(Constants.MANTER, model);
        }
        public JsonResult ListarPaginado(string Nome)
        {
            var paginaAtual = Convert.ToInt32(Request.Params[Constants.START_PAGE]);

            var discente = new Student {Person = new Person {Name = Nome}};

            var discentes = _servicoStudent.SelectWithPagination(discente, paginaAtual);

            var totalRegistros = _servicoStudent.Total(discente);

            discentes.ForEach(a => a.Classes = null);
            return BuildJsonObject(discentes, totalRegistros);
        }
        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 static Func<Student, bool> StudentFilterCondition(Student student)
 {
     return a =>
         string.IsNullOrEmpty(student.Person.Name) ||
         a.Person.Name.ToLower().Contains(student.Person.Name.ToLower());
 }