public GetAsignaturasModel GetAsignaturas() { var model = new GetAsignaturasModel(); using (SchoolDataContext ctx = new SchoolDataContext()) { var asignaturas = (from x in ctx.Asignaturas orderby x.Id, x.MateriaCod select new Model.Asignatura { ID = x.Id, CodigoMateria = x.MateriaCod, Materia = x.Materia.Titulo, AlumnoCedula = x.AlumnoDni, Alumno = x.Alumno.Nombres, ProfesorCedula = x.ProfesorDni, Profesor = x.Profesor.Nombres, NotaTareas = x.Tareas, NotaExamen = x.Examen }).ToList(); model.Asignaturas = asignaturas; model.Alumnos = this.GetAlumnos(); model.Profesores = this.GetProfesores(); model.PromedioGeneral = (from x in asignaturas select x.Promedio).Average(); } return(model); }
static void Main(string[] args) { using (SchoolDataContext db = new SchoolDataContext()) { Console.WriteLine("Enter a department name:"); string dName = Console.ReadLine(); Department department = new Department() { Name = dName }; db.Departments.Add(department); db.SaveChanges(); Console.WriteLine("Enter a student information:"); Student student = new Student { Department = department }; Console.WriteLine("Write name: "); student.Name = Console.ReadLine(); Console.WriteLine("Write address: "); student.Address = Console.ReadLine(); Console.WriteLine("Write phone: "); student.Phone = Console.ReadLine(); db.Students.Add(student); db.SaveChanges(); DisplayStudents(db.Students.ToList()); } Console.WriteLine("Done"); Console.ReadLine(); }
public List <RegisteredStudent> List() { using (SchoolDataContext schoolContext = new SchoolDataContext()) { return(schoolContext.Students.ToList().Select(x => x.toDTO()).ToList()); } }
public static UserListModel Save(UserListModel obj) { using (SchoolDataContext dbcontext = new SchoolDataContext()) { // //dbcontext.User.Add(obj); dbcontext.SaveChanges(); } return(obj); }
public RegisteredStudent Create(CreateStudent newRegistry) { using (SchoolDataContext schoolContext = new SchoolDataContext()) { var newStudent = newRegistry.ToEntity(); schoolContext.Students.Add(newStudent); schoolContext.SaveChanges(); return(newStudent.toDTO()); } }
public RegisteredStudent Delete(DeletedStudent deletedStudent) { using (SchoolDataContext schoolContext = new SchoolDataContext()) { Student studentToDelete = (Student)schoolContext.Students.Where(b => b.Id == deletedStudent.Id).First(); schoolContext.Entry(studentToDelete).State = System.Data.Entity.EntityState.Deleted; schoolContext.SaveChanges(); return(studentToDelete.toDTO()); } }
public GetAsignaturasModel GetAsignaturas(string filtro) { var model = new GetAsignaturasModel(); using (SchoolDataContext ctx = new SchoolDataContext()) { var rows = (from x in ctx.Asignaturas orderby x.Id, x.MateriaCod select new Model.Asignatura { ID = x.Id, CodigoMateria = x.MateriaCod, Materia = x.Materia.Titulo, AlumnoCedula = x.AlumnoDni, Alumno = x.Alumno.Nombres, ProfesorCedula = x.ProfesorDni, Profesor = x.Profesor.Nombres, NotaTareas = x.Tareas, NotaExamen = x.Examen }).ToList(); //if (string.IsNullOrWhiteSpace(filtro) == false) //{ // rows = from x in rows // where filtro.Contains(x.AlumnoCedula) || // filtro.Contains(x.Alumno) || // filtro.Contains(x.Materia) || // filtro.Contains(x.Profesor) // select x; //} if (string.IsNullOrWhiteSpace(filtro) == false && filtro.ToUpper().Equals("APROBADO")) { rows = (from x in rows where x.Aprobo == true select x).ToList(); } if (string.IsNullOrWhiteSpace(filtro) == false && filtro.ToUpper().Equals("REPROBADO")) { rows = (from x in rows where x.Aprobo == false select x).ToList(); } var rowsFiltered = (from x in rows orderby x.ID, x.CodigoMateria select x).ToList(); model.Asignaturas = rowsFiltered; model.Alumnos = this.GetAlumnos(); model.Profesores = this.GetProfesores(); model.PromedioGeneral = (from x in rowsFiltered select x.Promedio).Average(); return(model); } }
public RegisteredStudent Update(UpdateStudent updateRegistry) { using (SchoolDataContext schoolContext = new SchoolDataContext()) { var studentToUpdate = updateRegistry.ToEntity(); schoolContext.Students.Attach(studentToUpdate); //schoolContext.Entry(studentToUpdate).Property(x => x.Name).IsModified = true; schoolContext.Entry(studentToUpdate).State = System.Data.Entity.EntityState.Modified; schoolContext.SaveChanges(); return(studentToUpdate.toDTO()); } }
public GetAsignaturasModel GetAsignaturasPorFiltro(GetAsignaturasPorFiltro filtro) { var model = new GetAsignaturasModel(); using (SchoolDataContext ctx = new SchoolDataContext()) { var rows = from x in ctx.Asignaturas orderby x.Id, x.MateriaCod select new Model.Asignatura { ID = x.Id, CodigoMateria = x.MateriaCod, Materia = x.Materia.Titulo, AlumnoCedula = x.AlumnoDni, Alumno = x.Alumno.Nombres, ProfesorCedula = x.ProfesorDni, Profesor = x.Profesor.Nombres, NotaTareas = x.Tareas, NotaExamen = x.Examen }; if (filtro != null) { if (string.IsNullOrWhiteSpace(filtro.SelectedProfesorCod) == false) { rows = from x in rows where filtro.SelectedProfesorCod.Equals(x.ProfesorCedula) select x; } if (string.IsNullOrWhiteSpace(filtro.SelectedAlumnoCod) == false) { rows = from x in rows where filtro.SelectedAlumnoCod.Equals(x.AlumnoCedula) select x; } } var rowsFiltered = (from x in rows orderby x.ID, x.CodigoMateria select x).ToList(); model.Asignaturas = rowsFiltered; model.Alumnos = this.GetAlumnos(); model.Profesores = this.GetProfesores(); model.PromedioGeneral = (from x in rowsFiltered select x.Promedio).Average(); return(model); } }
public static UserListModel Update(UserListModel obj) { using (SchoolDataContext dbcontext = new SchoolDataContext()) { var updObj = dbcontext.User.FirstOrDefault(n => n.Id == obj.Id); updObj.FirstName = obj.FirstName; updObj.LastName = obj.LastName; updObj.MiddleName = obj.MiddleName; //updObj.DateOfBirth = obj.DateOfBirth; updObj.Email = obj.Email; dbcontext.User.Update(updObj); dbcontext.SaveChanges(); } return(obj); }
/// <summary> /// This method creates the XML document based on the Person table in /// SQLServer2005DB database in All-In-One Code Framework /// </summary> /// <param name="path">The database XML document path</param> private static void CreateDatabaseXml(string path) { // Create the Linq to SQL data context object // For detail about Linq to SQL examples, please see the CSLinqToSQL // project in All-In-One Code Framework SchoolDataContext db = new SchoolDataContext(); // Build the XML document, each element is under the default XML // namespace ns: http://cfx.codeplex.com XDocument doc = new XDocument( // XML declaration new XDeclaration("1.0", "utf-8", "yes"), // The root element new XElement(ns + "Person", // The Employees elements new XElement(ns + "Employees", // Embeded Linq query to build the child XML elements from e in db.Persons where e.PersonCategory == 2 select new XElement(ns + "Employee", // Create the element's attribute new XAttribute("id", e.PersonID), new XElement(ns + "Name", e.FirstName + " " + e.LastName), new XElement(ns + "HireDate", e.HireDate.Value.ToString()) ) ), // The Students elements new XElement(ns + "Students", // Embeded Linq query to build the child XML elements from s in db.Persons where s.PersonCategory == 1 select new XElement(ns + "Student", // Create the element's attribute new XAttribute("id", s.PersonID), new XElement(ns + "Name", s.FirstName + " " + s.LastName), new XElement(ns + "EnrollmentDate", s.EnrollmentDate.Value.ToString()) ) ) ) ); // Save the XML document to the file system doc.Save(path); }
public List <Model.Profesor> GetProfesores() { using (SchoolDataContext ctx = new SchoolDataContext()) { var rows = (from x in ctx.Profesors orderby x.Cedula select new Model.Profesor { Cedula = x.Cedula, Nombres = x.Nombres, Telefono = x.Telefono }).ToList(); return(rows); } }
public List <Model.Materia> GetMaterias() { using (SchoolDataContext ctx = new SchoolDataContext()) { var rows = (from x in ctx.Materias orderby x.Codigo select new Model.Materia { Codigo = x.Codigo, Area = x.Area, Titulo = x.Titulo }).ToList(); return(rows); } }
/// <summary> /// 这个方法基于All-In-One代码框架中的SQLServer2005DB数据库中的Person表 /// 来创建XML文档 /// </summary> /// <param name="path">数据库XML文档路径</param> private static void CreateDatabaseXml(string path) { // 创建Linq to SQL数据上下文对象 // 有关Linq to SQL的详细信息,请参考All-In-One代码框架中的CSLinqToSQL // 工程 SchoolDataContext db = new SchoolDataContext(); // 生成XML文档,每个元素都在默认的XML命名空间ns: http://cfx.codeplex.com下 XDocument doc = new XDocument( // XML 声明 new XDeclaration("1.0", "utf-8", "yes"), // 根元素 new XElement(ns + "Person", // Employees 元素 new XElement(ns + "Employees", // 嵌入Linq查询来生成子XML元素 from e in db.Persons where e.PersonCategory == 2 select new XElement(ns + "Employee", // 创建元素的属性 new XAttribute("id", e.PersonID), new XElement(ns + "Name", e.FirstName + " " + e.LastName), new XElement(ns + "HireDate", e.HireDate.Value.ToString()) ) ), // Students 元素 new XElement(ns + "Students", // 嵌入Linq查询来生成子XML元素 from s in db.Persons where s.PersonCategory == 1 select new XElement(ns + "Student", // 创建元素的属性 new XAttribute("id", s.PersonID), new XElement(ns + "Name", s.FirstName + " " + s.LastName), new XElement(ns + "EnrollmentDate", s.EnrollmentDate.Value.ToString()) ) ) ) ); // 保存XML文档到文件系统 doc.Save(path); }
public void SchoolHasFixtures() { using (var db = new SchoolDataContext()) { Fixture fixture = new Fixture(); fixture.Kickoff = DateTime.Now; db.Fixtures.Add(fixture); School school = new School(); db.Schools.Add(school); school.Fixtures.Add(fixture); db.SaveChanges(); Assert.That(school.Fixtures.Contains <Fixture>(fixture)); } }
public void SchoolHasFixtures() { using (var db = new SchoolDataContext()) { Fixture fixture = new Fixture(); fixture.Kickoff = DateTime.Now; db.Fixtures.Add(fixture); School school = new School(); db.Schools.Add(school); school.Fixtures.Add(fixture); db.SaveChanges(); Assert.That(school.Fixtures.Contains<Fixture>(fixture)); } }
public List <Model.Alumno> GetAlumnos() { using (SchoolDataContext ctx = new SchoolDataContext()) { var rows = (from x in ctx.Alumnos orderby x.Cedula select new Model.Alumno { Cedula = x.Cedula, Nombres = x.Nombres, Telefono = x.Telefono, Direccion = x.Direccion }).ToList(); return(rows); } }
public void ChildHasFixtures() { using (var db = new SchoolDataContext()) { Fixture fixture = new Fixture(); fixture.Kickoff = DateTime.Now; db.Fixtures.Add(fixture); Child child = new Child(); db.Children.Add(child); PlayingStatus playingStatus = PlayingStatus.Create(fixture, child); db.PlayingStatuses.Add(playingStatus); db.SaveChanges(); Assert.That(child.PlayingStatuses.Contains <PlayingStatus>(playingStatus)); } }
public void ChildHasFixtures() { using (var db = new SchoolDataContext()) { Fixture fixture = new Fixture(); fixture.Kickoff = DateTime.Now; db.Fixtures.Add(fixture); Child child = new Child(); db.Children.Add(child); PlayingStatus playingStatus = PlayingStatus.Create(fixture, child); db.PlayingStatuses.Add(playingStatus); db.SaveChanges(); Assert.That(child.PlayingStatuses.Contains<PlayingStatus>(playingStatus)); } }
public static List <UserListModel> Get(LoggedInUserModel userInfo) { var user = new List <UserListModel>(); using (SchoolDataContext dbcontext = new SchoolDataContext()) { user = dbcontext.User.Select(n => new UserListModel { Id = n.Id, FirstName = n.FirstName, MiddleName = n.MiddleName, LastName = n.LastName, Email = n.Email, Mobile = n.Mobile, DateOfBirth = string.Format("{0:dd/MM/yyyy}", n.DateOfBirth) }).ToList(); } return(user); }
public static UserListModel Get(int id) { var user = new UserListModel(); using (SchoolDataContext dbcontext = new SchoolDataContext()) { user = dbcontext.User.Where(n => n.Id == id) .Select(n => new UserListModel { Id = n.Id, FirstName = n.FirstName, MiddleName = n.MiddleName, LastName = n.LastName, Email = n.Email, Mobile = n.Mobile, DateOfBirth = string.Format("{0:dd/MM/yyyy}", n.DateOfBirth) }).FirstOrDefault(); } return(user); }
public Model.Asignatura GetAsignatura(decimal ID) { using (SchoolDataContext ctx = new SchoolDataContext()) { var asignatura = (from x in ctx.Asignaturas where x.Id == ID select new Model.Asignatura { ID = x.Id, CodigoMateria = x.MateriaCod, Materia = x.Materia.Titulo, AlumnoCedula = x.AlumnoDni, Alumno = x.Alumno.Nombres, ProfesorCedula = x.ProfesorDni, Profesor = x.Profesor.Nombres, NotaTareas = x.Tareas, NotaExamen = x.Examen }).FirstOrDefault(); return(asignatura); } }
public bool SaveAsignatura(Model.Asignatura materia) { using (SchoolDataContext ctx = new SchoolDataContext()) { var asignatura = (from x in ctx.Asignaturas where x.Id == materia.ID select x).FirstOrDefault(); if (asignatura is null) { return(false); } else { asignatura.Tareas = materia.NotaTareas; asignatura.Examen = materia.NotaExamen; ctx.SubmitChanges(); return(true); } } }
public List <Model.Asignatura> GetAsignaturasPorProfesor(string profesorDNI) { using (SchoolDataContext ctx = new SchoolDataContext()) { var rows = (from x in ctx.Asignaturas where x.ProfesorDni.Equals(profesorDNI) orderby x.Id, x.MateriaCod select new Model.Asignatura { ID = x.Id, CodigoMateria = x.MateriaCod, Materia = x.Materia.Titulo, AlumnoCedula = x.AlumnoDni, Alumno = x.Alumno.Nombres, ProfesorCedula = x.ProfesorDni, Profesor = x.Profesor.Nombres, NotaTareas = x.Tareas, NotaExamen = x.Examen }).ToList(); return(rows); } }
public StudentDataHandler() { this._ctx = new SchoolDataContext(); }
public HomeController() { Context = new SchoolDataContext(); }
public UserAuthenticationModel Get(int id) { var user = new UserAuthenticationModel(); using (SchoolDataContext dbcontext = new SchoolDataContext()) { user = dbcontext.User .Where(n => n.Id == id) .Select(n => new UserAuthenticationModel { Id = n.Id, Name = n.FirstName + " " + n.LastName, RoleId = n.RoleId, IsAuthenticated = true }).FirstOrDefault(); } if (user != null && user.IsAuthenticated) { return(user); } else { return new UserAuthenticationModel { IsAuthenticated = false } }; } /*public UserAuthenticationModel Get(string userName, string password) * { * var user = new UserAuthenticationModel(); * * user = _userRepository * .Find(n => n.UserName.Equals(userName) && n.Password.Equals(password)) * .Select(n => new UserAuthenticationModel * { * Id = n.Id, * Name = n.FirstName + " " + n.LastName, * RoleId = n.RoleId, * IsAuthenticated = true * }).FirstOrDefault(); * * * if (user != null && user.IsAuthenticated) * return user; * else * return new UserAuthenticationModel * { * IsAuthenticated = false * }; * } * * public static UserAuthenticationModel Get(int id) * { * var user = new UserAuthenticationModel(); * * using (SchoolDataContext dbcontext = new SchoolDataContext()) * { * user = dbcontext.User * .Where(n => n.Id == id) * .Select(n => new UserAuthenticationModel * { * Id = n.Id, * Name = n.FirstName + " " + n.LastName, * RoleId = n.RoleId, * IsAuthenticated = true * }).FirstOrDefault(); * } * * if (user != null && user.IsAuthenticated) * return user; * else * return new UserAuthenticationModel * { * IsAuthenticated = false * }; * }*/ }
public LoginController() { Context = new SchoolDataContext(); }