コード例 #1
0
        public void Put(Coperativa obj)
        {
            using (var ct = new Contexto())
            using (var trans = ct.Database.BeginTransaction())
            {
                try
                {
                    new ControleMensalRepository().Put(obj.Controles.First(), ct);

                    if (obj.Telefones.Any())
                        new TelefoneRepository().Put(obj.Telefones, obj.Id, ct);

                    obj.Controles = null;
                    obj.Telefones = null;

                    ct.DbCoperativa.AddOrUpdate(obj);
                    var a = ct.SaveChanges();
                    trans.Commit();
                }
                catch (Exception ex)
                {
                    trans.Rollback();
                    throw ex;
                }
            }
        }
コード例 #2
0
        public void Put(ControleMensal obj , Contexto ctx)
        {
            try
            {
                ctx.DbControleMensal.AddOrUpdate(obj);

                if (!obj.Recebido)
                    return;

                var controle = new ControleMensal
                {
                    Id = 0,
                    CoperativaId = obj.CoperativaId,
                    DataContrato = obj.DataContrato,
                    DataVencimento = obj.DataVencimento.AddMonths(1),
                    Recebido = false,
                    Valor = obj.Valor
                };
                ctx.DbControleMensal.AddOrUpdate(controle);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #3
0
        public int Post(Coperativa obj)
        {
            using (var ct = new Contexto())
            {
                ct.DbCoperativa.Add(obj);

                return ct.SaveChanges();
            }
        }
コード例 #4
0
        public Coperativa Get(int id)
        {
            var ct = new Contexto();
            var cop = ct.DbCoperativa.FirstOrDefault(x => x.Id == id);

            if (cop != null)
            {
                var ctrl = cop.Controles.OrderBy(x => x.DataVencimento).Last();
                cop.Controles.Clear();
                cop.Controles.Add(ctrl);
            }
            return cop;
        }
コード例 #5
0
        public void Put(IList<Telefone> telefones , int copId , Contexto ctx)
        {
            try
            {
                var tels = ctx.DbTelefone.Where(x => x.CoperativaId == copId).ToList();

                foreach (var telefone in tels.Where(telefone => telefones.All(x => x.Id != telefone.Id)))
                    ctx.DbTelefone.Remove(telefone);

                foreach (var telefone in telefones)
                    ctx.DbTelefone.AddOrUpdate(telefone);
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }
コード例 #6
0
 public List<CoperativaGrid> GetGrid(bool? ativo = null)
 {
     using (var ct = new Contexto())
     {
         var list = ct.DbCoperativa.ToList()
             .Where(x => x.Ativo == ativo || ativo == null)
             .Select(x => new CoperativaGrid
             {
                 Id = x.Id,
                 Descricao = x.Descricao,
                 QtdeTelefones = x.QtdeTelefones,
                 DataVencimento = x.Controles.OrderBy(d => d.DataVencimento).Last().DataVencimento,
                 Recebido = x.Controles.OrderBy(d => d.DataVencimento).Last().Recebido,
             }).ToList();
         return list;
     }
 }
コード例 #7
0
        public void Delete(int id)
        {
            using (var ct = new Contexto())
            {
                var coper = ct.DbCoperativa.FirstOrDefault(x => x.Id == id);

                if (coper == null)
                    return;

                coper.Ativo = false;
                coper.Excluido = true;

                ct.Entry(coper).State = EntityState.Modified;

                ct.SaveChanges();
            }
        }