public static bool Login(string username, string password) { using (StudentsDBEntities entities = new StudentsDBEntities()) { return(entities.Securities.Any(security => security.Username.Equals(username, StringComparison.OrdinalIgnoreCase) && security.Password == password)); } }
public IEnumerable <Student> Get() { using (StudentsDBEntities entities = new StudentsDBEntities()) { return(entities.Students.ToList()); } }
public IHttpActionResult Get() { using (StudentsDBEntities ctx = new StudentsDBEntities()) { return(Ok(ctx.Students.ToList())); } }
public object getStudentData() { using (StudentsDBEntities entities = new StudentsDBEntities()) { return(entities.Students.ToList()); } }
public HttpResponseMessage PUT([FromBody] int id, Student student) { try { using (StudentsDBEntities entities = new StudentsDBEntities()) { var entity = entities.Students.FirstOrDefault(e => e.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Student with Id = " + id.ToString() + " not found to update")); } else { entity.FirstName = student.FirstName; entity.LastName = student.LastName; entity.Gender = student.Gender; entity.YearAdmitted = student.YearAdmitted; entity.Class = student.Class; entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public IHttpActionResult Get(int id) { using (StudentsDBEntities ctx = new StudentsDBEntities()) { return(Ok(ctx.Students.FirstOrDefault(s => s.ID == id))); } }
public HttpResponseMessage Delete(int id) { try { using (StudentsDBEntities db = new StudentsDBEntities()) { var student = db.Students.FirstOrDefault(s => s.Id == id); if (student == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Student with Id " + id + " not found to delete.")); } else { db.Students.Remove(student); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
public HttpResponseMessage Put(int id, [FromBody] Student student) { try { using (StudentsDBEntities db = new StudentsDBEntities()) { var _student = db.Students.FirstOrDefault(s => s.Id == id); if (_student == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Student with Id " + id.ToString() + " not found to edit.")); } else { _student.FirstName = student.FirstName; _student.LastName = student.LastName; _student.Birthday = student.Birthday; db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK, _student)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
//[BasicAuthentication] public IHttpActionResult Get(string schoolClass, string gender = "All") { string grade = Thread.CurrentPrincipal.Identity.Name; using (StudentsDBEntities entities = new StudentsDBEntities()) { if (!(gender.ToLower() == "all" || gender.ToLower() == "male" || gender.ToLower() == "female")) { return(BadRequest()); } switch (schoolClass.ToLower()) { case "all": return(Ok(entities.Students.ToList())); case "pry1": var test = entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList(); return(Ok(test)); case "pry2": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "pry3": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "pry4": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "pry5": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "jss1": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "jss2": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "jss3": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "ss1": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "ss2": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); case "ss3": return(Ok(entities.Students.Where(e => e.Class.ToLower() == schoolClass.ToLower() && e.Gender.ToLower() == gender.ToLower()).ToList())); default: return(BadRequest()); } } }
protected override void Dispose(bool disposing) { if (disposing) { using (StudentsDBEntities ctx = new StudentsDBEntities()) { ctx.Dispose(); } } base.Dispose(disposing); }
private void EdytujStudentaBtn_Click(object sender, RoutedEventArgs e) { StudentsDBEntities SDE = new StudentsDBEntities(); var ST = SDE.StudentsTable.Where(p => p.Id == row.Id).FirstOrDefault(); ST.StudentName = ImieTb.Text; ST.StudentSurname = NazwiskoTb.Text; ST.DateOfBirt = DataDp.SelectedDate.Value; SDE.SaveChanges(); DialogResult = true; }
public IHttpActionResult GetStudents() { using (StudentsDBEntities db = new StudentsDBEntities()) { var students = db.Students.ToList(); if (students == null) { return(NotFound()); } return(Ok(students)); } }
public IHttpActionResult Delete(int id) { using (StudentsDBEntities ctx = new StudentsDBEntities()) { var studentToDelete = ctx.Students.FirstOrDefault(s => s.ID == id); var gradesAndCourses = from studentCourses in ctx.StudentCourses where studentCourses.StudentID == id select studentCourses; foreach (StudentCourses element in gradesAndCourses) { ctx.StudentCourses.Remove(element); } ctx.Students.Remove(studentToDelete); return(Ok(ctx.SaveChanges())); } }
public IHttpActionResult Put([FromBody] Grades grade, int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (StudentsDBEntities ctx = new StudentsDBEntities()) { var gradeToEdit = ctx.Grades.FirstOrDefault(g => g.ID == id); gradeToEdit.LetterEquivalent = grade.LetterEquivalent; gradeToEdit.NumberEquivalent = grade.NumberEquivalent; return(Ok(ctx.SaveChanges())); } }
public IHttpActionResult Post([FromBody] Students student) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (StudentsDBEntities ctx = new StudentsDBEntities()) { var maxId = ctx.Students.ToList().Select(s => s).Max(x => x.ID); student.ID = maxId + 1; ctx.Students.Add(student); return(Ok(ctx.SaveChanges())); } }
public HttpResponseMessage Get(int id) { using (StudentsDBEntities entities = new StudentsDBEntities()) { var entity = entities.Students.FirstOrDefault(e => e.ID == id); if (entity != null) { return(Request.CreateResponse(HttpStatusCode.OK, entity)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Student with Id = " + id.ToString() + " not found")); } } }
public IHttpActionResult Put([FromBody] Courses course, int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (StudentsDBEntities ctx = new StudentsDBEntities()) { var courseToEdit = ctx.Courses.FirstOrDefault(c => c.ID == id); courseToEdit.Name = course.Name; courseToEdit.DayLength = course.DayLength; return(Ok(ctx.SaveChanges())); } }
private void DodajOceneBtn_Click(object sender, RoutedEventArgs e) { StudentsDBEntities SDE = new StudentsDBEntities(); AssessmentsTable AT = new AssessmentsTable(); var checkedAssessment = OcenySp.Children.OfType <RadioButton>() .FirstOrDefault(r => r.IsChecked.HasValue && r.IsChecked.Value); var checkedSubject = PrzedmiotySp.Children.OfType <RadioButton>() .FirstOrDefault(r => r.IsChecked.HasValue && r.IsChecked.Value); AT.Assessment = Decimal.Parse(checkedAssessment.Content.ToString().Replace(".", ",")); AT.IndeksID = indeksId; AT.Subjects = checkedSubject.Content.ToString(); SDE.AssessmentsTable.Add(AT); SDE.SaveChanges(); DialogResult = true; }
public HttpResponseMessage GetStudent(int id) { using (StudentsDBEntities db = new StudentsDBEntities()) { var student = db.Students.FirstOrDefault(s => s.Id == id); if (student != null) { return(Request.CreateResponse(HttpStatusCode.OK, student)); } else { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Student with Id " + id + " not found.")); } } }
public IHttpActionResult Get(int id) { using (StudentsDBEntities ctx = new StudentsDBEntities()) { var studentResults = from c in ctx.Courses join sc in ctx.StudentCourses on c.ID equals sc.CourseID join g in ctx.Grades on sc.GradeID equals g.ID join s in ctx.Students on sc.StudentID equals s.ID where sc.StudentID == id select new { c.ID, c.Name, g.NumberEquivalent, g.LetterEquivalent }; if (studentResults == null) { return(NotFound()); } return(Ok(studentResults.ToList())); } }
public IHttpActionResult Put([FromBody] Students student, int id) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } using (StudentsDBEntities ctx = new StudentsDBEntities()) { var studentToEdit = ctx.Students.FirstOrDefault(s => s.ID == id); studentToEdit.Name = student.Name; studentToEdit.Surname = student.Surname; studentToEdit.City = student.City; studentToEdit.DateOfBirth = student.DateOfBirth; return(Ok(ctx.SaveChanges())); } }
public HttpResponseMessage Post([FromBody] Student student) { try { using (StudentsDBEntities entities = new StudentsDBEntities()) { entities.Students.Add(student); entities.SaveChanges(); var message = Request.CreateResponse(HttpStatusCode.Created, student); message.Headers.Location = new Uri(Request.RequestUri + student.ID.ToString()); return(message); } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }
private void DodajStudentaBtn_Click(object sender, RoutedEventArgs e) { int id = Int32.Parse(IndeksTb.Text); StudentsDBEntities SDE = new StudentsDBEntities(); StudentsTable ST = new StudentsTable(); var czy_istnieje = SDE.StudentsTable.Where(p => p.Id == id).FirstOrDefault(); if (czy_istnieje == null) { ST.Id = Int32.Parse(IndeksTb.Text); ST.StudentName = ImieTb.Text; ST.StudentSurname = NazwiskoTb.Text; ST.DateOfBirt = DataDp.SelectedDate.Value; SDE.StudentsTable.Add(ST); SDE.SaveChanges(); } else { MessageBox.Show("Istnieje już taki student"); } DialogResult = true; }
public HttpResponseMessage Delete(int id) { try { using (StudentsDBEntities entities = new StudentsDBEntities()) { var entity = entities.Students.FirstOrDefault(e => e.ID == id); if (entity == null) { return(Request.CreateErrorResponse(HttpStatusCode.NotFound, "Student with Id = " + id.ToString() + " not found to delete")); } else { entities.Students.Remove(entity); entities.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } } } catch (Exception ex) { return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex)); } }