public JsonNetResult AddEntry(int recordId, TimeRecordEntry entry) { var timeRecord = _timeRecordRepository.GetNullableById(recordId); Check.Require(timeRecord != null, "Invalid time record identifier"); Check.Require(_timeRecordBLL.HasAccess(CurrentUser, timeRecord), "Current user does not have access to this record"); timeRecord.AddEntry(entry);//Add the entry to the time record Check.Require(entry.IsValid(), "Entry is not valid"); _timeRecordRepository.EnsurePersistent(timeRecord); _timeRecordRepository.DbContext.CommitTransaction(); var modificationResult = new TimeRecordEntryModificationDto(entry.Id, entry.Hours); return new JsonNetResult(modificationResult); }
public JsonNetResult EditEntry(int entryId, TimeRecordEntry entry) { var entryRepository = Repository.OfType<TimeRecordEntry>(); var entryToUpdate = entryRepository.GetNullableById(entryId); Check.Require(entryToUpdate != null, "Entry not found"); var originalHours = entryToUpdate.Hours; TransferValuesTo(entryToUpdate, entry); Check.Require(entryToUpdate.IsValid(), "Entry is not valid"); entryRepository.EnsurePersistent(entryToUpdate); var modificationResult = new TimeRecordEntryModificationDto(entryToUpdate.Id, entryToUpdate.Hours - originalHours); return new JsonNetResult(modificationResult); }
public JsonNetResult RemoveEntry(int entryId) { var entryRepository = Repository.OfType<TimeRecordEntry>(); var entry = entryRepository.GetById(entryId); entryRepository.Remove(entry); var modificationResult = new TimeRecordEntryModificationDto(entry.Id, -entry.Hours); return new JsonNetResult(modificationResult); }