public void TestGetPhysicalFile() { try { FileAccessService service = new FileAccessService(); service.GetPhysicalFile(); } catch (Exception ex) { throw ex; } }
//[ExtendedAuthorize(Roles = "U")] public ActionResult Index() { var model = FileAccessService.ReadAccessList(); return(View(model)); }
public JsonResult JEditNews(NewsViewModel oNewsViewModel) { oNewsViewModel.NEWS_CONTENT = oNewsViewModel.NEWS_CONTENT.Replace(Environment.NewLine, "</br>"); Response oResponseResult = null; string sRealFileName = string.Empty; string sModifiedFileName = string.Empty; HttpPostedFileBase filebase = null; var oFile = System.Web.HttpContext.Current.Request.Files["NewsImage"]; if (oFile != null) { filebase = new HttpPostedFileWrapper(oFile); if (filebase.ContentLength > 0) { sRealFileName = filebase.FileName; sModifiedFileName = CommonHelper.AppendTimeStamp(filebase.FileName); oNewsViewModel.NEWS_IMG_FILE_PATH = Path.Combine(this.CurrentApplicationID.ToString(), "News", sModifiedFileName).Replace('\\', '/'); } } oNewsViewModel.PUBLISHED_DATE = DateTime.ParseExact(string.Format("{0} {1}", oNewsViewModel.FORMATTED_PUBLISHED_DATE, oNewsViewModel.PUBLISHED_TIME), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); oNewsViewModel.MODIFIED_BY = Convert.ToInt32(CurrentUser.nUserID); oResponseResult = this.oINewsService.oUpdateNews(oNewsViewModel); this.OperationResult = oResponseResult.OperationResult; switch (this.OperationResult) { case enumOperationResult.Success: { this.OperationResultMessages = CommonResx.MessageAddSuccess; if (oFile != null) { try { FileAccessService oFileAccessService = new FileAccessService(CommonHelper.sGetConfigKeyValue(ConstantNames.FileAccessURL)); //DirectoryPath = Saved Application ID + News Folder string sDirectoryPath = Path.Combine(this.CurrentApplicationID.ToString(), "News"); string sFullFilePath = Path.Combine(sDirectoryPath, sModifiedFileName); oFileAccessService.CreateDirectory(sDirectoryPath); MagickImage oMagickImage = new MagickImage(filebase.InputStream); oMagickImage.Format = MagickFormat.Png; oMagickImage.Resize(Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageWidth)), Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageHeight))); oFileAccessService.WirteFileByte(sFullFilePath, oMagickImage.ToByteArray()); } catch (Exception ex) { this.OperationResultMessages = ex.Message.ToString(); } } this.OperationResult = enumOperationResult.Success; } break; case enumOperationResult.Faild: this.OperationResultMessages = CommonResx.MessageAddFailed; break; } return(Json( new { nResult = this.OperationResult, sResultMessages = this.OperationResultMessages }, JsonRequestBehavior.AllowGet)); }
public JsonResult JSaveNews(NewsViewModel oNewsViewModel) { oNewsViewModel.NEWS_CONTENT = oNewsViewModel.NEWS_CONTENT.Replace(Environment.NewLine, "</br>"); Response oResponseResult = null; var oFile = System.Web.HttpContext.Current.Request.Files["NewsImage"]; HttpPostedFileBase filebase = new HttpPostedFileWrapper(oFile); string sRealFileName = filebase.FileName; string sModifiedFileName = CommonHelper.AppendTimeStamp(filebase.FileName); oNewsViewModel.APPLICATION_ID = this.CurrentApplicationID; oNewsViewModel.LANGUAGE_ID = Convert.ToInt32(this.CurrentApplicationLanguage); oNewsViewModel.PUBLISHED_DATE = DateTime.ParseExact(string.Format("{0} {1}", oNewsViewModel.FORMATTED_PUBLISHED_DATE, oNewsViewModel.PUBLISHED_TIME), "dd/MM/yyyy HH:mm", CultureInfo.InvariantCulture); oNewsViewModel.NEWS_IMG_FILE_PATH = Path.Combine(CurrentApplicationID.ToString(), "News", sModifiedFileName).Replace('\\', '/'); oNewsViewModel.CREATED_BY = Convert.ToInt32(CurrentUser.nUserID); oResponseResult = this.oINewsService.oInsertNews(oNewsViewModel); this.OperationResult = oResponseResult.OperationResult; switch (this.OperationResult) { case enumOperationResult.Success: { this.OperationResultMessages = CommonResx.MessageAddSuccess; try { FileAccessService oFileAccessService = new FileAccessService(CommonHelper.sGetConfigKeyValue(ConstantNames.FileAccessURL)); //DirectoryPath = Application ID + News Folder string sDirectoryPath = Path.Combine(this.CurrentApplicationID.ToString(), "News"); string sFullFilePath = Path.Combine(sDirectoryPath, sModifiedFileName); oFileAccessService.CreateDirectory(sDirectoryPath); MagickImage oMagickImage = new MagickImage(filebase.InputStream); oMagickImage.Format = MagickFormat.Jpg; oMagickImage.Resize(Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageWidth)), Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageHeight))); oFileAccessService.WirteFileByte(sFullFilePath, oMagickImage.ToByteArray()); this.OperationResult = enumOperationResult.Success; } catch (Exception ex) { this.OperationResultMessages = ex.Message.ToString(); //TODO :: Log this Elmah.ErrorLog.GetDefault(System.Web.HttpContext.Current).Log(new Elmah.Error(ex)); } if (oNewsViewModel.IS_NOTIFY_USER && oNewsViewModel.IS_ACTIVE) { string sNewsTitle = oNewsViewModel.NEWS_TITLE; string sNewsDesc = oNewsViewModel.NEWS_CONTENT.Substring(0, Math.Min(oNewsViewModel.NEWS_CONTENT.Length, 150)) + "..."; #region Send Push Notification var lstApplicationUsers = this.oIUserServices.lGetApplicationUsers(this.CurrentApplicationID, Convert.ToInt32(enumUserType.MobileUser).ToString()); if (lstApplicationUsers.Count > 0) { string sDeviceIDS = string.Join(",", lstApplicationUsers.Where(o => Convert.ToInt32(o.PREFERED_LANGUAGE_ID) == (int)this.CurrentApplicationLanguage) .Where(o => o.DEVICE_ID != null) .Where(o => o.DEVICE_ID != string.Empty) .Where(o => o.IS_ACTIVE == true) .Where(o => o.IS_BLOCKED == false) .Select(o => o.DEVICE_ID.ToString())); string sMobileNumbers = string.Join(",", lstApplicationUsers.Where(o => Convert.ToInt32(o.PREFERED_LANGUAGE_ID) == (int)this.CurrentApplicationLanguage) .Where(o => o.DEVICE_ID != null) .Where(o => o.DEVICE_ID != string.Empty) .Where(o => o.IS_ACTIVE == true) .Where(o => o.IS_BLOCKED == false) .Select(o => o.PHONE_NUMBER.ToString())); PushNotification oPushNotification = new PushNotification(); oPushNotification.NotificationType = enmNotificationType.News; oPushNotification.sHeadings = sNewsTitle; oPushNotification.sContent = sNewsDesc; oPushNotification.enmLanguage = this.CurrentApplicationLanguage; oPushNotification.sRecordID = oResponseResult.ResponseCode; oPushNotification.sDeviceID = sDeviceIDS; oPushNotification.sOneSignalAppID = this.CurrentApplicationOneSignalID; oPushNotification.sOneSignalAuthKey = this.CurrentApplicationOneSignalAuthKey; oPushNotification.SendPushNotification(); NotificationLogViewModel oNotificationLogViewModel = new NotificationLogViewModel(); oNotificationLogViewModel.APPLICATION_ID = this.CurrentApplicationID; oNotificationLogViewModel.NOTIFICATION_TYPE = "news"; oNotificationLogViewModel.REQUEST_JSON = oPushNotification.sRequestJSON; oNotificationLogViewModel.RESPONSE_MESSAGE = oPushNotification.sResponseResult; oNotificationLogViewModel.MOBILE_NUMBERS = sMobileNumbers; oNotificationLogViewModel.IS_SENT_NOTIFICATION = oPushNotification.bIsSentNotification; oICommonServices.oInsertNotificationLog(oNotificationLogViewModel); } #endregion } } break; case enumOperationResult.Faild: this.OperationResultMessages = CommonResx.MessageAddFailed; break; } return(Json( new { nResult = this.OperationResult, sResultMessages = this.OperationResultMessages }, JsonRequestBehavior.AllowGet)); }