public async Task <SaveResponse <IList <IDocumentHistory> > > SaveAllDocumentHistoryAsync(IList <IDocumentHistory> items) { var response = new SaveResponse <IList <IDocumentHistory> >(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = GetDocumentHistoryMergeStatement(); var dtos = items.Select(i => { var dto = new DocumentHistoryDto(); return(dto.FromModel(i)); }).ToList(); var trans = connection.BeginTransaction(); var result = await connection.ExecuteAsync(sql, dtos, trans); trans.Commit(); response.Content = items; response.Message = $@"Document history was inserted/updated successfully."; } } catch (Exception e) { var message = $@"Error saving document history."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public async Task <SaveResponse <IDocumentHistory> > SaveDocumentHistoryAsync(IDocumentHistory item) { var response = new SaveResponse <IDocumentHistory>(); try { using (var connection = ConnectionFactory.GetConnection()) { var sql = GetDocumentHistoryMergeStatement(); var dto = new DocumentHistoryDto(); var result = await connection.QuerySingleAsync <DocumentHistoryDto>(sql, dto.FromModel(item)); response.Content = result.ToModel(); response.Message = $@"Document history was inserted/updated successfully."; } } catch (Exception e) { var message = $@"Error saving document history."; LogManager.LogError(e, message); response.AddError(e); Console.WriteLine(e); } return(response); }
public static DocumentHistoryDto MapToDocumentHistoryDto(DocumentHistory documentHistory, IkarusContext _dbContext, int id) { var documentHistoryDto = new DocumentHistoryDto() { ModifiedAt = documentHistory.ModifiedAt, DocumentTitle = documentHistory.DocumentTitle, Author = documentHistory.ModifiedByUser.FirstName + " " + documentHistory.ModifiedByUser.LastName, CaseNumber = documentHistory.CaseNumber, DocumentCategoryName = documentHistory.DocumentCategoryName, DocumentDescription = documentHistory.DocumentDescription, DocumentPath = documentHistory.DocumentPath, }; var extension = Path.GetExtension(documentHistoryDto.DocumentPath).Replace(".", ""); if (extension != null) { documentHistoryDto.IconPath = _dbContext.FileType.FirstOrDefault(c => c.Extension == extension).IconPath; } return(documentHistoryDto); }