public bool Remove(int ID) { try { using (SchoolEntities db = new SchoolEntities()) { int id = ID; var sql = @"DELETE FROM [Course] WHERE CourseID = {0}"; db.Database.ExecuteSqlCommand(sql, id); } return(true); } catch (Exception ex) { throw new Exception("ERROR EN ACCESO A DATOS," + ex.Message); } }
public bool Add(CourseData curso) { try { using (SchoolEntities db = new SchoolEntities()) { Course nuevo = new Course(); nuevo.CourseID = curso.CourseID; nuevo.Title = curso.Title; nuevo.Credits = curso.Credits; nuevo.DepartmentID = curso.DepartmentID; db.Courses.Add(nuevo); db.SaveChanges(); return(true); } } catch { return(false); } }
public bool Add(PersonaData persona) { try { using (SchoolEntities db = new SchoolEntities()) { Person nuevo = new Person(); nuevo.PersonID = persona.id; nuevo.FirstName = persona.FirstName; nuevo.LastName = persona.LastName; nuevo.HireDate = DateTime.Today; nuevo.EnrollmentDate = DateTime.Today; db.People.Add(nuevo); db.SaveChanges(); return(true); } } catch { return(false); } }
public List <PersonaData> GetAll() { List <PersonaData> datos = new List <PersonaData>(); try { using (SchoolEntities db = new SchoolEntities()) { var consulta = from personas in db.People select personas; foreach (Person p in consulta) { PersonaData pData = new PersonaData() { id = p.PersonID, LastName = p.LastName, FirstName = p.FirstName, }; if (p.HireDate.HasValue) { pData.HireDate = p.HireDate.Value; } if (p.EnrollmentDate.HasValue) { pData.EnrollmentDate = p.EnrollmentDate.Value; } datos.Add(pData); } } } catch (Exception ex) { throw new Exception("ERROR EN ACCESO A DATOS," + ex.Message); } return(datos); }