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 InsertId Put(int id, [FromBody] SheetEntryDTO value) { SheetEntry entry = this._sheetEntryRepository.FindById(id).EnsureNotNull(); this.EnsureCorrectSheet(entry); this.EntityOwnerService.EnsureOwner(entry.Sheet, this.OwnerId); AutoMapper.Mapper.Map(value, entry); entry.UpdateTimestamp = DateTime.Now; entry.Sheet.UpdateTimestamp = DateTime.Now; this._sheetEntryRepository.SaveChanges(); return(entry.Id); }
public InsertId Post(int sheetYear, int sheetMonth, [FromBody] SheetEntryDTO value) { Sheet targetSheet = this._sheetRetrievalService.GetBySubject(sheetMonth, sheetYear, this.OwnerId).EnsureNotNull(); this.EntityOwnerService.EnsureOwner(targetSheet, this.OwnerId); SheetEntry entry = AutoMapper.Mapper.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); this._sheetEntryRepository.SaveChanges(); return(entry.Id); }
public async Task <IActionResult> Put(int id, [FromBody] SheetEntryDTO value) { SheetEntry entry = await this.GetByIdAsync(id); if (!this.ModelState.IsValid) { return(this.BadRequest(this.ModelState)); } this._mappingEngine.Map(value, entry); entry.UpdateTimestamp = DateTime.Now; entry.Sheet.UpdateTimestamp = DateTime.Now; await this._sheetEntryRepository.SaveChangesAsync(); await this._sheetLastVisitedMarkerService.AddOrUpdateImmediateAsync(entry.Sheet, this.User.Identity.GetUserId()); return(this.NoContent()); }