Ejemplo n.º 1
0
        public string Post(Course course)
        {
            Course courseToUpdate = null;

            if (course.Id > 0)
            {

                courseToUpdate = db.Courses.Include("Students").First(i => i.Id == course.Id);

            }
            else
            {
                courseToUpdate = new Course();

            }

            courseToUpdate.Aktiv = course.Aktiv;
            courseToUpdate.Credits = course.Credits;
            courseToUpdate.Name = course.Name;
            courseToUpdate.Term = course.Term;
            courseToUpdate.Year = course.Year;

            foreach (var student in db.Students)
            {
                if (!course.Students.Any(item => item.Id == student.Id))
                {

                    courseToUpdate.Students.Remove(student);

                }
                else
                {

                    courseToUpdate.Students.Add((student));
                }

            }

            if (course.Id > 0)
            {

                db.Entry(courseToUpdate).State = EntityState.Modified;
            }

            else
            {

                db.Courses.Add(courseToUpdate);
            }
            db.SaveChanges();

            return course.Name;
        }
        private static void LoadCourses()
        {
            var course = new Course()
            {
                Id = 1,
                //Students = Students,
                Credits = "15",
                Name = "Pedagogik 1",
                Term = "VT",
                Year = "2015"
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 2,
                //Students = Students,
                Credits = "10",
                Name = "Pedagogik 2",
                Term = "VT",
                Year = "2015"
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 3,
                //Students = Students,
                Credits = "5",
                Name = "Datalogi 1",
                Term = "VT",
                Year = "2015"
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 4,
                //Students = Students,
                Credits = "7,5",
                Name = "Filosofi 1",
                Term = "VT",
                Year = "2015"
            };
            Courses.Add(course);
        }
Ejemplo n.º 3
0
        public string Post(Course course)
        {
            if (course.Id == 0)
            {
                if (MvcApplication.Courses.Any())
                {
                    var id = MvcApplication.Courses.Max(x => x.Id) + 1;
                    course.Id = id;
                }
                else
                {
                    course.Id = 1;
                }
            }
            else
            {
                var savedIndex = MvcApplication.Courses.FindIndex(x => x.Id == course.Id);
                MvcApplication.Courses.RemoveAt(savedIndex);
            }
            MvcApplication.Courses.Add(course);

            return course.Name;
        }
        public string Post(Course course)
        {
            Course courseToUpdate = null;

            courseToUpdate = course.Id > 0 ? db.Courses.Include("Students").First(i => i.Id == course.Id) : new Course();

            courseToUpdate.IsActive = course.IsActive;
            courseToUpdate.Credits = course.Credits;
            courseToUpdate.Name = course.Name;
            courseToUpdate.Term = course.Term;
            courseToUpdate.Year = course.Year;

            foreach (var student in db.Students)
            {
                if (course.Students.All(item => item.Id != student.Id)) // Contains
                {
                    courseToUpdate.Students.Remove(student);
                }
                else
                {
                    courseToUpdate.Students.Add(student);
                }
            }

            if (course.Id > 0)
            {
                db.Entry(courseToUpdate).State = EntityState.Modified;
            }
            else
            {
                db.Courses.Add(courseToUpdate);
            }

            db.SaveChanges();

            return course.Name;
        }
Ejemplo n.º 5
0
        private static void LoadCourses()
        {
            var course = new Course()
            {
                Id = 1,
                Students = Students,
                SchoolNo = "c08bdab7-ed3d-4048-8338-d4f14f2770a8",
                Credits = "15",
                Name = "Pedagogik 1",
                Term = "VT",
                Year = "2015",
                Active = false
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 2,
                //Students = Students,
                SchoolNo = "c08bdab7-ed3d-4048-8338-d4f14f2770a8",
                Credits = "10",
                Name = "Pedagogik 2",
                Term = "VT",
                Year = "2015",
                Active = false
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 3,
                //Students = Students,
                SchoolNo = "c08bdab7-ed3d-4048-8338-d4f14f2770a8",
                Credits = "5",
                Name = "Datalogi 1",
                Term = "VT",
                Year = "2015",
                Active = true
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 4,
                //Students = Students,
                SchoolNo = "c08bdab7-ed3d-4048-8338-d4f14f2770a8",
                Credits = "7,5",
                Name = "Filosofi 1",
                Term = "VT",
                Year = "2015",
                Active = true
            };
            Courses.Add(course);
        }
Ejemplo n.º 6
0
        private static void LoadCourses()
        {
            var course = new Course()
            {
                Id = 1,
                Credits = "15",
                Name = "Pedagogik 1",
                Term = "VT",
                Year = "2015",
                IsActive = true
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 2,
                Credits = "10",
                Name = "Pedagogik 2",
                Term = "VT",
                Year = "2015",
                IsActive = false
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 3,
                Credits = "5",
                Name = "Datalogi 1",
                Term = "VT",
                Year = "2015",
                IsActive = false
            };
            Courses.Add(course);

            course = new Course()
            {
                Id = 4,
                Credits = "7.5",
                Name = "Filosofi 1",
                Term = "VT",
                Year = "2015",
                IsActive = true
            };
            Courses.Add(course);
        }