Esempio n. 1
0
 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));
     }
 }
Esempio n. 2
0
 public IEnumerable <Student> Get()
 {
     using (StudentsDBEntities entities = new StudentsDBEntities())
     {
         return(entities.Students.ToList());
     }
 }
Esempio n. 3
0
 public IHttpActionResult Get()
 {
     using (StudentsDBEntities ctx = new StudentsDBEntities())
     {
         return(Ok(ctx.Students.ToList()));
     }
 }
Esempio n. 4
0
 public object getStudentData()
 {
     using (StudentsDBEntities entities = new StudentsDBEntities())
     {
         return(entities.Students.ToList());
     }
 }
Esempio n. 5
0
        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));
            }
        }
Esempio n. 6
0
 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));
            }
        }
Esempio n. 9
0
        //[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());
                }
            }
        }
Esempio n. 10
0
 protected override void Dispose(bool disposing)
 {
     if (disposing)
     {
         using (StudentsDBEntities ctx = new StudentsDBEntities())
         {
             ctx.Dispose();
         }
     }
     base.Dispose(disposing);
 }
Esempio n. 11
0
        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));
     }
 }
Esempio n. 13
0
 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()));
     }
 }
Esempio n. 14
0
        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()));
            }
        }
Esempio n. 15
0
        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()));
            }
        }
Esempio n. 16
0
        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"));
                }
            }
        }
Esempio n. 17
0
        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()));
            }
        }
Esempio n. 18
0
        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."));
                }
            }
        }
Esempio n. 20
0
 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()));
     }
 }
Esempio n. 21
0
        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()));
            }
        }
Esempio n. 22
0
        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));
            }
        }
Esempio n. 23
0
        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;
        }
Esempio n. 24
0
        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));
            }
        }