Ejemplo n.º 1
0
        public string ModStudent(Models2.Student s)
        {
            string odp = "";

            try
            {
                var student = _context.Student.Where(stu => stu.IndexNumber == s.IndexNumber).ToList();
                if (student.Count == 0)
                {
                    //eskaUnik = 0;
                    return("bad req");
                }
                var stu = student[0];

                _context.Entry(stu).CurrentValues.SetValues(s);//połowocznie działa ale popraw
                _context.Entry(stu).State = EntityState.Modified;
                _context.SaveChanges();
                odp = "zmodyfikowano studenta o idndeksie =" + s.IndexNumber;
            }
            catch (Exception exc)
            {
                odp = "Wystapil blad transakcji";
            }
            return(odp);
        }
Ejemplo n.º 2
0
        public IActionResult updateStudent(Models2.Student student)
        {
            var db = new Models2.s19278Context();


            var st = db.Student.Where(e => e.IndexNumber == student.IndexNumber);

            if (!st.Any())
            {
                return(NotFound());
            }
            if (student.LastName != null)
            {
                st.FirstOrDefault().LastName = student.LastName;
            }
            if (student.FirstName != null)
            {
                st.FirstOrDefault().FirstName = student.FirstName;
            }
            if (student.BirthDate != null)
            {
                st.FirstOrDefault().BirthDate = student.BirthDate;
            }
            if (student.IdEnrollment != 0)
            {
                st.FirstOrDefault().IdEnrollment = student.IdEnrollment;
            }
            db.SaveChanges();

            return(Ok());
        }
Ejemplo n.º 3
0
        public string EnrollStudent(Models.Student s)
        {
            if (!(_context.Studies.Any(st => st.Name == s.Studies)))
            {
                return("Nie ma takich studiow");
            }
            if ((_context.Student.Any(st => st.IndexNumber == s.IndexNumber)))
            {
                // JEST TAKI INDEX
                return("Nie jest to unikalny index");
            }
            var s2 = new Models2.Student()
            {
                IndexNumber = s.IndexNumber,
                FirstName   = s.FirstName,
                LastName    = s.LastName,
                BirthDate   = DateTime.Parse(s.BirthDate)
            };
            //var result = _context.Studies.Where(stu => stu.Name == s.Studies).;

            var study   = _context.Studies.Where(stu => stu.Name == s.Studies).FirstOrDefault();
            int idStudy = study.IdStudy;

            if (!(_context.Enrollment.Any(en => en.IdStudy == idStudy && en.Semester == 1 && en.StartDate.Date == DateTime.Now.Date)))
            {
                var setStudent = new HashSet <Student> {
                    s2
                };

                var enroll = new Models2.Enrollment()
                {
                    IdEnrollment = _context.Enrollment.Select(en => en.IdEnrollment).Max() + 1,
                    Semester     = 1,
                    StartDate    = DateTime.Now.Date,
                    Student      = setStudent,
                };

                study.Enrollment.Add(enroll);
                _context.Add(enroll);
                _context.Attach(study);
                _context.Entry(study).State = EntityState.Modified;
                _context.SaveChanges();

                return("Utworzono enrollment i student");
            }
            else
            {
                var enroll = _context.Enrollment.Where(en => en.IdStudy == idStudy && en.Semester == 1 && en.StartDate.Date == DateTime.Now.Date).FirstOrDefault();

                enroll.Student.Add(s2);
                _context.Attach(enroll);
                _context.Entry(enroll).State = EntityState.Modified;
                _context.SaveChanges();

                return("Utworzono student");
            }
        }
Ejemplo n.º 4
0
 public bool ModifyStudents(Models2.Student s)
 {
     try
     {
         _context.Attach(s);
         _context.Entry(s).State = EntityState.Modified;
         _context.SaveChanges();
         return(true);
     }
     catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 5
0
        public IActionResult ModStudent(Models2.Student s)
        {
            Student stu      = s;
            var     operacja = _context.ModStudent(stu);

            if (operacja == "bad req")
            {
                return(BadRequest("nie ma takiej eski"));
            }
            else if (operacja == "Wystapil blad transakcji")
            {
                return(BadRequest(operacja));
            }
            return(Ok(operacja));
        }
Ejemplo n.º 6
0
 public bool DeleteStudents(Models2.Student d)
 {
     try
     {
         /*var d = new Student
          * {
          *  IndexNumber = index
          * };*/
         _context.Attach(d);
         _context.Remove(d);
         _context.SaveChanges();
         return(true);
     }catch (Exception e)
     {
         return(false);
     }
 }
Ejemplo n.º 7
0
 public IActionResult updateStudent(Models2.Student student)
 {
     return(Ok(_dbService.updateStudent(student)));
 }
Ejemplo n.º 8
0
        public string EnrollStudent(Models.Student s)
        {
            int eskaUnik = 1;
            var student  = new Student();

            var studia = _context.Studies.Where(stu => stu.Name == s.Studies).ToList();

            if (studia.Count == 0)
            {
                return("nie ma takiego kierunku");
            }
            var unikId = _context.Student.Where(stu => stu.IndexNumber == s.IndexNumber).ToList();

            if (unikId.Count != 0)
            {
                eskaUnik = 0;
                student  = unikId[0];
            }
            var stud = new Models2.Student()
            {
                IndexNumber = s.IndexNumber,
                FirstName   = s.FirstName,
                LastName    = s.LastName,
                BirthDate   = DateTime.Parse(s.BirthDate)
            };

            var study   = _context.Studies.Where(stu => stu.Name == s.Studies).FirstOrDefault();
            int idStudy = study.IdStudy;

            if ((!(_context.Enrollment.Any(enrl => enrl.IdStudy == idStudy && enrl.Semester == 1 && enrl.StartDate.Date == DateTime.Now.Date))))
            {
                if (eskaUnik == 1)
                {
                    var setStudent = new HashSet <Student> {
                        stud
                    };
                    var enroll = new Models2.Enrollment()
                    {
                        IdEnrollment = _context.Enrollment.Select(en => en.IdEnrollment).Max() + 1,
                        Semester     = 1,
                        StartDate    = DateTime.Now.Date,
                        Student      = setStudent,
                    };
                    study.Enrollment.Add(enroll);
                    _context.Add(enroll);
                    _context.Attach(study);
                    _context.Entry(study).State = EntityState.Modified;

                    _context.SaveChanges();
                    return("dodano nowego studenta i nowy enroll");
                }
                else
                {
                    var setStudent = new HashSet <Student> {
                        student
                    };
                    var enroll = new Models2.Enrollment()
                    {
                        IdEnrollment = _context.Enrollment.Select(en => en.IdEnrollment).Max() + 1,
                        Semester     = 1,
                        StartDate    = DateTime.Now.Date,
                        Student      = setStudent,
                    };
                    study.Enrollment.Add(enroll);
                    _context.Add(enroll);
                    _context.Attach(study);
                    _context.Entry(study).State = EntityState.Modified;

                    _context.SaveChanges();
                    return("zapisano studenta na nowy enroll");
                }
            }
            else
            {
                if (eskaUnik == 1)
                {
                    var enroll = _context.Enrollment.Where(en => en.IdStudy == idStudy && en.Semester == 1 && en.StartDate.Date == DateTime.Now.Date).FirstOrDefault();
                    enroll.Student.Add(stud);
                    _context.Attach(study);
                    _context.Entry(study).State = EntityState.Modified;
                    _context.SaveChanges();
                    return("dodano nowego studenta na instniejacy enroll");
                }
                else
                {
                    var enroll = _context.Enrollment.Where(en => en.IdStudy == idStudy && en.Semester == 1 && en.StartDate.Date == DateTime.Now.Date).FirstOrDefault();
                    enroll.Student.Add(student);
                    _context.Attach(study);
                    _context.Entry(study).State = EntityState.Modified;
                    _context.SaveChanges();
                    return("dodano studenta na instniejacy enroll");
                }
            }
        }
Ejemplo n.º 9
0
 public IActionResult updateStudent(Models2.Student student)
 {
     throw new NotImplementedException();
 }