Esempio n. 1
0
        public virtual async Task <IActionResult> GetMerchandiseReturnNoteFile(string merchandiseReturnNoteId)
        {
            var merchandiseReturnNote = await _merchandiseReturnService.GetMerchandiseReturnNote(merchandiseReturnNoteId);

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

            var merchandiseReturn = await _merchandiseReturnService.GetMerchandiseReturnById(merchandiseReturnNote.MerchandiseReturnId);

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

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

            var download = await _downloadService.GetDownloadById(merchandiseReturnNote.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 : merchandiseReturnNote.Id.ToString();
            string contentType = !String.IsNullOrWhiteSpace(download.ContentType) ? download.ContentType : "application/octet-stream";

            return(new FileContentResult(download.DownloadBinary, contentType)
            {
                FileDownloadName = fileName + download.Extension
            });
        }