Example #1
0
        public ActionResult PreviewAttachment()
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Preview Attachment").ToInputLogString());

            try
            {
                AttachmentEntity selectedAttach = (AttachmentEntity)TempData["FILE_DOWNLOAD"];
                TempData["FILE_DOWNLOAD"] = selectedAttach; // keep object

                _commonFacade = new CommonFacade();
                string documentFolder = selectedAttach.DocumentLevel == Constants.DocumentLevel.Customer ?
                                        _commonFacade.GetCSMDocumentFolder() : _commonFacade.GetSrDocumentFolder();
                string pathFile  = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", documentFolder, selectedAttach.Url);
                byte[] byteArray = System.IO.File.ReadAllBytes(pathFile);

                return(File(byteArray, selectedAttach.ContentType, selectedAttach.Filename));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Preview Attachment").Add("Error Message", ex.Message).ToFailLogString());
                return(Error(new HandleErrorInfo(ex, this.ControllerContext.RouteData.Values["controller"].ToString(),
                                                 this.ControllerContext.RouteData.Values["action"].ToString())));
            }
        }
Example #2
0
        public JsonResult LoadFileAttachment()
        {
            Logger.Info(_logMsg.Clear().SetPrefixMsg("Load FileAttachment").ToInputLogString());

            try
            {
                if (TempData["FILE_DOWNLOAD"] != null)
                {
                    AttachmentEntity selectedAttach = (AttachmentEntity)TempData["FILE_DOWNLOAD"];
                    TempData["FILE_DOWNLOAD"] = selectedAttach;

                    _commonFacade = new CommonFacade();
                    string documentFolder = selectedAttach.DocumentLevel == Constants.DocumentLevel.Customer ?
                                            _commonFacade.GetCSMDocumentFolder() : _commonFacade.GetSrDocumentFolder();
                    string pathFile = string.Format(CultureInfo.InvariantCulture, "{0}\\{1}", documentFolder, selectedAttach.Url);

                    if (!System.IO.File.Exists(pathFile))
                    {
                        return(Json(new
                        {
                            Valid = false,
                            Error = "ไม่พบไฟล์ที่ต้องการ Download",
                            Errors = string.Empty
                        }));
                    }
                }

                return(Json(new
                {
                    Valid = true
                }));
            }
            catch (Exception ex)
            {
                Logger.Error("Exception occur:\n", ex);
                Logger.Info(_logMsg.Clear().SetPrefixMsg("Load FileAttachment").Add("Error Message", ex.Message).ToFailLogString());
                return(Json(new
                {
                    Valid = false,
                    Error = Resource.Error_System,
                    Errors = string.Empty
                }));
            }
        }