public async Task <IActionResult> Post(int sheetYear, int sheetMonth, [FromBody] SheetEntryDTO value) { Sheet targetSheet = await this._sheetRetrievalService.GetBySubjectAsync(sheetMonth, sheetYear, this.OwnerId).EnsureNotNull(); this.EntityOwnerService.EnsureOwner(targetSheet, this.OwnerId); if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } SheetEntry entry = this._mappingEngine.Map <SheetEntryDTO, SheetEntry>(value); entry.Sheet = targetSheet; entry.CreateTimestamp = DateTime.Now; entry.UpdateTimestamp = entry.CreateTimestamp; entry.Sheet.UpdateTimestamp = DateTime.Now; entry.SortOrder = targetSheet.Entries.Max(x => (int?)x.SortOrder).GetValueOrDefault() + 1; this._sheetEntryRepository.Add(entry); await this._sheetEntryRepository.SaveChangesAsync(); await this._sheetLastVisitedMarkerService.AddOrUpdateImmediateAsync(targetSheet, this.User.Identity.GetUserId()); return(this.CreatedAtRoute("SheetEntry-Get", new { id = entry.Id }, await this.Get(entry.Id, sheetYear, sheetMonth))); }
public SheetDTO GetBySubject(int month, int year) { Sheet theSheet = this._sheetRetrievalService.GetBySubject(month, year, this.OwnerId); var dto = AutoMapper.Mapper.Map <Sheet, SheetDTO>(theSheet); Array.Sort(dto.Entries, SortOrderComparer <SheetEntry> .Instance); return(dto); }
public async Task <SheetDTO> GetBySubject(int month, int year) { Sheet theSheet = await this._sheetRetrievalService.GetBySubjectAsync(month, year, this.OwnerId); PreviousSheetVisitMarker marker = await this._sheetLastVisitedMarkerService.GetAndUpdateAsync(theSheet, this.User.Identity.GetUserId()); SheetDTO dto = this._mappingEngine.Map <Sheet, SheetDTO>(theSheet, opts => opts.SetPreviousSheetVisitMarker(marker)); Array.Sort(dto.Entries, SortOrderComparer <SheetEntry> .Instance); return(dto); }
public SheetDTO GetById(int id) { Sheet sheet = this._sheetRepository.FindByIdInclude(id) .Include(x => x.Entries) .FirstOrDefault(); sheet.EnsureNotNull(); this.EntityOwnerService.EnsureOwner(sheet, this.OwnerId); var dto = AutoMapper.Mapper.Map <Sheet, SheetDTO>(sheet); Array.Sort(dto.Entries, SortOrderComparer <SheetEntry> .Instance); return(dto); }
public async Task <SheetEntryDTO> Get(int id, int sheetYear, int sheetMonth) { Sheet targetSheet = await this._sheetRetrievalService.GetBySubjectAsync(sheetMonth, sheetYear, this.OwnerId).EnsureNotNull(); this.EntityOwnerService.EnsureOwner(targetSheet, this.OwnerId); SheetEntry entry = await this._sheetEntryRepository.FindByIdAsync(id).EnsureNotNull(); this.EnsureCorrectSheet(entry); PreviousSheetVisitMarker marker = await this._sheetLastVisitedMarkerService.GetAndUpdateAsync(targetSheet, this.User.Identity.GetUserId()); return(this._mappingEngine.Map <SheetEntry, SheetEntryDTO>(entry, opts => opts.SetPreviousSheetVisitMarker(marker))); }
public async Task <SheetDTO> GetById(int id) { Sheet sheet = await this._sheetRepository.FindByIdInclude(id).FirstOrDefaultAsync().EnsureNotNull(); sheet.Entries = new List <Models.Domain.SheetEntry>(this._sheetRepository.GetOfSheet(sheet)); PreviousSheetVisitMarker marker = await this._sheetLastVisitedMarkerService.GetAndUpdateAsync(sheet, this.User.Identity.GetUserId()); this.EntityOwnerService.EnsureOwner(sheet, this.OwnerId); SheetDTO dto = this._mappingEngine.Map <Sheet, SheetDTO>(sheet, m => m.SetPreviousSheetVisitMarker(marker)); Array.Sort(dto.Entries, SortOrderComparer <SheetEntry> .Instance); return(dto); }