Пример #1
0
        public virtual async Task <IActionResult> GetCustomerNoteFile(string customerNoteId,
                                                                      [FromServices] ICustomerNoteService customerNoteService)
        {
            if (string.IsNullOrEmpty(customerNoteId))
            {
                return(Content("Download is not available."));
            }

            var customerNote = await customerNoteService.GetCustomerNote(customerNoteId);

            if (customerNote == null)
            {
                return(InvokeHttp404());
            }

            if (_workContext.CurrentCustomer == null || customerNote.CustomerId != _workContext.CurrentCustomer.Id)
            {
                return(Challenge());
            }

            var download = await _downloadService.GetDownloadById(customerNote.DownloadId);

            if (download == null)
            {
                return(Content("Download is not available any more."));
            }

            if (download.UseDownloadUrl)
            {
                return(new RedirectResult(download.DownloadUrl));
            }

            //binary download
            if (download.DownloadBinary == null)
            {
                return(Content("Download data is not available any more."));
            }

            //return result
            string fileName    = !String.IsNullOrWhiteSpace(download.Filename) ? download.Filename : customerNote.Id.ToString();
            string contentType = !String.IsNullOrWhiteSpace(download.ContentType) ? download.ContentType : "application/octet-stream";

            return(new FileContentResult(download.DownloadBinary, contentType)
            {
                FileDownloadName = fileName + download.Extension
            });
        }
Пример #2
0
 public GetNotesHandler(ICustomerNoteService customerNoteService,
                        IDateTimeService dateTimeService)
 {
     _customerNoteService = customerNoteService;
     _dateTimeService     = dateTimeService;
 }