public void UpdateGoal(GoalDto goalDto) { var goal = _db.Goals.Find(goalDto.Id); _mapper.Map(goalDto, goal); _db.SaveChanges(); }
public void TestGetGoals() { var options = new DbContextOptionsBuilder <MyPracticeJournalContext>() .UseInMemoryDatabase(Guid.NewGuid().ToString()).Options; using (var db = new MyPracticeJournalContext(options)) { db.Goals.Add(new Goal { Name = "One" }); db.Goals.Add(new Goal { Name = "Two" }); db.Goals.Add(new Goal { Name = "Three" }); db.SaveChanges(); } // Use a clean instance of the context to run the test using (var context = new MyPracticeJournalContext(options)) { var service = new GoalService(_mapper, context); var result = service.GetGoal(1); Assert.IsNotNull(result); } }
public void UpdatePractice(PracticeDto practiceDto) { // remove previously saved schedules var schedules = _db.Schedules.Where(x => x.PracticeId == practiceDto.Id); _db.Schedules.RemoveRange(schedules); // remove passed schedules with zero minutes practiceDto.Schedules = practiceDto.Schedules.Where(x => x.Minutes > 0); // save practice var practice = _db.Practices.Find(practiceDto.Id); _mapper.Map(practiceDto, practice); _db.SaveChanges(); }
public void UpdateFinishedPractice(int practiceId, DateTime weekFromDate, DayOfWeek dayOfWeek) { var practiceDate = GetPracticeDate(weekFromDate, dayOfWeek); var dayIndex = (int)dayOfWeek; var schedule = _db.Schedules.First(x => x.PracticeId == practiceId && x.DayOfWeek == dayIndex); // update db var finishedPractice = _db.FinishedPractices .FirstOrDefault(x => x.PracticeId == practiceId && x.Date == practiceDate); if (finishedPractice == null) { _db.FinishedPractices.Add(new FinishedPractice { Date = practiceDate, PracticeId = practiceId, Minutes = schedule.Minutes }); } else { _db.FinishedPractices.Remove(finishedPractice); } _db.SaveChanges(); }