public DataSeeder() { this.Students = new List<Student>(); this.Courses = new List<Course>(); this.Homeworks = new List<Homework>(); this.randomGenerator = new Random(); for (int i = 0; i < 100; i++) { var deadLine = new Homework() { Content = this.GetRandomName(), DeadLine = this.GerRandomDate() }; this.Homeworks.Add(deadLine); } for (int i = 0; i < 100; i++) { var student = new Student() { Name = this.GetRandomName(), StudentId = GetRandomNumberInRange(0, 10), HomeWorks = this.Homeworks.Take(10).ToList()}; this.Students.Add(student); } for (int i = 0; i < 100; i++) { var course = new Course() { Name = this.GetRandomName(), Description = this.GetRandomName(), Materials = this.GetRandomName(), Homeworks = this.Homeworks.Take(100).ToList(),Students=this.Students.Take(1).ToList()}; this.Courses.Add(course); } }
public IHttpActionResult Create(Homework homework) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } this.StudentSystemData.Homeworks.Add(homework); this.StudentSystemData.SaveChanges(); return this.CreatedAtRoute("DefaultApi", new { id = homework.HomeworkId }, homework); }
public IHttpActionResult Post(HomeworkModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Incorrect data"); } // Just adding first student and course var item = new Homework() { FileUrl = model.FileUrl, TimeSent = DateTime.Now, StudentId = this.Data.Students.All().First().Id, CourseId = this.Data.Courses.All().First().Id }; this.Data.Homeworks.Add(item); this.Data.SaveChanges(); return this.Ok("Record added"); }
public IHttpActionResult Update(int id, Homework model) { if (!this.ModelState.IsValid) { return this.BadRequest("Invalid model"); } var item = this.Data.Homeworks.GetById(id); if (item == null) { return this.NotFound(); } item.FileUrl = model.FileUrl; item.TimeSent = model.TimeSent; this.Data.Homeworks.Update(item); this.Data.SaveChanges(); return this.Ok("Updated"); }