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;
                }
            }
        }
        public int Post(Coperativa obj)
        {
            using (var ct = new Contexto())
            {
                ct.DbCoperativa.Add(obj);

                return ct.SaveChanges();
            }
        }
 public dynamic Put(Coperativa usua)
 {
     try
     {
         new CoperativaRepository().Put(usua);
         return Json(new {error = ""});
     }
     catch (Exception ex)
     {
         return Json(new {error = ex.Message});
     }
 }
 public dynamic Post(Coperativa usua)
 {
     try
     {
         usua.DataCadastro = DateTime.Now;
         usua.Controles[0].DataContrato = DateTime.Now;
         var user = new CoperativaRepository().Post(usua);
         return Json(new { error = "" });
     }
     catch (Exception ex)
     {
         return Json(new { error = ex.Message });
     }
 }