public static Mantencion MantencionCompBDaAPP(MANTENCION_COMP aer) { int id = Decimal.ToInt32(aer.ID_MANTENCION); string descripcion = aer.DESCRIPCION; DateTime date = aer.FECHA_MANTENCION; return(new Mantencion(id, descripcion, date)); }
public int ModificarMantencionCompEnBD(int id) { Entities db = new Entities(); MANTENCION_COMP mant = db.MANTENCION_COMP.Where(x => x.ID_MANTENCION == this.IdMantencion).First(); mant.DESCRIPCION = this.Descripcion; mant.COMPONENTE_AERONAVE_ID = mant.COMPONENTE_AERONAVE_ID; mant.FECHA_MANTENCION = this.FechaMMantencion; return(db.SaveChanges()); }
public int GuardarMantencionCompEnBD(int id) { Entities db = new Entities(); MANTENCION_COMP mant = new MANTENCION_COMP(); mant.DESCRIPCION = this.Descripcion; mant.FECHA_MANTENCION = this.FechaMMantencion; COMPONENTE_AERONAVE compp = db.COMPONENTES .Where(x => x.ID_COMPONENTE == id) .First() .COMPONENTE_AERONAVE .First(); mant.COMPONENTE_AERONAVE1 = compp; mant.MATRICULA = compp.AERONAVES_MATRICULA; db.MANTENCION_COMP.Add(mant); try { // Your code... // Could also be before try if you know the exception occurs in SaveChanges return(db.SaveChanges()); } catch (DbEntityValidationException e) { foreach (var eve in e.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; } }