public HttpResponseMessage CreateTicket(TakamulTicket oTakamulTicket, int nUserID, int nLanguageID)
        {
            ApiResponse oApiResponse   = new ApiResponse();
            string      sResultMessage = string.Empty;

            if (ModelState.IsValid)
            {
                try
                {
                    string sDefaultImagePath = string.Empty;
                    if (!string.IsNullOrEmpty(oTakamulTicket.Base64DefaultImage))
                    {
                        enumFileTypes oEnumFileTypes = (enumFileTypes)Enum.Parse(typeof(enumFileTypes), oTakamulTicket.DefaultImageType.ToString());
                        switch (oEnumFileTypes)
                        {
                        case enumFileTypes.png:
                            sDefaultImagePath = CommonHelper.AppendTimeStamp("fake.png");
                            break;

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

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

                    TicketViewModel oTicketViewModel = new TicketViewModel()
                    {
                        APPLICATION_ID          = oTakamulTicket.ApplicationID,
                        TICKET_NAME             = oTakamulTicket.TicketName,
                        TICKET_DESCRIPTION      = oTakamulTicket.TicketDescription,
                        DEFAULT_IMAGE           = sDefaultImagePath,
                        TICKET_CREATED_PLATFORM = (int)Infrastructure.Core.enmTicketPlatForm.Mobile,
                        CREATED_BY = nUserID
                    };

                    Response oResponse = this.oITicketServices.oInsertTicket(oTicketViewModel, nUserID);
                    if (oResponse.nOperationResult == 1)
                    {
                        if (!string.IsNullOrEmpty(sDefaultImagePath) && !string.IsNullOrEmpty(oTakamulTicket.Base64DefaultImage))
                        {
                            FileAccessService oFileAccessService = new FileAccessService(CommonHelper.sGetConfigKeyValue(ConstantNames.FileAccessURL));
                            if (!oResponse.ResponseID.Equals("-99"))
                            {
                                Byte[] oArrImage = Convert.FromBase64String(oTakamulTicket.Base64DefaultImage);

                                MagickImage oMagickImage = new MagickImage(oArrImage);
                                oMagickImage.Format = MagickFormat.Png;
                                oMagickImage.Resize(Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageWidth)), Convert.ToInt32(CommonHelper.sGetConfigKeyValue(ConstantNames.ImageHeight)));


                                string sDirectoyPath = Path.Combine(oTakamulTicket.ApplicationID.ToString(), oResponse.ResponseID);
                                oFileAccessService.CreateDirectory(sDirectoyPath);
                                //oFileAccessService.WirteFileByte(Path.Combine(sDirectoyPath, sDefaultImagePath), oArrImage);
                                oFileAccessService.WirteFileByte(Path.Combine(sDirectoyPath, sDefaultImagePath), oMagickImage.ToByteArray());
                            }
                        }
                        oApiResponse.OperationResult = 1;
                        oApiResponse.ResponseID      = Convert.ToInt32(oResponse.ResponseID);
                        sResultMessage = nLanguageID == 2 ? "Ticket has been successfully created." : "تم إنشاء الموضوع بنجاح.";
                        oApiResponse.OperationResultMessage = sResultMessage;
                    }
                    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;
                    oApiResponse.OperationResultMessage = nLanguageID == 2 ? "An error occurred during the operation. Please try again later." : "حدث خطأ  يرجى المحاولة لاحقا مرة أخرى.";
                    return(Request.CreateResponse(HttpStatusCode.InternalServerError, oApiResponse));
                }
            }
            oApiResponse.OperationResult        = 0;
            oApiResponse.OperationResultMessage = nLanguageID == 2 ? "validation failed": "خطاء في التحقق";
            return(Request.CreateResponse(HttpStatusCode.BadRequest, oApiResponse));
        }
        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));
        }
Beispiel #3
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));
        }