Пример #1
0
        public JsonResult JSaveChatFile(int nTicketID, int nChatTypeID)
        {
            if (nTicketID != 99)
            {
                string sReplyImagePath      = string.Empty;
                string sReplyImageDirectory = string.Empty;
                string sFullFilePath        = string.Empty;
                if (System.Web.HttpContext.Current.Request.Files.AllKeys.Any())
                {
                    var oFile = System.Web.HttpContext.Current.Request.Files["ChatFile"];
                    HttpPostedFileBase filebase = new HttpPostedFileWrapper(oFile);

                    sReplyImageDirectory = Path.Combine(CurrentApplicationID.ToString(), nTicketID.ToString());

                    #region Create dynamic file name based on file type
                    enumFileTypes oEnumFileTypes = (enumFileTypes)Enum.Parse(typeof(enumFileTypes), nChatTypeID.ToString());
                    switch (oEnumFileTypes)
                    {
                    case enumFileTypes.png:
                        sReplyImagePath = CommonHelper.AppendTimeStamp("fake.png");
                        break;

                    case enumFileTypes.jpg:
                        sReplyImagePath = CommonHelper.AppendTimeStamp("fake.jpg");
                        break;

                    case enumFileTypes.jpeg:
                        sReplyImagePath = CommonHelper.AppendTimeStamp("fake.jpeg");
                        break;

                    case enumFileTypes.doc:
                        sReplyImagePath = CommonHelper.AppendTimeStamp("fake.doc");
                        break;

                    case enumFileTypes.docx:
                        sReplyImagePath = CommonHelper.AppendTimeStamp("fake.docx");
                        break;

                    case enumFileTypes.pdf:
                        sReplyImagePath = CommonHelper.AppendTimeStamp("fake.pdf");
                        break;
                    }
                    #endregion

                    sFullFilePath = Path.Combine(sReplyImageDirectory, sReplyImagePath);

                    TicketChatViewModel oTicketChatViewModel = new TicketChatViewModel()
                    {
                        TICKET_ID             = nTicketID,
                        REPLY_FILE_PATH       = sFullFilePath.Replace('\\', '/'),
                        TICKET_CHAT_TYPE_ID   = nChatTypeID,
                        TICKET_PARTICIPANT_ID = CurrentUser.nUserID
                    };

                    Response oResponse = this.oITicketServices.oInsertTicketChat(oTicketChatViewModel);
                    if (oResponse.OperationResult == enumOperationResult.Success)
                    {
                        SendTicketChatPushNotification(nTicketID, string.Empty, true, oTicketChatViewModel);
                        string sUserDeviceID = oResponse.ResponseCode;

                        if (!string.IsNullOrEmpty(sFullFilePath))
                        {
                            FileAccessService oFileAccessService = new FileAccessService(CommonHelper.sGetConfigKeyValue(ConstantNames.FileAccessURL));
                            MemoryStream      target             = new MemoryStream();
                            filebase.InputStream.CopyTo(target);
                            byte[] oArrImage = target.ToArray();

                            oFileAccessService.CreateDirectory(sReplyImageDirectory);
                            oFileAccessService.WirteFileByte(Path.Combine(sReplyImageDirectory, sReplyImagePath), oArrImage);
                        }
                        this.OperationResult = enumOperationResult.Success;
                    }
                    else
                    {
                        this.OperationResult = enumOperationResult.Faild;
                    }
                }

                switch (this.OperationResult)
                {
                case enumOperationResult.Success:
                    this.OperationResultMessages = CommonResx.MessageAddSuccess;
                    break;

                case enumOperationResult.Faild:
                    this.OperationResultMessages = CommonResx.MessageAddFailed;
                    break;
                }
            }
            return(Json(
                       new
            {
                nResult = this.OperationResult,
                sResultMessages = this.OperationResultMessages
            },
                       JsonRequestBehavior.AllowGet));
        }
Пример #2
0
        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));
        }