public async Task <int> CreateDocument(DocumentContentsDto d, int authorId, int userActingOnBehalfId = -1) { var author = await userRepo.GetById(authorId); if (author == null) { throw new ArgumentException("Document Author not found", nameof(d)); } Document document; if (userActingOnBehalfId != -1) { var actingUser = await userRepo.GetById(userActingOnBehalfId); if (actingUser == null) { throw new ArgumentException("Acting User not found", nameof(userActingOnBehalfId)); } document = new Document(d.Title, d.Body, author, d.Message, actingUser); } else { document = new Document(d.Title, d.Body, author, d.Message); } await docRepo.Create(document); return(document.Id); }
public async Task <bool> EditDocument(DocumentContentsDto d, int documentId, int editorId) { try { var editor = await userRepo.GetById(editorId); var document = await docRepo.GetById(documentId); document.Edit(editor, d.Title, d.Body, d.Message); await docRepo.Update(document); } catch (Exception) { return(false); } return(true); }
public async Task <int> CreateDocument(DocumentContentsDto d, int authorId) { return(await CreateDocument(d, authorId, -1)); }