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 ActionResult Courses_Create([DataSourceRequest]DataSourceRequest request, Course course) { var newId = 0; if (ModelState.IsValid) { var entity = new Course { Title = course.Title, Type = course.Type, CategoryId = 1, CreatedOn = course.CreatedOn, ModifiedOn = course.ModifiedOn, IsDeleted = course.IsDeleted, DeletedOn = course.DeletedOn, UserId = this.User.Identity.GetUserId() }; this.courses.Add(entity); this.courses.Save(); newId = entity.Id; } var courseToDisplay = this.courses.GetAll().FirstOrDefault(x => x.Id == newId); return Json(new[] { courseToDisplay }.ToDataSourceResult(request, ModelState)); }
public static Test FromModelToData(Course testModel) { return new Test() { Course = testModel }; }
public static CourseModel TransformCourse(Course c) { if (c==null) { return null; } return new CourseModel() { Description = c.Description, Id = c.Id, Name = c.Name, Students = c.Students.ToList().Select(StudentModel.TransformStudent).ToList() }; }
public IHttpActionResult Post(CourseModel model) { if (!this.ModelState.IsValid) { return this.BadRequest("Incorrect data"); } var item = new Course() { Name = model.Name, Description = model.Description }; this.Data.Courses.Add(item); this.Data.SaveChanges(); return this.Ok("Record added"); }
public ActionResult Courses_Destroy([DataSourceRequest]DataSourceRequest request, Course course) { if (ModelState.IsValid) { var entityToDelete = this.courses.GetById(course.Id); this.courses.Delete(entityToDelete); this.courses.Save(); //var entity = new Course //{ // Id = course.Id, // Title = course.Title, // Type = course.Type, // CreatedOn = course.CreatedOn, // ModifiedOn = course.ModifiedOn, // IsDeleted = course.IsDeleted, // DeletedOn = course.DeletedOn //}; } return Json(new[] { course }.ToDataSourceResult(request, ModelState)); }
public Homework(string content, ContentTypeEnum contentType, DateTime submissionDate, Course course, Student student) { this.HomeWorkContent = content; this.ContentType = contentType; this.SubmissionDate = submissionDate; this.Course = course; this.Student = student; }
public ActionResult Courses_Update([DataSourceRequest]DataSourceRequest request, Course course) { //if (ModelState.IsValid) //{ var entity = this.courses.GetById(course.Id); entity.Title = course.Title; entity.Type = course.Type; entity.CreatedOn = course.CreatedOn; entity.ModifiedOn = course.ModifiedOn; entity.IsDeleted = course.IsDeleted; entity.DeletedOn = course.DeletedOn; entity.UserId = this.User.Identity.GetUserId(); //var entity = new Course //{ // Id = course.Id, // Title = course.Title, // Type = course.Type, // CreatedOn = course.CreatedOn, // ModifiedOn = course.ModifiedOn, // IsDeleted = course.IsDeleted, // DeletedOn = course.DeletedOn //}; this.courses.Update(entity); //} var courseToDisplay = this.courses.GetAll().FirstOrDefault(x => x.Id == course.Id); return Json(new[] { courseToDisplay }.ToDataSourceResult(request, ModelState)); }
public IHttpActionResult Create(Course course) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } this.StudentSystemData.Courses.Add(course); this.StudentSystemData.SaveChanges(); return this.CreatedAtRoute("DefaultApi", new { id = course.CourseId }, course); }