Example #1
0
        public static object getAll(string nome = "", string email = "")
        {
            try
            {
                EasyDevContext context = new EasyDevContext();

                var objs = context.Candidatos.AsEnumerable();

                if (!string.IsNullOrEmpty(nome))
                {
                    objs = objs.Where(x => !string.IsNullOrEmpty(x.nomeCompleto) && x.nomeCompleto.IndexOf(nome, StringComparison.OrdinalIgnoreCase) >= 0);
                }

                if (!string.IsNullOrEmpty(email))
                {
                    objs = objs.Where(x => !string.IsNullOrEmpty(x.email) && x.email.IndexOf(email, StringComparison.OrdinalIgnoreCase) >= 0);
                }

                return(objs.Select(x => new
                {
                    id = x.id,
                    nomeCompleto = x.nomeCompleto,
                    email = x.email
                }));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #2
0
        public static Candidato getById(int id)
        {
            try
            {
                EasyDevContext context = new EasyDevContext();

                return(context.Candidatos.Find(id));
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #3
0
        public Candidato save(int id = 0)
        {
            try
            {
                EasyDevContext context = new EasyDevContext();

                if (this.id == 0 && id == 0)
                {
                    this.dtHoraCadastro = DateTime.Now;

                    var conhecimentos = new List <CandidatoConhecimento>(this.conhecimentos);
                    this.conhecimentos = null;

                    context.Candidatos.Add(this);

                    context.SaveChanges();

                    CandidatoConhecimento.save(this.id, conhecimentos);
                }
                else
                {
                    if (this.id != id)
                    {
                        throw new HttpException(404, "id do registro difere do id passado como parâmetro");
                    }

                    Candidato oldObj = context.Candidatos.Find(this.id);
                    if (oldObj == null)
                    {
                        throw new HttpException(404, "Registro não localizado.");
                    }
                    else
                    {
                        context.Entry(oldObj).CurrentValues.SetValues(this);
                    }

                    foreach (var candidatoConhecimento in this.conhecimentos)
                    {
                        candidatoConhecimento.save(candidatoConhecimento.id);
                    }

                    context.SaveChanges();
                }

                return(this);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #4
0
        public static object getAll(string descricao = "")
        {
            try
            {
                EasyDevContext context = new EasyDevContext();

                var objs = context.Conhecimentos.AsEnumerable();

                if (!string.IsNullOrEmpty(descricao))
                {
                    objs = objs.Where(x => !string.IsNullOrEmpty(x.descricao) && x.descricao.IndexOf(descricao, StringComparison.OrdinalIgnoreCase) >= 0);
                }

                return(objs);
            }
            catch (Exception)
            {
                throw;
            }
        }
Example #5
0
        public static void delete(int id)
        {
            try
            {
                EasyDevContext context = new EasyDevContext();

                var obj = context.Candidatos.Find(id);

                if (obj == null)
                {
                    throw new HttpException(400, "Registro não localizado.");
                }

                context.Candidatos.Remove(obj);
                context.SaveChanges();
            }
            catch (Exception)
            {
                throw;
            }
        }