private void BtmInvoiceImage_Click(object sender, EventArgs e) { string strInvoiceImagePathPathLoc = String.Format(@"{0}\{1}.jpg", this.setSettings.strInvoiceImagesPath, (int)this.dgvInvoices.SelectedRows[0].Cells["intNumber"].Value); if (File.Exists(strInvoiceImagePathPathLoc)) { this.btmInvoiceImage.Enabled = false; InvoiceImage frmFactor = new InvoiceImage(); frmFactor.Owner = this; frmFactor.strInvoiceImagePath = strInvoiceImagePathPathLoc; frmFactor.ShowDialog(); this.btmInvoiceImage.Enabled = true; } }
protected override async Task Execute(InvoiceImageModel parameter, ClaimsPrincipal principal, CancellationToken cancellationToken) { throw new NotSupportedException(); var requestId = parameter.RequestId; var request = await _requestRepository.GetRequest(requestId, cancellationToken); if (!principal.IsInRole(Roles.Admin) && principal.GetId() != request.UserId) { throw AppExceptions.AuthorizationException(); } byte[] buffer; if (parameter.File == null) { throw new OperationErrorException(StatusCodes.Status400BadRequest); } var fullName = parameter.File.FileName; if (parameter.File.Length > 1048576) { throw new OperationErrorException(StatusCodes.Status413PayloadTooLarge); } using (var openReadStream = parameter.File.OpenReadStream()) { buffer = new byte[parameter.File.Length]; openReadStream.Read(buffer, 0, buffer.Length); } var image = new InvoiceImage { Data = buffer, Name = fullName, RequestId = requestId }; await _invoiceImageRepository.AddInvoiceImage(image, cancellationToken); await _unitOfWork.SaveChanges(cancellationToken); }
public async Task AddInvoiceImage(InvoiceImage invoiceImage, CancellationToken cancellationToken) { await _context.InvoiceImages.AddAsync(invoiceImage, cancellationToken); }