public Exercise AddExercise(Guid id, Exercise exercise) { Homework homework = homeworksRepository.Get(id); if (homework == null) { throw new ArgumentException("Invalid guid"); } homework.Exercises.Add(exercise); homeworksRepository.Update(homework); homeworksRepository.Save(); return(exercise); }
public Exercise AddExercise(Guid id, Exercise exercise) { Homework homework = homeworksRepository.Get(id); if (homework == null) { //TODO: ¿Se pueden manejar mejor los mensaje de las excepciones? throw new ArgumentException("Invalid guid"); } homework.Exercises.Add(exercise); homeworksRepository.Update(homework); //nunca olvidar esto ! homeworksRepository.Save(); return(exercise); }
public Homework Update(Guid id, Homework homework) { // 3 Homework homeworkToUpdate = homeworksRepository.Get(id); if (homeworkToUpdate == null) { throw new ArgumentException("Invalid guid"); } homeworkToUpdate.Description = homework.Description; homeworkToUpdate.DueDate = homework.DueDate; homeworksRepository.Update(homeworkToUpdate); homeworksRepository.Save(); return(homeworkToUpdate); }
// PUT api/Homeworks/5 public IHttpActionResult Put(int id, [FromBody] Homework value) { var homeworkToUpdate = homeworksRepository.All().Where(x => x.Id == id).FirstOrDefault(); if (homeworkToUpdate == null) { return(this.BadRequest("No such homework")); } if (value.Course != null) { homeworkToUpdate.Course = value.Course; } if (value.Student != null) { homeworkToUpdate.Student = value.Student; } if (value.FileUrl != null) { homeworkToUpdate.FileUrl = value.FileUrl; } if (value.TimeSent != DateTime.MinValue) { homeworkToUpdate.TimeSent = value.TimeSent; } if (value.StudentIdentification != 0) { homeworkToUpdate.StudentIdentification = value.StudentIdentification; } homeworksRepository.Update(homeworkToUpdate); data.SaveChanges(); return(this.ResponseMessage(new HttpResponseMessage(HttpStatusCode.Found))); }
public void Update() { // arrange var fixture = new Fixture(); var HomeworkExistUser = 490; var updatedhomework = fixture.Build <Homework>().Create(); updatedhomework.TopicId = 1; updatedhomework.Id = HomeworkExistUser; // act _repository.Update(updatedhomework); // assert var homework = _repository.Get(HomeworkExistUser); Assert.NotNull(homework); Assert.AreEqual(updatedhomework.TopicId, homework.TopicId); Assert.AreEqual(updatedhomework.Name, homework.Name); Assert.AreEqual(updatedhomework.Link, homework.Link); Assert.AreEqual(updatedhomework.Grade, homework.Grade); }
public async Task Update() { var fixture = new Fixture(); var newhomework = fixture.Create <Homework>(); var homeworkId = await _repository.Add(newhomework); var updatedhomework = fixture.Create <Homework>(); updatedhomework.Id = homeworkId; // act await _repository.Update(updatedhomework); // assert var homework = await _repository.Get(homeworkId); Assert.NotNull(homework); Assert.Equal(updatedhomework.Title, homework.Title); Assert.Equal(updatedhomework.Description, homework.Description); Assert.Equal(updatedhomework.Link, homework.Link); }
public bool Update(Guid id, Homework updatedHomework) { return(homeworks.Update(id, updatedHomework)); }