static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); var db = new StudentSystemContext(); using (db) { var homework = new Homework(); var student = new Student(); var course = new Course(); student.FirstName = "Gancho"; student.LastName = "Minchev"; student.StudentNumber = 12345; course.Name = "Animals"; course.Students.Add(student); course.Homeworks.Add(homework); course.Materials = "Books"; course.Students.Add(student); homework.Content = "African Animals"; homework.Course = course; student.Homeworks.Add(homework); db.SaveChanges(); } }
public IHttpActionResult PutHomework(int id, Homework homework) { if (!ModelState.IsValid) { return BadRequest(ModelState); } if (id != homework.Id) { return BadRequest(); } db.Entry(homework).State = EntityState.Modified; try { db.SaveChanges(); } catch (DbUpdateConcurrencyException) { if (!HomeworkExists(id)) { return NotFound(); } else { throw; } } return StatusCode(HttpStatusCode.NoContent); }
public IHttpActionResult AddHomework(int id, HomeworkModel homework) { var course = this.data.Courses .All() .FirstOrDefault(c => c.Id == id); if (course == null) { return BadRequest("Course not exist - invalid id"); } if (!this.ModelState.IsValid) { return BadRequest(this.ModelState); } var newHomework = new Homework { Content = homework.Content, Deadline = homework.Deadline }; course.Homeworks.Add(newHomework); foreach (var student in course.Students) { student.Homeworks.Add(newHomework); } this.data.Courses.SaveChanges(); return Ok(homework); }
public IHttpActionResult Post(HomeworkRequestModel model) { if (model == null) { return this.BadRequest(); } var db = new StudentSystemDbContext(); var homeworsRepo = new GenericRepository<Homework>(db); var coursesRepo = new GenericRepository<Course>(db); var studentsRepo = new GenericRepository<Student>(db); Course defaultCourse = coursesRepo.All().ToList().FirstOrDefault(); Student defaultStudent = studentsRepo.All().ToList().FirstOrDefault(); var homeworkToAdd = new Homework { FileUrl = model.FileUrl, TimeSent = new DateTime(model.TimeSentTicks), Course = defaultCourse, CourseId = defaultCourse.Id, Student = defaultStudent, StudentIdentification = defaultStudent.StudentIdentification }; homeworsRepo.Add(homeworkToAdd); homeworsRepo.SaveChanges(); return this.Ok(); }
/* 02. Write a console application that uses the data.*/ /// <summary> /// Mains this instanse. /// </summary> public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); using (var db = new StudentSystemContext()) { var pesho = new Student { Name = "Pesho", Number = 666 }; db.Students.Add(pesho); db.SaveChanges(); var dbCourse = new Course { Name = "Database Course", Description = "Basic Database operations", Materials = "http://telerikacademy.com/Courses/Courses/Details/98" }; db.Courses.Add(dbCourse); db.SaveChanges(); var course = db.Courses.First(c => c.Name == dbCourse.Name); var student = db.Students.First(s => s.Number == pesho.Number); var hw = new Homework { Content = "Empty Homework", TimeSent = DateTime.Now, CourseId = course.CourseId, StudentId = student.StudentID }; db.Homeworks.Add(hw); db.SaveChanges(); } ListStudents(); }
public IHttpActionResult GetHomework(int id) { Homework homework = db.Homework.Find(id); if (homework == null) { return(NotFound()); } return(Ok(homework)); }
public override void AddHomeworkToDatabase() { Console.WriteLine("Adding Homework to Database!"); var studentsIds = this.Database.Students .OrderBy(s => Guid.NewGuid()) .Select(s => s.Id) .ToList(); var coursesIds = this.Database.Courses .OrderBy(c => Guid.NewGuid()) .Select(c => c.Id) .ToList(); var averageHomeworkPerCourse = NumberOfHomeworkToAdd / coursesIds.Count; var currentCourseIndex = 0; var currentCourseId = coursesIds[currentCourseIndex]; for (int i = 0; i < NumberOfHomeworkToAdd; i++) { if (i > 0 && i % averageHomeworkPerCourse == 0 && currentCourseIndex < coursesIds.Count - 1) { currentCourseIndex += 1; currentCourseId = coursesIds[currentCourseIndex]; } var studentId = studentsIds[i % studentsIds.Count]; var homeworkToAdd = new Homework { Content = RandomDataGenerator.GetRandomString(20, 300), TimeSent = RandomDataGenerator.GetRandomDate(), StudentId = studentId, CourseId = currentCourseId }; this.Database.Homework.Add(homeworkToAdd); if (i % 500 == 0) { Console.Write("."); } if (i % 100 == 0) { this.Database.SaveChanges(); this.Database.Dispose(); this.Database = new StudentsSystemDbContext(); } } this.Database.SaveChanges(); Console.WriteLine(); }
//[ValidateAntiForgeryToken] public ActionResult Tracker([Bind(Include = "ID,Urgency,DueDate,DueTIme,Department,Course,Title,Notes")] Homework homework) { if (ModelState.IsValid) { db.Homework.Add(homework); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(homework)); }
public async Task <IActionResult> Create([Bind("Id,Description")] Homework homework) { if (ModelState.IsValid) { _context.Add(homework); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(homework)); }
public void AddHomework(int lessonid, string name) { Homework homework = new Homework(); homework.LessonId = lessonid; homework.Name = name; homework.Active = true; homework.CreatedDate = DateTime.Now; _homeworkRepository.Add(homework); _uow.SaveChanges(); }
private static void forloopscanskip() { Primitive numbers = "@"; for (int i = 1; i <= 20; i += ___) { PreventInfiniteLoop(); numbers = numbers + i + ","; } Homework.CheckAnswer(numbers, equals, "@1,3,5,7,9,11,13,15,17,19,"); }
protected void GridView1_RowCommand(object sender, GridViewCommandEventArgs e) { if (e.CommandName == "back") { string[] CommandArgumentValue = e.CommandArgument.ToString().Split(','); string sno = CommandArgumentValue[0]; string cname = CommandArgumentValue[1]; string workname = CommandArgumentValue[2]; BGrade bg = new BGrade(); Grade G = new Grade(workname, sno, cname, false); bg.UpdateGrade2(G); BHomework bh = new BHomework(); Homework h = new Homework(sno, false); if (Page.IsValid) { bh.UpdateHomework2(h); Response.Write("<script>alert('发回成功!');location='RemarkDone.aspx'</script>"); } else { Response.Write("<script>alert('发回失败!');</script>"); } } if (e.CommandName == "download") { string[] CommandArgumentValue = e.CommandArgument.ToString().Split(','); string cname = CommandArgumentValue[0]; string sname = CommandArgumentValue[1]; string workname = CommandArgumentValue[2]; string fileName = cname + sname + workname + ".rar"; string filePath = Server.MapPath("..//Student/upload/" + cname + sname + workname + ".rar"); System.IO.FileInfo fileInfo = new System.IO.FileInfo(filePath); if (fileInfo.Exists == true) { FileStream fs = new FileStream(filePath, FileMode.Open); byte[] bytes = new byte[(int)fs.Length]; fs.Read(bytes, 0, bytes.Length); fs.Close(); Response.ContentType = "application/octet-stream"; Response.AddHeader("Content-Disposition", "attachment; filename=" + HttpUtility.UrlEncode(fileName, System.Text.Encoding.UTF8)); Response.BinaryWrite(bytes); Response.Flush(); Response.End(); } else { Response.Write("<script>alert('下载失败,该学生(" + cname + sname + workname + ")未上传作业材料')</script>"); } } }
public void DeleteHomeworkTestExeption(Homework homework) { var moq = new Mock <IHomeworkContract>(); moq.Setup(a => a.DeleteHomework(homework)).Throws <ArgumentException>(); Assert.Throws <ArgumentException>(() => { moq.Object.DeleteHomework(homework); }); }
public void Remove(Guid id) { Homework homework = homeworksRepository.GetFirst(x => x.Id == id); if (homework == null) { throw new ArgumentException("Invalid guid"); } homeworksRepository.Remove(homework); homeworksRepository.Save(); }
private static string GetHomeworkStatusHtmlString(this Homework homework) { if (homework == null) { return("<td></td>"); } return(!homework.IsCompleted ? IsNullOrEmpty(homework.ReviewComment) ? $"<td class=\"table-success\">{homework.GetUrl()}</td>" : "<td></td>" : $"<td class=\"bg-success\">{homework.GetUrl()}</td>"); }
public async Task Create_HomeworkIsNull_ShouldThrowArgumentNullException() { // arrange Homework homework = null; // act await Assert.ThrowsAsync <ArgumentNullException>(() => _service.Create(homework)); // assert _homeworksRespositoryMock.Verify(x => x.Add(It.IsAny <Homework>()), Times.Never); }
private static void forloopscanstartanywhere() { Primitive answer = "Because "; for (int i = 7; i <= 9; i++) { answer = answer + i; } //Question: Why is 7 the most feared number ? Homework.CheckAnswer(answer, equals, "Because 789"); }
public ActionResult Create([Bind(Include = "ID,HomeworkPriority,DueDate,DueTime,Department,Course,HomeworkTitle,Notes")] Homework homework) { if (ModelState.IsValid) { db.Homeworks.Add(homework); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(homework)); }
private static void forloopscangobackwards() { Primitive numbers = "Countdown: "; for (int i = 5; i >= 1; i += -1) { PreventInfiniteLoop(); numbers = numbers + i; } Homework.CheckAnswer(numbers, equals, "Countdown: 54321"); }
public ActionResult Edit(HomeworkEditModel modelHomework) { Homework myStudent = _homeworkRepository.GetById(modelHomework.Id); Mapper.Map(modelHomework, myStudent); _homeworkRepository.Update(myStudent); const string title = "Tarea Actualizada"; var content = "La tarea " + modelHomework.Title + " ha sido actualizada exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.SuccessMessage); return(RedirectToAction("Index")); }
public ActionResult AddHomework(Homework myHomework) { if (ModelState.IsValid) { HomeworkList.Add(myHomework); return(RedirectToAction("Index", "Home")); } else { return(View(myHomework)); } }
public ActionResult Edit(EditHomeworkModel modelHomework) { Homework myStudent = _homeworkRepository.GetById(modelHomework.Id); var homeworktModel = Mapper.Map <EditHomeworkModel, Homework>(modelHomework); _homeworkRepository.UpdateHomeworkFromHomeworkEditModel(homeworktModel, myStudent); const string title = "Tarea Actualizada"; var content = "La tarea " + modelHomework.Title + " ha sido actualizado exitosamente."; _viewMessageLogic.SetNewMessage(title, content, ViewMessageType.InformationMessage); return(RedirectToAction("Index")); }
public IActionResult Put(Guid id, [FromBody] HomeworkDTO homeworkDTO) { try { Homework homework = homeworkDTO.ToEntity(); Homework updatedHomework = homeworksLogic.Update(id, homework); HomeworkDTO homeworkToReturn = new HomeworkDTO(updatedHomework); return(CreatedAtRoute("Get", new { id = homework.Id }, updatedHomework)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public void UpdateHomework(Homework _homework) { Homework = _homework; this.LB_Subject.Content = Homework.Subject; this.LB_Job.Text = Homework.Job; this.LB_Date.Content = Homework.Date.Value.ToShortDateString(); Recolor(); Refont(); }
public IHttpActionResult PostHomework(Homework homework) { if (!ModelState.IsValid) { return BadRequest(ModelState); } db.Homework.Add(homework); db.SaveChanges(); return CreatedAtRoute("DefaultApi", new { id = homework.Id }, homework); }
public IHttpActionResult PostHomework(Homework homework) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } db.Homework.Add(homework); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = homework.Id }, homework)); }
public IActionResult Post([FromBody] HomeworkDTO homeworkDTO) { try { Homework homework = homeworkDTO.ToEntity(); Homework createdHomework = homeworksLogic.Create(homework); HomeworkDTO homeworkToReturn = new HomeworkDTO(createdHomework); return(CreatedAtRoute("Get", new { id = homeworkToReturn.Id }, homeworkToReturn)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public ActionResult Edit(Homework homeworkInput, string deleteHomeWorks, List <int> deleteIdsList) { if (!string.IsNullOrEmpty(deleteHomeWorks)) { Delete(deleteIdsList); return(RedirectToAction("Edit")); } //add the homework u get _homeworkDb.DbSet.Add(homeworkInput); _homeworkDb.SaveChanges(); return(RedirectToAction("Edit")); }
public static HomeworkModel Parse(Homework homework) { var models = new HomeworkModel { Id = homework.Id, Subject = homework.Subject.Name, SubmitDate = homework.SubmitDate, IsDone = homework.IsDone }; return(models); }
public IActionResult Post([FromBody] Homework homework) { try { Homework createdHomework = logic.Create(homework); return(CreatedAtRoute("Get", new { id = homework.Id }, createdHomework)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public IActionResult Put(Guid id, [FromBody] Homework homework) { try { Homework updatedHomework = logic.Update(id, homework); return(CreatedAtRoute("Get", new { id = homework.Id }, updatedHomework)); } catch (ArgumentException e) { return(BadRequest(e.Message)); } }
public HttpResponseMessage CreateHomework(HomeworkModel model, [ValueProvider(typeof(HeaderValueProviderFactory <string>))] string accessToken) { var responseMsg = this.PerformOperationAndHandleExceptions(() => { var dbContext = new TimetableContext(); using (dbContext) { var user = this.GetUserByAccessToken(accessToken, dbContext); var subject = model.Subject; var existingSubject = dbContext.Subjects.FirstOrDefault(s => s.Name == subject); var homework = new Homework { Owner = user, IsDone = model.IsDone, SubmitDate = model.SubmitDate }; user.Homeworks.Add(homework); dbContext.SaveChanges(); if (existingSubject == null) { var newSubject = new Subject { Name = subject, Owner = user }; user.Subjects.Add(newSubject); dbContext.SaveChanges(); homework.Subject = newSubject; newSubject.Homeworks.Add(homework); } else { homework.Subject = existingSubject; existingSubject.Homeworks.Add(homework); } dbContext.SaveChanges(); var responseModel = new ResponseModel() { Id = homework.Id }; var response = this.Request.CreateResponse(HttpStatusCode.OK, responseModel); return(response); } }); return(responseMsg); }
public ActionResult Delete(int id, Homework homework) { try { homeworkService.Remove(id); return(RedirectToAction("Index")); } catch { return(View()); } }
public ActionResult Edit(int id, Homework homework) { try { homeworkService.Update(homework); return(RedirectToAction("Index")); } catch { return(View()); } }
private void OnNewHomeworkSaved(Homework homework) { ScheduleDay sd = Days.Find(x => x.Date.CompareTo(homework.Date.Value) == 0); if (sd != null) { ScheduleItem si = new ScheduleItem(); si.UpdateHomework(homework); sd.ShowHomework(si); } }
public async Task Insert([FromBody] Homework homework) { try { await _homeworkRepository.Insert(homework); } catch (Exception error) { Console.WriteLine(error.Message); Console.WriteLine(error.StackTrace); } }
static void Main(string[] args) { var dataBase = new StudentSystemContext(); var course = new Courses { Parent = null, Name = "Database course", Description = "A course that all junior develepers need to pass", Materials = "Google.com"}; dataBase.Courses.Add(course); var studentOnDataBaseCourse = new Students { Name = "Bill Gates", Number = 1 }; var homeWorkForDataBases = new Homework { Content = "Introduction in SQL" }; dataBase.SaveChanges(); }
// POST api/Homeworks public IHttpActionResult Post([FromBody]Homework value) { var test = new Homework { FileUrl = value.FileUrl, TimeSent = value.TimeSent, Student = value.Student, Course = value.Course }; homeworksRepository.Add(value); data.SaveChanges(); return this.StatusCode(HttpStatusCode.Created); }
public object Create(string courseName, string fileUrl, int studentId) { //http://localhost:2583/api/homework/create?courseName=Seeded%20course&fileUrl=someurl.com&studentId=10 var homework = new Homework() { Course = this.courseData.All().First(c => c.Name == courseName), FileUrl = fileUrl, StudentIdentification = studentId, TimeSent = DateTime.Now }; this.homeworkData.Add(homework); this.homeworkData.SaveChanges(); return this.Ok(); }
public void GenerateHomeworks(StudentsDbContext data, int count) { var studentsIds = data.Students.Select(s => s.StudentId).ToList(); var coursesIds = data.Courses.Select(c => c.CourseId).ToList(); for (int i = 0; i < count; i++) { var homework = new Homework { Content = random.GetRandomString(random.GetRandomNumber(5, 50)), TimeSent = DateTime.Now.AddDays(-random.GetRandomNumber(60, 360)), StudentId = studentsIds[random.GetRandomNumber(0, studentsIds.Count - 1)], CourseId = coursesIds[random.GetRandomNumber(0, coursesIds.Count - 1)] }; data.Homework.Add(homework); } }
static void Main() { Database.SetInitializer( new MigrateDatabaseToLatestVersion<StudentContext, Configuration>()); var db = new StudentContext(); var course = new Course("c#", "New javascript web technology", new List<string> { "1", "2", "3" }); db.Courses.Add(course); var student = new Student("Venci", 9999); db.Students.Add(student); student.Courses.Add(course); var homework = new Homework() { Course = course, Content = "Good", TimeSent = DateTime.Now }; student.Homeworks.Add(homework); db.SaveChanges(); }
public static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemDbContext, Configuration>()); var db = new StudentSystemDbContext(); Console.WriteLine("Homeworks count before inserting: {0}", db.Homeworks.Count()); Console.WriteLine("Courses count before inserting: {0}", db.Courses.Count()); Console.WriteLine("Students count before inserting: {0}", db.Students.Count()); var student = new Student { FirstName = "David", LastName = "Nielsen", Age = 24, Number = 31813 }; var course = new Course { Name = "Databases", Description = "Introduction to Databases" }; var homework = new Homework { Content = "Entity Framework Code First Homework", TimeSent = DateTime.Now }; course.Homeworks.Add(homework); student.Courses.Add(course); student.Homeworks.Add(homework); db.Homeworks.Add(homework); db.Courses.Add(course); db.Students.Add(student); db.SaveChanges(); Console.WriteLine(new string('-', 50)); Console.WriteLine("Homeworks count after inserting: {0}", db.Homeworks.Count()); Console.WriteLine("Courses count after inserting: {0}", db.Courses.Count()); Console.WriteLine("Students count after inserting: {0}", db.Students.Count()); }
public IHttpActionResult Post(HomeworkRequestModel model) { var courseInDb = this.courses.GetById(model.CourseId); if (courseInDb == null) { return this.NotFound(); } var homeworkToAdd = new Homework { CourseId = model.CourseId, StudentIdentification = model.StudentIdentification, FileUrl = model.FileUrl, TimeSent = DateTime.Now }; this.homeworks.Add(homeworkToAdd); return this.Ok("Homework added successfully!"); }
public IHttpActionResult Post(HomeworkDetailsResponseModel model) { var currentUser = this.users .All() .FirstOrDefault(u => u.UserName == this.User.Identity.Name); var newHomework = new Homework { FileUrl = model.FileUrl, StudentIdentification = model.StudentIdentification, CourseId = model.CourseId, TimeSent = DateTime.Now }; this.homework.Add(newHomework); this.homework.SaveChanges(); return this.Ok(newHomework.Id); }
public IHttpActionResult Create(HomeworkModel homework) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newHomework = new Homework { Content = homework.Content }; this.data.Homeworks.Add(newHomework); this.data.SaveChanges(); homework.HomeworkId = newHomework.HomeworkId; return Ok(homework); }
public IHttpActionResult Post(HomeworkRequestModel model) { if (model == null) { return this.BadRequest("Homework is not set to un instance of object"); } var newHomework = new Homework() { FileUrl = model.FileUrl, TimeSent = DateTime.Now, StudentIdentification = model.StudentIdentification, CourseId = model.CourseId }; this.data.Homeworks.Add(newHomework); this.data.SaveChanges(); return this.Ok(newHomework.Id); }
public IHttpActionResult Create(HomeworkModel homework) { if (!this.ModelState.IsValid) { return BadRequest(ModelState); } var newHomework = new Homework() { FileUrl = homework.FileUrl, TimeSent = homework.TimeSent, CourseId = homework.CourseId, StudentId = homework.StudentId }; this.data.Homeworks.Add(newHomework); this.data.SaveChanges(); homework.HomeworkId = newHomework.HomeworkId; return Ok(homework); }
public static void CreateSampleHomeworks(StudentsContext db) { var homework1 = new Homework { Content = "Study this", Student = db.Students.FirstOrDefault(x => x.Name == "Harry Potter"), Course = db.Courses.FirstOrDefault(x => x.Name == "Alchemy") }; var homework2 = new Homework { Content = "Very easy", Student = db.Students.FirstOrDefault(x => x.Name == "Hermione"), Course = db.Courses.FirstOrDefault(x => x.Name == "Dark arts") }; db.Homeworks.Add(homework1); db.Homeworks.Add(homework2); db.SaveChanges(); }
public IHttpActionResult Create(HomeworkModel homework) { if (!this.ModelState.IsValid) { return this.BadRequest(ModelState); } var newHw = new Homework() { FileUrl = homework.FileUrl, Student = new Student() { FirstName = homework.StudentFirstName, LastName = homework.StudentLastName }, TimeSent = DateTime.Now, CourseId = homework.CourseId, }; this.data.Homeworks.Add(newHw); this.data.SaveChanges(); homework.Id = newHw.StudentIdentification; return Ok(homework); }
public void ImportHomeWorks(int numberOfHomeworks) { Console.Write("Importing Homework"); var db = new StudentSystemContext(); var studentIds = db.Students.Select(s => s.Id).ToList(); var studentsCount = studentIds.Count(); var counter = 0; while (numberOfHomeworks > 0) { var student = db.Students.Find(studentIds[RandomGenerator.GetInt(0, studentsCount - 1)]); if (student != null && student.Courses.Count != 0) { var homework = new Homework() { Content = RandomGenerator.GetString(20, 1000), TimeSent = RandomGenerator.GetDate(new DateTime(2014, RandomGenerator.GetInt(1, 12), RandomGenerator.GetInt(1, 28)), DateTime.Now) }; student.Homeworks.Add(homework); var studentCoursesIds = student.Courses.Select(c => c.Id).ToList(); db.Courses.Find(studentCoursesIds[RandomGenerator.GetInt(0, studentCoursesIds.Count - 1)]).Homeworks.Add(homework); counter++; numberOfHomeworks--; } if (counter > 100) { db.SaveChanges(); db.Dispose(); db = new StudentSystemContext(); Console.Write("."); counter = 0; } } db.SaveChanges(); Console.WriteLine(" Completed!"); }
static void AddHomeworks() { Homework firstCourseFirstHomework = new Homework() { Name = "Homework 1" }; context.Courses.First().Homeworks.Add(firstCourseFirstHomework); Homework firstCourseSecondHomework = new Homework() { Name = "Homework 2" }; context.Courses.First().Homeworks.Add(firstCourseSecondHomework); Homework secondCourseFirstHomework = new Homework() { Name = "Homework 1" }; context.Courses.OrderBy(c => c.ID).Skip(1).First().Homeworks.Add(secondCourseFirstHomework); Homework secondCourseSecondHomework = new Homework() { Name = "Homework 2" }; context.Courses.OrderBy(c => c.ID).Skip(1).First().Homeworks.Add(secondCourseSecondHomework); firstCourseFirstHomework.TimeSent = DateTime.Now.Subtract(new TimeSpan(5, 0, 0)); secondCourseSecondHomework.TimeSent = DateTime.Now.Subtract(new TimeSpan(2, 0, 0)); firstCourseSecondHomework.TimeSent = DateTime.Now.Subtract(new TimeSpan(3, 0, 0)); context.Students.First().Homeworks.Add(firstCourseFirstHomework); context.Students.First().Homeworks.Add(firstCourseSecondHomework); context.Students.OrderBy(s => s.ID).Skip(2).First().Homeworks.Add(secondCourseSecondHomework); }
static void Main() { Database.SetInitializer(new MigrateDatabaseToLatestVersion <StudentSystemContext, Configuration>()); var context = new StudentSystemContext(); var course = new Course { Name = "Database" }; var student = new Student { StudentNumber = 31150 }; student.Name = "Pesho Petrov"; course.Students.Add(student); student.Courses.Add(course); var homework = new Homework { SendDate = DateTime.Now, CourseId = 1, StudentId = 1 }; var lecture = new Material { CourseId = 1 }; student.Homeworks.Add(homework); course.Materials.Add(lecture); course.Homeworks.Add(homework); context.Courses.Add(course); context.Students.Add(student); context.Homeworks.Add(homework); context.Materials.Add(lecture); context.SaveChanges(); }
public static void ImportHomeworks() { var db = new StudentsDbContext();; Console.Write("Adding Homeworks"); var courseIds = db.Courses.Select(c => c.Id).ToList(); var studentIds = db.Students.Select(s => s.Id).ToList(); for (int i = 0; i < DefaultAddingNumber; i++) { var homeworkToAdd = new Homework() { Content = RandomGenerator.GetRandomString(1, 100), TimeSent = null, CourseId = courseIds[RandomGenerator.GetRandomNumber(0, courseIds.Count - 1)], StudentId = studentIds[RandomGenerator.GetRandomNumber(0, studentIds.Count - 1)] }; db.Homeworks.Add(homeworkToAdd); } db.SaveChanges(); }
public HttpResponseMessage AddHomework(HomeworkTemplate homework) { if (!this.ModelState.IsValid) { return this.Request.CreateResponse(HttpStatusCode.BadRequest, this.ModelState); } var newHomeworkToAdd = new Homework { FileUrl = homework.FileUrl, TimeSent = DateTime.Now }; this.data.Homeworks.Add(newHomeworkToAdd); this.data.SaveChanges(); var response = this.Request.CreateResponse<HomeworkTemplate>(HttpStatusCode.Created, homework); string uri = this.Url.Link("DefaultApi", new { id = newHomeworkToAdd.Id }); response.Headers.Location = new Uri(uri); return response; }
public static void Main(string[] args) { Database.SetInitializer(new MigrateDatabaseToLatestVersion<StudentSystemContext, Configuration>()); using(var dbContext = new StudentSystemContext()) { var student = new Student { FirstName = "Pesho", LastName = "Peshov", Number = 12345 }; var course = new Course { Name = "DSA", Description = "DSA", Materials = new string[] {"Telerik Academy", "C# Intro"} }; var homework = new Homework { Content = "Let's do it", TimeSend = DateTime.Now }; student.Courses.Add(course); student.Homework.Add(homework); course.Homework.Add(homework); course.Students.Add(student); dbContext.Students.Add(student); dbContext.SaveChanges(); Console.WriteLine("{0} is added!", dbContext.Students.FirstOrDefault().FullName); Console.WriteLine("Ready!"); Console.ReadLine(); } }
public IHttpActionResult Post([FromBody] HomeworkResponseModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var student = this.data.Students .SearchFor(s => s.StudentIdentification == model.StudentIdentification) .FirstOrDefault(); if (student == null) { return this.BadRequest(); } var course = this.data.Courses.SearchFor(c => c.Id.ToString() == model.CourseId).FirstOrDefault(); if (course == null) { return this.BadRequest(); } var homeworkToAdd = new Homework() { FileUrl = model.FileUrl, TimeSent = DateTime.Now }; course.Homeworks.Add(homeworkToAdd); student.Homeworks.Add(homeworkToAdd); this.data.SaveChanges(); return this.Ok(model); }
public void SeedHomeworks(int homeworksCount) { for (int i = 0; i < homeworksCount; i++) { int year = this.randomGenerator.GetRandomInteger(1997, 2015); int month = this.randomGenerator.GetRandomInteger(1, 12); int day = this.randomGenerator.GetRandomInteger(1, 28); var hw = new Homework() { Content = this.randomGenerator.GetRandomString(), TimeSent = new DateTime(year, month, day) }; this.db.Homeworks.Add(hw); if (this.db.ChangeTracker.Entries<Homework>().Count() > 1000) { this.ResetDb(); } } this.ResetDb(); }
public IHttpActionResult Post(HomeworkRequestModel model) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var homework = new Homework { Content = model.Content, Deadline = model.Deadline }; this.data.Homeworks.Add(homework); this.data.Homeworks.SaveChanges(); return this.Ok(homework); }
public IHttpActionResult Post(HomeworkRequestModel homework) { if (homework == null) { return this.BadRequest("Homework must be set."); } var h = new Homework { CourseId = homework.CourseId, StudentIdentification = homework.StudentId, FileUrl = homework.FileUrl, TimeSent = DateTime.Now }; this.data.Homework.Add(h); this.data.SaveChanges(); return this.Ok(h.Id); }
public IHttpActionResult Post(HomeworkRequestModel homework) { if (!this.ModelState.IsValid) { return this.BadRequest(this.ModelState); } var homeworkToPost = new Homework() { StudentIdentification = homework.StudentId, CourseId = homework.CourseId, TimeSent = homework.TimeSent }; this.db.Homeworks.Add(homeworkToPost); this.db.SaveChanges(); return this.Ok(homework); }