Exemplo n.º 1
0
        public async Task <IActionResult> CreateNewMeeting([FromBody] TeacherStudentMeeting newMeeting)
        {
            var meeting = new TeacherStudentMeeting
            {
                AcceptedByTeacher = false,
                Duration          = 120,
                MeetingDate       = new DateTime(2018, 06, 13),
                StudentID         = 1,
                TeacherID         = 2,
                TotalCost         = 40
            };

            try
            {
                //await _context.Meetings.AddAsync(newMeeting);
                await _context.Meetings.AddAsync(meeting);

                await _context.SaveChangesAsync();

                return(CreatedAtAction(nameof(CreateNewMeeting), new { id = meeting.Id }, null));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }
Exemplo n.º 2
0
        public static void Initialize(MeetingContext context)
        {
            context.Database.EnsureDeleted();
            context.Database.EnsureCreated();

            if (context.Meetings.Any()) //DB has been seeded
            {
                return;
            }

            var meetings = new TeacherStudentMeeting[]
            {
                new TeacherStudentMeeting {
                    StudentID         = 1,
                    TeacherID         = 2,
                    MeetingDate       = new DateTime(2018, 06, 10),
                    AcceptedByTeacher = false
                },
                new TeacherStudentMeeting {
                    StudentID         = 1,
                    TeacherID         = 3,
                    MeetingDate       = new DateTime(2018, 06, 10),
                    AcceptedByTeacher = true
                },
                new TeacherStudentMeeting {
                    StudentID         = 2,
                    TeacherID         = 1,
                    MeetingDate       = new DateTime(2017, 05, 30),
                    AcceptedByTeacher = false
                }
            };

            foreach (TeacherStudentMeeting m in meetings)
            {
                context.Meetings.Add(m);
            }
            context.SaveChanges();
        }