Пример #1
0
        /// <summary>
        /// Insert Ticket Chat
        /// </summary>
        /// <param name="oTicketChatViewModel"></param>
        /// <returns></returns>
        public Response oInsertTicketChat(TicketChatViewModel oTicketChatViewModel)
        {
            #region ": Insert Sp Result:"

            Response oResponse = new Response();

            try
            {
                List <DbParameter> arrParameters = new List <DbParameter>();

                arrParameters.Add(CustomDbParameter.BuildParameter("Pin_TicketId", SqlDbType.Int, oTicketChatViewModel.TICKET_ID, ParameterDirection.Input));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pin_Ticket_Participant_Id", SqlDbType.Int, oTicketChatViewModel.TICKET_PARTICIPANT_ID, ParameterDirection.Input));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pin_ReplyMessage", SqlDbType.NVarChar, oTicketChatViewModel.REPLY_MESSAGE, 4000, ParameterDirection.Input));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pin_ReplyFilePath", SqlDbType.VarChar, oTicketChatViewModel.REPLY_FILE_PATH, 500, ParameterDirection.Input));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pin_TicketChatTypeId", SqlDbType.Int, oTicketChatViewModel.TICKET_CHAT_TYPE_ID, ParameterDirection.Input));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pout_DeviceID", SqlDbType.VarChar, ParameterDirection.Output, 4000));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pout_ChatID", SqlDbType.Int, ParameterDirection.Output));
                arrParameters.Add(CustomDbParameter.BuildParameter("Pout_Error", SqlDbType.Int, ParameterDirection.Output));


                this.ExecuteStoredProcedureCommand("InsertTicketChat", arrParameters.ToArray());
                oResponse.nOperationResult = Convert.ToInt32(arrParameters[7].Value.ToString());


                if (oResponse.nOperationResult == 1)
                {
                    //User Device ID
                    oResponse.ResponseCode    = arrParameters[5].Value.ToString();
                    oResponse.OperationResult = enumOperationResult.Success;
                    oResponse.ResponseID      = arrParameters[6].Value.ToString();
                }

                //oResponse.OperationResult = (enumOperationResult)Enum.Parse(typeof(enumOperationResult), arrParameters[5].Value.ToString());
            }
            catch (Exception Ex)
            {
                oResponse.OperationResult = enumOperationResult.Faild;
                //TODO : Log Error Message
                oResponse.OperationResultMessage = Ex.Message.ToString();
            }

            return(oResponse);

            #endregion
        }
Пример #2
0
        public JsonResult JSendChat(int nTicketID, string sChatMessage)
        {
            TicketChatViewModel oTicketChatViewModel = new TicketChatViewModel()
            {
                TICKET_ID             = nTicketID,
                REPLY_MESSAGE         = sChatMessage,
                TICKET_CHAT_TYPE_ID   = 1,
                TICKET_PARTICIPANT_ID = CurrentUser.nUserID
            };

            Response oResponse = this.oITicketServices.oInsertTicketChat(oTicketChatViewModel);
            string   sContent  = oTicketChatViewModel.REPLY_MESSAGE.Length > 25 ? oTicketChatViewModel.REPLY_MESSAGE.Substring(0, 100) + "..." : oTicketChatViewModel.REPLY_MESSAGE;

            SendTicketChatPushNotification(nTicketID, sContent, false, oTicketChatViewModel);

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

            case enumOperationResult.Faild:
                this.OperationResultMessages = CommonResx.MessageAddFailed;
                break;
            }

            return(Json(
                       new
            {
                nResult = this.OperationResult,
                sResultMessages = this.OperationResultMessages
            },
                       JsonRequestBehavior.AllowGet));
        }
        public HttpResponseMessage PostTicketChat(TakamulTicketChat oTakamulTicketChat, int nLanguageID)
        {
            ApiResponse oApiResponse   = new ApiResponse();
            string      sResultMessage = string.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    string sReplyImagePath      = string.Empty;
                    string sReplyImageDirectory = string.Empty;
                    string sFullFilePath        = string.Empty;
                    if (!string.IsNullOrEmpty(oTakamulTicketChat.Base64ReplyImage))
                    {
                        sReplyImageDirectory = Path.Combine(oTakamulTicketChat.ApplicationID.ToString(), oTakamulTicketChat.TicketID.ToString());
                        enumFileTypes oEnumFileTypes = (enumFileTypes)Enum.Parse(typeof(enumFileTypes), oTakamulTicketChat.TicketChatTypeID.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;
                        }
                        sFullFilePath = Path.Combine(sReplyImageDirectory, sReplyImagePath);
                    }

                    TicketChatViewModel oTicketChatViewModel = new TicketChatViewModel()
                    {
                        TICKET_ID             = oTakamulTicketChat.TicketID,
                        REPLY_MESSAGE         = oTakamulTicketChat.ReplyMessage,
                        REPLY_FILE_PATH       = sFullFilePath.Replace('\\', '/'),
                        TICKET_CHAT_TYPE_ID   = oTakamulTicketChat.TicketChatTypeID,
                        TICKET_PARTICIPANT_ID = oTakamulTicketChat.UserID
                    };

                    Response oResponse = this.oITicketServices.oInsertTicketChat(oTicketChatViewModel);
                    if (oResponse.nOperationResult == 1)
                    {
                        if (!string.IsNullOrEmpty(sFullFilePath) && !string.IsNullOrEmpty(oTakamulTicketChat.Base64ReplyImage))
                        {
                            FileAccessService oFileAccessService = new FileAccessService(CommonHelper.sGetConfigKeyValue(ConstantNames.FileAccessURL));
                            Byte[]            oArrImage          = Convert.FromBase64String(oTakamulTicketChat.Base64ReplyImage);
                            oFileAccessService.CreateDirectory(sReplyImageDirectory);

                            enumFileTypes oEnumFileTypes = (enumFileTypes)Enum.Parse(typeof(enumFileTypes), oTakamulTicketChat.TicketChatTypeID.ToString());
                            if (oEnumFileTypes == enumFileTypes.jpeg || oEnumFileTypes == enumFileTypes.jpg ||
                                oEnumFileTypes == enumFileTypes.png)
                            {
                                MagickImage oMagickImage = new MagickImage(oArrImage);
                                oMagickImage.Format = MagickFormat.Jpeg;
                                oMagickImage.Resize(Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageWidth)), Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageHeight)));
                                oFileAccessService.WirteFileByte(Path.Combine(sReplyImageDirectory, sReplyImagePath), oMagickImage.ToByteArray());
                            }
                            else
                            {
                                oFileAccessService.WirteFileByte(Path.Combine(sReplyImageDirectory, sReplyImagePath), oArrImage);
                            }
                        }
                        oApiResponse.OperationResult        = 1;
                        oApiResponse.OperationResultMessage = "Success.";
                    }
                    else
                    {
                        switch (oResponse.nOperationResult)
                        {
                        case -5:
                            oApiResponse.OperationResult = -5;
                            sResultMessage = nLanguageID == 2 ? "The Application is expired." : "انتهت صلاحية التطبيق.";
                            oApiResponse.OperationResultMessage = sResultMessage;
                            break;

                        case -6:
                            oApiResponse.OperationResult = -6;
                            sResultMessage = nLanguageID == 2 ? "OTP is not verified." : "لم يتم التحقق من رمز التفعيل.";
                            oApiResponse.OperationResultMessage = sResultMessage;
                            break;

                        case -7:
                            oApiResponse.OperationResult = -7;
                            sResultMessage = nLanguageID == 2 ? "User is blocked." : "المستخدم محضور.";
                            oApiResponse.OperationResultMessage = sResultMessage;
                            break;

                        case -8:
                            oApiResponse.OperationResult = -8;
                            sResultMessage = nLanguageID == 2 ? "Ticket submission is restricted." : "المواضيع الجديدة مقيدة.";
                            oApiResponse.OperationResultMessage = sResultMessage;
                            break;

                        case -9:
                            oApiResponse.OperationResult = -9;
                            sResultMessage = nLanguageID == 2 ? "Ticket Submission Interval Days reached." : "وصلت للفترة الزمنية لتقديم للمواضيع.";
                            oApiResponse.OperationResultMessage = sResultMessage;
                            break;

                        default:
                            oApiResponse.OperationResult = 0;
                            sResultMessage = nLanguageID == 2 ? "An error occurred during the operation. Please try again later." : "حدث خطأ  يرجى المحاولة لاحقا مرة أخرى.";
                            oApiResponse.OperationResultMessage = sResultMessage;
                            break;
                        }
                    }
                    return(Request.CreateResponse(HttpStatusCode.OK, oApiResponse));
                }
                catch (Exception ex)
                {
                    Elmah.ErrorLog.GetDefault(HttpContext.Current).Log(new Elmah.Error(ex));
                    oApiResponse.OperationResult = 0;
                    sResultMessage = nLanguageID == 2 ? "An error occurred during the operation. Please try again later." : "حدث خطأ  يرجى المحاولة لاحقا مرة أخرى.";
                    oApiResponse.OperationResultMessage = sResultMessage;
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, oApiResponse));
                }
            }
            oApiResponse.OperationResult = 0;
            sResultMessage = nLanguageID == 2 ? "An error occurred during the operation. Please try again later." : "حدث خطأ  يرجى المحاولة لاحقا مرة أخرى.";
            oApiResponse.OperationResultMessage = sResultMessage;
            return(Request.CreateResponse(HttpStatusCode.BadRequest, oApiResponse));
        }
Пример #4
0
        public void SendTicketChatPushNotification(int nTicketID, string sContent, bool bIsFileTypeChat, TicketChatViewModel oTicketChatViewModel)
        {
            List <TicketMobileUserParticipantViewModel> lstTicketMobileUserParticipantViewModel = this.oITicketServices.IlGetTicketMobileUserParticipants(nTicketID, -99);

            if (lstTicketMobileUserParticipantViewModel.Count > 0)
            {
                foreach (var oTicketMobileUserParticipantViewModel in lstTicketMobileUserParticipantViewModel)
                {
                    if (!oTicketMobileUserParticipantViewModel.DEVICE_ID.Equals(string.Empty))
                    {
                        PushNotification oPushNotification = new PushNotification();
                        oPushNotification.NotificationType = enmNotificationType.TicketChats;
                        oPushNotification.sHeadings        = oTicketMobileUserParticipantViewModel.TICKET_NAME;
                        if (bIsFileTypeChat)
                        {
                            oPushNotification.sContent = string.Format("{0} {1}", CurrentUser.sUserFullNameEnglish, oTicketMobileUserParticipantViewModel.PreferedLanguage == Data.Core.Languages.English ? " has uploaded a file" : "تحميل ملف.");
                        }
                        else
                        {
                            oPushNotification.sContent = string.Format("{0} : {1}", CurrentUser.sUserFullNameEnglish, sContent);
                        }


                        oPushNotification.enmLanguage          = oTicketMobileUserParticipantViewModel.PreferedLanguage;
                        oPushNotification.sDeviceID            = oTicketMobileUserParticipantViewModel.DEVICE_ID;
                        oPushNotification.oTicketChatViewModel = oTicketChatViewModel;
                        oPushNotification.sOneSignalAppID      = this.CurrentApplicationOneSignalID;
                        oPushNotification.sOneSignalAuthKey    = this.CurrentApplicationOneSignalAuthKey;
                        oPushNotification.SendPushNotification();
                        NotificationLogViewModel oNotificationLogViewModel = new NotificationLogViewModel();
                        oNotificationLogViewModel.APPLICATION_ID       = this.CurrentApplicationID;
                        oNotificationLogViewModel.NOTIFICATION_TYPE    = "tickets";
                        oNotificationLogViewModel.REQUEST_JSON         = oPushNotification.sRequestJSON;
                        oNotificationLogViewModel.RESPONSE_MESSAGE     = oPushNotification.sResponseResult;
                        oNotificationLogViewModel.MOBILE_NUMBERS       = oTicketMobileUserParticipantViewModel.PHONE_NUMBER;
                        oNotificationLogViewModel.IS_SENT_NOTIFICATION = oPushNotification.bIsSentNotification;
                        oICommonServices.oInsertNotificationLog(oNotificationLogViewModel);
                    }
                }
            }



            //if (oTicketChatViewModel.TICKET_CHAT_TYPE_ID != 1)
            //{
            //    oPushNotification.sContent = "File uploaded";
            //}
            //else
            //{
            //    oPushNotification.sContent = oTicketChatViewModel.REPLY_MESSAGE.Length > 25 ? oTicketChatViewModel.REPLY_MESSAGE.Substring(0, 100) + "..." : oTicketChatViewModel.REPLY_MESSAGE;
            //}
        }
Пример #5
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));
        }