public ActionResult WriteDownloadToResponse(HttpResponseBase response, Order order, OrderLine orderLine)
        {
            if (order == null || orderLine == null)
                return new ContentResult { Content = "Error", ContentType = "text/plain" };

            var errors = _rules.SelectMany(rule => rule.GetErrors(order, orderLine));
            if (errors.Any())
                return new ContentResult { Content = "Sorry the file you requested to be downloaded is unavailable. Either the order is not paid or the file has been downloaded a maximum amount of times. Contact the store owner if you believe this to be incorrect.", ContentType = "text/plain" };

            if (!_fileSystem.Exists(orderLine.DownloadFileUrl))
                return new ContentResult { Content = "File no longer exists.", ContentType = "text/plain" };

            EcommerceDownloadResult writeDownloadToResponse;
            try
            {
                writeDownloadToResponse = new EcommerceDownloadResult(_fileSystem, orderLine);
            }
            catch (Exception exception)
            {
                _logService.Insert(new Log
                    {
                        Error = new Error(exception),
                        Message = "Error downloading file"
                    });
                return new ContentResult { Content = "An error occoured, please contact the store owner.", ContentType = "text/plain" };
            }

            orderLine.NumberOfDownloads++;
            _session.Transact(session => session.Update(orderLine));
            return writeDownloadToResponse;
        }
        public ActionResult WriteDownloadToResponse(HttpResponseBase response, Order order, OrderLine orderLine)
        {
            if (order == null || orderLine == null)
            {
                return new ContentResult {
                           Content = "Error", ContentType = "text/plain"
                }
            }
            ;

            var errors = _rules.SelectMany(rule => rule.GetErrors(order, orderLine));

            if (errors.Any())
            {
                return new ContentResult {
                           Content = "Sorry the file you requested to be downloaded is unavailable. Either the order is not paid or the file has been downloaded a maximum amount of times. Contact the store owner if you believe this to be incorrect.", ContentType = "text/plain"
                }
            }
            ;

            if (!_fileSystem.Exists(orderLine.DownloadFileUrl))
            {
                return new ContentResult {
                           Content = "File no longer exists.", ContentType = "text/plain"
                }
            }
            ;

            EcommerceDownloadResult writeDownloadToResponse;

            try
            {
                writeDownloadToResponse = new EcommerceDownloadResult(_fileSystem, orderLine);
            }
            catch (Exception exception)
            {
                _logService.Insert(new Log
                {
                    Error   = new Error(exception),
                    Message = "Error downloading file"
                });
                return(new ContentResult {
                    Content = "An error occoured, please contact the store owner.", ContentType = "text/plain"
                });
            }

            orderLine.NumberOfDownloads++;
            _session.Transact(session => session.Update(orderLine));
            return(writeDownloadToResponse);
        }
    }
}