public async Task InsertOrRemoveCheckListItem( string contextUserEmail, PersonCheckListItemDto dto, long personId) { await _userService.ThrowIfNotInRole(contextUserEmail, UserRoleEnum.Editor); if (dto == null) { throw new ArgumentNullException(nameof(PersonCheckListItemDto)); } var model = await _context.PersonCheckLists.FirstOrDefaultAsync( pcl => pcl.PersonCheckListItemId == dto.Id && pcl.PersonId == personId); if (model == null) { model = new PersonCheckList { PersonId = personId, PersonCheckListItemId = dto.Id, Note = dto.Note, Date = dto.Date ?? DateTimeOffset.UtcNow }; _context.PersonCheckLists.Add(model); } else { _context.PersonCheckLists.Remove(model); } await _context.SaveChangesAsync(); }
public async Task <IActionResult> CheckListItem(long id, [FromBody] PersonCheckListItemDto dto) { var trans = await _personService.BeginTransactionAsync(); try { await _personService.InsertOrRemoveCheckListItem(ContextUserEmail, dto, id); trans.Commit(); var data = await _personService.Find(x => x.Id == id); return(Ok(data)); } catch (Exception e) { trans.Rollback(); return(Exception(e)); } }