public void UpdatePeriod(int id, Period period) { if (DateTime.Compare(period.PickStartDateTime, period.PickEndDateTime) >= 0) { throw new Exception($"Registration start date must be after its end date."); } if (DateTime.Compare(period.ReportStartDateTime, period.ReportEndDateTime) >= 0) { throw new Exception($"Play start date must be after its end date."); } var entity = _prdRepo.GetSingle(prd => prd.GameId == id && prd.Id == period.Id); if (entity == null) { throw new Exception($"Cannot find game for Id {id} or period Id {period.Id}"); } var hasChanged = !period.CompareTo(entity, "GameId"); if (hasChanged) { period.CopyTo(entity, "GameId"); _prdRepo.Update(entity); } }