public ActionResult AddOrUpdate(PupilModel model) { if (!ModelState.IsValid) { return(View(model)); } var isCreated = model.Id == Guid.Empty; var pupil = new Pupils(); if (!isCreated) { pupil = PupilRepository.GetById(model.Id); } pupil.BirthdayDate = model.BirthdayDate; pupil.Classrooms = ClassroomRepository.GetById(pupil.Classroom_Id); pupil.Classroom_Id = model.ClassroomId; pupil.FirstName = model.FirstName; pupil.LastName = model.LastName; pupil.Level_Id = model.LevelId; pupil.Levels = LevelRepository.GetById(pupil.Level_Id); pupil.Sex = (short)model.Sex; pupil.State = model.State; pupil.Tutor_Id = model.TutorId; pupil.Tutors = TutorRepository.GetById(pupil.Tutor_Id); if (isCreated) { PupilRepository.Add(pupil); } PupilRepository.Save(); return(Redirect(Url.Action("Get", "Pupil", new { id = pupil.Id }))); }
public void Should_Update_Level_In_Db(int id) { var fakeContext = new FakeContext("UpdateLevel"); fakeContext.FillWith <Level>(); using (var context = new MainContext(fakeContext.FakeOptions)) { var repository = new LevelRepository(context); var currentLevel = repository.GetById(id); currentLevel.Name = "123abc"; repository.Update(currentLevel); Assert.Equal("123abc", repository.GetById(id).Name); repository.Dispose(); } }
public HttpResponseMessage Edit([FromBody] LevelModel levelModel) { Level level = levelRepository.GetById(levelModel.Id); level.UpdateLevelDifficult(levelModel.PictureAmount, levelModel.Duration, levelModel.Multiplier); if (level.Validate()) { return(ResponderOK(levelRepository.EditLevel(level))); } return(ResponderErro(level.Messages)); }
public void Should_Return_Right_Level_When_Find_By_Id_In_Db(int id) { var fakeContext = new FakeContext("LevelById"); fakeContext.FillWith <Level>(); using (var context = new MainContext(fakeContext.FakeOptions)) { var expected = fakeContext.GetFakeData <Level>().Find(x => x.Id == id); var repository = new LevelRepository(context); var actual = repository.GetById(id); Assert.Equal(expected, actual, new LevelIdComparer()); repository.Dispose(); } }
public void Should_Save_New_Level_To_Db() { var fakeContext = new FakeContext("AddNewLevel"); var fakeLevel = new Level(); fakeLevel.Name = "Desenvolvimento"; fakeLevel.Id = 4; using (var context = new MainContext(fakeContext.FakeOptions)) { var repository = new LevelRepository(context); repository.Create(fakeLevel); var createdLevel = repository.GetById(4); Assert.NotEqual(0, fakeLevel.Id); Assert.Equal("Desenvolvimento", createdLevel.Name); Assert.Equal(4, createdLevel.Id); repository.Dispose(); } }
public Level GetById(int Id) { LevelRepository repo = new LevelRepository(); return(repo.GetById(Id)); }