public static Func<Class, bool> ClassFilterCondition(Class entity)
 {
     return
         a =>
             string.IsNullOrEmpty(entity.Description) ||
             a.Description.ToLower().Contains(entity.Description.ToLower())
             && entity.ClassTime == 0 || a.ClassTime == entity.ClassTime;
 }
        public JsonResult ListarPaginado(string nome, int? turno)
        {
            var turma = new Class {Description = nome, ClassTime = turno.HasValue ? turno.Value : 0};

            var paginaAtual = Convert.ToInt32(Request.Params[Constants.START_PAGE]);

            var retorno = _servicoClass.SelectWithPagination(turma, paginaAtual);

            foreach (var item in retorno)
            {
                item.Teacher = null;
                item.Students = null;
            }

            return BuildJsonObject(retorno, retorno.Count);
        }
        private void BuildDropDownLists(Class model)
        {
            ViewBag.Turno = BuildListItemfromEnum<ClassesTimeEnum>(model.ClassTime.ToString());

            var docentes = _servicoTeacher.GetAll().ToList();
            ViewBag.Docentes = BuildListSelectListItemWith(docentes, "Person.Name", "Id");

            var discentesSelecionados = model.Students.ToList();

            var todosDiscentesCadastrados = _servicoStudent.GetAll().ToList();

            discentesSelecionados
                .ForEach(
                    discente =>
                        todosDiscentesCadastrados.RemoveAll(discenteCadastrado => discente.Id == discenteCadastrado.Id));

            ViewBag.DiscentesNaoSelecionados = BuildListSelectListItemWith(todosDiscentesCadastrados, "Person.Name",
                "Id");

            ViewBag.DiscentesSelecionados = BuildListSelectListItemWith(discentesSelecionados, "Person.Name", "Id");
        }
        public JsonResult Salvar(Class model)
        {
            var jsonResult = new JsonResult();
            try
            {
                GetSelectedDiscents(model);
                model.Teacher = _servicoTeacher.GetById(model.Teacher.Id);

                _servicoClass.ValidateTurmaBusinessRules(model);
                _servicoClass.SaveAndReturn(model);
            }
            catch (Exception e)
            {
                jsonResult = e.GetType() == typeof (DuplicatedEntityException)
                    ? BuildJson(0, Messages.REGISTER_ALREADY_IN_PLACE)
                    : BuildJson(0, Messages.CLASS_STUDENT_OVERFLOW);
            }

            return jsonResult;
        }
 private void GetSelectedDiscents(Class model)
 {
     model.SelectedStudentsId.Split(',')
         .ForEach(idDiscente => model.Students.Add(_servicoStudent.GetById(int.Parse(idDiscente))));
 }