public string Post(Student student)
        {
            Student studentToUpdate = null;

            if (student.Id > 0)
            {
                studentToUpdate = db.Students.First(i => i.Id == student.Id);
            }
            else
            {
                studentToUpdate = new Student();
            }

            studentToUpdate.FirstName = student.FirstName;
            studentToUpdate.LastName = student.LastName;
            studentToUpdate.Courses = student.Courses;
            studentToUpdate.personalId = student.personalId;

            if (student.Id > 0)
            {
                db.Entry(studentToUpdate).State = EntityState.Modified;
            }
            else
            {
                db.Students.Add(studentToUpdate);
            }

            db.SaveChanges();

            return string.Format("{0} {1}", student.FirstName, student.LastName);
        }
示例#2
0
        public string Post(Student student)
        {
            if (student.Id == 0)
            {
                if (MvcApplication.Courses.Any())
                {
                    var id = MvcApplication.Students.Max(x => x.Id) + 1;
                    student.Id = id;
                }
                else
                {
                    student.Id = 1;
                }
            }
            else
            {
                var savedIndex = MvcApplication.Students.FindIndex(x => x.Id == student.Id);
                MvcApplication.Students.RemoveAt(savedIndex);
            }

            MvcApplication.Students.Add(student);

            return string.Format("{0}{1}", student.FirstName, student.LastName);

            //return student.Name;

            //if (student.Id == 0)
            //{
            //    var id = MvcApplication.Students.Max(x => x.Id) + 1;
            //    student.Id = id;
            //}
            //MvcApplication.Students.Add(student);

            //return string.Format("{0} {1}", student.FirstName, student.LastName);
        }
        public string Post(Student student)
        {
            if (student.Id == 0)
            {
                var id = MvcApplication.Students.Max(x => x.Id) + 1;
                student.Id = id;
            }
            MvcApplication.Students.Add(student);

            return string.Format("{0} {1}", student.FirstName, student.LastName);
        }
 public string Post(Student student)
 {
     if (student.Id > 0) //Save it
     {
         db.Entry(student).State = System.Data.Entity.EntityState.Modified;
     }
     else // Add it
     {
         db.Students.Add(student);
     }
     db.SaveChanges();
     return string.Format("{0} {1}", student.FirstName, student.LastName);
 }
示例#5
0
        public string Post(Student student)
        {
            if (student.Id > 0) // Save
            {
                db.Entry(student).State = EntityState.Modified;
            }
            else  // Add
            {
                db.Students.Add(student);
            }
            db.SaveChanges();

            return string.Format("{0} {1} {2} {3}", student.FirstName, student.LastName, student.SocialSecurityNumber, student.Active);
        }
        public string Post(Student student)
        {
            if (student.Id > 0) // save
            {
                db.Entry(student).State = System.Data.Entity.EntityState.Modified;
            }
            else // add
            {
                db.Students.Add(student);
                //var savedIndex = MvcApplication.Students.FindIndex(x => x.Id == student.Id);
                //MvcApplication.Students.RemoveAt(savedIndex);
            }
            db.SaveChanges();

            return string.Format("{0} {1}", student.FirstName, student.LastName);
        }
示例#7
0
        private static void LoadStudents()
        {
            var student = new Student
            {
                Id = 1,
                FirstName = "Kalle",
                LastName = "Bengtsson",
                Personnummer = "760101-9999",
                Active = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 2,
                FirstName = "Eva",
                LastName = "Andersson",
                Personnummer = "760101-4444",
                Active = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 3,
                FirstName = "Ylva",
                LastName = "Nordsson",
                Personnummer = "760101-5555",
                Active = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 4,
                FirstName = "Evy",
                LastName = "Carlsson",
                Personnummer = "760101-7711",
                Active = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 5,
                FirstName = "Lisa",
                LastName = "Olofsson",
                Personnummer = "760101-6666",
                Active = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 6,
                FirstName = "Robert",
                LastName = "Tovek",
                Personnummer = "760101-2222",
                Active = true
            };
            Students.Add(student);
        }
        private static void LoadStudents()
        {
            var student = new Student
            {
                Id = 1,
                FirstName = "Kalle",
                LastName = "Bengtsson",
                personalId = "1992-06-12-1231"
            };
            Students.Add(student);

            student = new Student
            {
                Id = 2,
                FirstName = "Eva",
                LastName = "Andersson",
                personalId = "1992-01-05-1232"
            };
            Students.Add(student);

            student = new Student
            {
                Id = 3,
                FirstName = "Ylva",
                LastName = "Nordsson",
                personalId = "1992-12-21-1233"
            };
            Students.Add(student);

            student = new Student
            {
                Id = 4,
                FirstName = "Evy",
                LastName = "Carlsson",
                personalId = "1992-10-29-1234"
            };
            Students.Add(student);

            student = new Student
            {
                Id = 5,
                FirstName = "Lisa",
                LastName = "Olofsson",
                personalId = "1992-03-04-1235"
            };
            Students.Add(student);

            student = new Student
            {
                Id = 6,
                FirstName = "Robert",
                LastName = "Tovek",
                personalId = "1992-11-09-1236"
            };
            Students.Add(student);
        }
        private static void LoadStudents()
        {
            var student = new Student
            {
                Id = 1,
                FirstName = "Kalle",
                LastName = "Bengtsson",
                Ssn = "19920317-1310",
                IsActive = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 2,
                FirstName = "Eva",
                LastName = "Andersson",
                Ssn = "19920317-1311",
                IsActive = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 3,
                FirstName = "Ylva",
                LastName = "Nordsson",
                Ssn = "19920317-1312",
                IsActive = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 4,
                FirstName = "Evy",
                LastName = "Carlsson",
                Ssn = "19920317-1313",
                IsActive = false
            };
            Students.Add(student);

            student = new Student
            {
                Id = 5,
                FirstName = "Lisa",
                LastName = "Olofsson",
                Ssn = "19920317-1314",
                IsActive = true
            };
            Students.Add(student);

            student = new Student
            {
                Id = 6,
                FirstName = "Robert",
                LastName = "Tovek",
                Ssn = "19920317-1314",
                IsActive = true
            };
            Students.Add(student);
        }