Пример #1
0
 /// <summary>
 /// Metodo encargado de actualizar la entidad referenciada dentro de la base de datos
 /// </summary>
 /// <param name="entity">Corresponde a la entidad que se desea actualizar</param>
 /// <returns></returns>
 public static T Update(T entity)
 {
     try
     {
         using (var bd = new Judicial())
         {
             bd.Entry(entity).State = System.Data.Entity.EntityState.Modified;
             bd.SaveChanges();
             return(entity);
         }
     }
     catch (System.Data.Entity.Validation.DbEntityValidationException ex)
     {
         foreach (var eve in ex.EntityValidationErrors)
         {
             Console.WriteLine("Entity of type \"{0}\" in state \"{1}\" has the following validation errors:",
                               eve.Entry.Entity.GetType().Name, eve.Entry.State);
             foreach (var ve in eve.ValidationErrors)
             {
                 Console.WriteLine("- Property: \"{0}\", Error: \"{1}\"",
                                   ve.PropertyName, ve.ErrorMessage);
             }
         }
         throw ex;
     }
     catch (Exception ex)
     {
         throw ex;
     }
 }
Пример #2
0
        public static Caso GuardarCaso(Caso pCaso)
        {
            try
            {
                using (var db = new Judicial())
                {
                    foreach (var vDetalle in pCaso.DetalleCaso)
                    {
                        db.Entry(vDetalle).State = vDetalle.DetalleCasoID > 0 ? EntityState.Modified : EntityState.Added;
                    }

                    db.Entry(pCaso).State = pCaso.CasoID > 0 ? EntityState.Modified : EntityState.Added;
                    db.SaveChanges();

                    return(pCaso);
                }
            }
            catch (Exception ex) { throw ex; }
        }