public async Task <ExpenseListViewModel> Upload(IFormFile fileForm, string fileName, int expenseId) { var viewModel = new ExpenseListViewModel(); try { var expense = await _expenseRepository.Get(expenseId); if (fileForm != null && fileForm.Length > 0) { using (var ms = new MemoryStream()) { fileForm.CopyTo(ms); var fileRawData = ms.ToArray(); var salesDocument = new SalesDocumentForm() { ExpenseId = expenseId, Name = fileName, FileRawData = fileRawData }; await _salesDocumentRepository.Create(salesDocument); } } viewModel.VirtualAccountId = expense.VirtualAccountId; viewModel.Expenses = await _expenseRepository.GetAll(expense.VirtualAccountId); } catch (Exception e) { viewModel.Error = new GackoError(e); } return(viewModel); }
public async void IsVirtualAccountCreatePossible() { var form = new SalesDocumentForm() { Name = "Test", ExpenseId = 1 }; var result = await _salesDocumentService.Create(form); Assert.NotEqual(0, result); }
public async Task <int> Create(SalesDocumentForm form) { try { var newEntity = _mapper.Map <DaoSalesDocument>(form); var createdEntry = _context.SalesDocuments.Add(newEntity); await _context.SaveChangesAsync(); return(createdEntry.Entity.Id); } catch (Exception e) { throw new RepositoryException(typeof(DaoSalesDocument).Name, eRepositoryExceptionType.Create); } }
public async Task <int> Update(SalesDocumentForm form) { try { var updateEntity = this._mapper.Map <DaoSalesDocument>(form); var updated = await _context.SalesDocuments.FirstOrDefaultAsync(_ => _.Id == updateEntity.Id); _context.Entry(updated).CurrentValues.SetValues(updateEntity); await _context.SaveChangesAsync(); return(updated.Id); } catch (Exception e) { throw new RepositoryException(typeof(DaoSalesDocument).Name, eRepositoryExceptionType.Update); } }
public Task <int> Update(SalesDocumentForm form) { return(_salesDocumentRepository.Update(form)); }