public IHttpActionResult Post(HomeworkRequestModels homework) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var dbHomework = new Homework { Content = homework.Content, TimeSent = homework.TimeSent, StudentId = homework.StudentId, CourseId = homework.CourseId }; this.homeworkRepository.InsertHomework(dbHomework); this.homeworkRepository.Save(); return this.Ok(homework); }
public static void Main() { Database.SetInitializer( new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>()); var db = new StudentSystemContext(); var student = new Student { FirstName = "Ivan", LastName = "Ivanov", Number = 13532 }; var course = new Course { Name = "JS", Description = "JS", Materials = "www.telerik" }; var homework = new Homework { Content = "Done", TimeSent = DateTime.Now, StudentId = 2, CourseId = 2 }; db.Homeworks.Add(homework); student.Courses.Add(course); db.Students.Add(student); db.Courses.Add(course); db.SaveChanges(); Console.WriteLine(db.Students.Count()); Console.WriteLine(db.Courses.Count()); }
private static void AddHomeworks(int homeworksCount) { var dbContext = new StudentsSystemDbContext(); var coursesIds = dbContext.Courses .Select(c => c.Id) .ToList(); int coursesIdsCount = coursesIds.Count; var studentsIds = dbContext.Students .Select(st => st.Id) .ToList(); for (int i = 0; i < homeworksCount; i++) { var hw = new Homework(); hw.Content = RandomDataGenerator.GetString(1, 500); int courseIndex = RandomDataGenerator.GetInteger(0, coursesIdsCount - 1); hw.CourseId = coursesIds[courseIndex]; // works while students count is equal or greater than homeworks count hw.StudentId = studentsIds[i]; dbContext.Homeworks.Add(hw); if (i % 100 == 0) { dbContext.SaveChanges(); dbContext.Dispose(); dbContext = new StudentsSystemDbContext(); } } dbContext.SaveChanges(); }
static void Main() { Database.SetInitializer( new MigrateDatabaseToLatestVersion<StudentSystemDbContext, Configuration>()); using (var db = new StudentSystemDbContext()) { var student = new Student { FirstName = "Sam", LastName = "Jones", Number = 5203 }; var course = new Course { Name = "Math", Description = "Stereometrics", Materials = "http://math.com" }; var homework = new Homework { Content = "Done", TimeSent = new DateTime(2015, 8, 15) }; db.Homeworks.Add(homework); student.Courses.Add(course); db.Students.Add(student); db.Courses.Add(course); db.SaveChanges(); Console.WriteLine(db.Students.Count()); Console.WriteLine(db.Courses.Count()); } }
public void AddHomework(Homework homework) { this.homeworkSubmissions.Add(homework); }