public async Task <RecurringSheetEntryDTO> Get(int id)
        {
            RecurringSheetEntry entry = await this.GetEntityByIdAsync(id);

            this.EntityOwnerService.EnsureOwner(entry, this.OwnerId);

            return(this._mappingEngine.Map <RecurringSheetEntryDTO>(entry));
        }
        public async Task Delete(int id)
        {
            RecurringSheetEntry entry = await this.GetEntityByIdAsync(id);

            this.EntityOwnerService.EnsureOwner(entry, this.OwnerId);

            this._recurringSheetEntryRepository.Delete(entry);
            await this._recurringSheetEntryRepository.SaveChangesAsync();
        }
        public async Task <IActionResult> MutateOrder(int id, SortOrderMutationType mutation)
        {
            int delta = (int)mutation;

            RecurringSheetEntry entry = await this.GetEntityByIdAsync(id);

            this.EntityOwnerService.EnsureOwner(entry, this.OwnerId);
            Trace.Assert(entry.Category != null);

            entry.SortOrder += delta;

            this._recurringSheetEntryRepository.ReplaceSortOrder(this.OwnerId, entry.SortOrder, entry.SortOrder - delta);
            await this._recurringSheetEntryRepository.SaveChangesAsync();

            return(this.NoContent());
        }
        public async Task <IActionResult> Post([FromBody] RecurringSheetEntryDTO value)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            RecurringSheetEntry entry = this._mappingEngine.Map <RecurringSheetEntryDTO, RecurringSheetEntry>(value);

            this.EntityOwnerService.AssignOwner(entry, this.OwnerId);

            entry.SortOrder = this._recurringSheetEntryRepository.FindNextSortOrder(this.OwnerId);
            this._recurringSheetEntryRepository.Add(entry);
            await this._recurringSheetEntryRepository.SaveChangesAsync();

            return(this.CreatedAtRoute("RecurringSheetEntry-Get", new { id = entry.Id }, await this.Get(entry.Id)));
        }
        public async Task <IActionResult> Put(int id, [FromBody] RecurringSheetEntryDTO value)
        {
            if (!this.ModelState.IsValid)
            {
                return(this.BadRequest(this.ModelState));
            }

            RecurringSheetEntry entry = await this.GetEntityByIdAsync(id);

            this.EntityOwnerService.EnsureOwner(entry, this.OwnerId);

            this._mappingEngine.Map(value, entry);

            await this._recurringSheetEntryRepository.SaveChangesAsync();

            return(this.NoContent());
        }