public string PermanentlyDeleteMessage(Stream message)
        {
            try
            {

                MessageBox objInput = JSonHelper.JsonDeserialize<MessageBox>(new StreamReader(message).ReadToEnd());
                if (System.Configuration.ConfigurationManager.AppSettings[objInput.Pin] == null)
                {
                    return "Invalid PIN";
                }
                if (objInput.Pin != null && objInput.Pin.Length > 0)
                {
                    MessageBox obj2 = new MessageBox();
                    List<MessageInfo> objcol = new List<MessageInfo>();
                    MessageInfo obj = new MessageInfo();
                    MessageBLL objbll = new MessageBLL();

                    obj.MessageComposeId = objInput.MessageComposeId;
                    obj.Pin = System.Configuration.ConfigurationManager.AppSettings[objInput.Pin].ToString();
                    int i = objbll.DeleteMessages_DeletedItems(obj);
                    if (i > 0)
                        return "Delete sucessful";
                    else
                        return "Delete Unsucessful";
                }
                else
                {
                    return "Pin is a required field";
                }
            }
            catch (Exception ex)
            {
                return "Unable to delete. Please try again later";
            }
        }
        public MessageBox[] DeletedMessages(Stream message)
        {
            MessageBox objInput = JSonHelper.JsonDeserialize<MessageBox>(new StreamReader(message).ReadToEnd());
            if (System.Configuration.ConfigurationManager.AppSettings[objInput.Pin] == null)
            {
                var objArray = new MessageBox[1];
                MessageBox obj2 = new MessageBox();
                obj2.ErrorMessage = "Invalid PIN";
                obj2.MessengerMessage = "Invalid PIN";
                objArray[0] = obj2;
                return objArray;
            }
            if (objInput.Pin != null && objInput.Pin.Length > 0)
            {
                var objArray = new MessageBox[1];
                MessageBox obj2 = new MessageBox();
                obj2.ErrorMessage = "No messages found";
                obj2.MessengerMessage = "No messages found";
                List<MessageInfo> objcol = new List<MessageInfo>();
                MessageInfo obj = new MessageInfo();
                MessageBLL objbll = new MessageBLL();
                obj.ToId = objInput.ToId;
                obj.ToType = objInput.ToType;
                obj.Getattachment = objInput.GetAttachment;
                obj.Pin = System.Configuration.ConfigurationManager.AppSettings[objInput.Pin].ToString();
                objcol = objbll.BindDeleteMessages(obj);
                if (objcol.Count() > 0)
                {
                    var objBox = new MessageBox[objcol.Count()];
                    for (int i = 0; i < objcol.Count(); i++)
                    {
                        MessageBox objR = new MessageBox();
                        objR.MessageComposeId = objcol[i].MessageComposeId;
                        objR.MessageId = objcol[i].MessageId;
                        objR.FromId = objcol[i].FromId;
                        objR.ToId = objcol[i].ToId;
                        objR.FromEmailId = objcol[i].FromEmailId;
                        objR.ToEmailId = objcol[i].ToEmailId;
                        objR.MessageId = objcol[i].MessageId;
                        objR.Subject = objcol[i].Subject;
                        objR.Message = objcol[i].Message;
                        if (objcol[i].Attachment != null && objcol[i].Attachment.Length > 0)
                        {
                            ////byte[] filecontent = File.ReadAllBytes(objcol[i].Attachment);
                            //FileInfo fi = new FileInfo(objcol[i].Attachment);
                            ////objR.Attachment = Convert.ToBase64String(filecontent);
                            //string extension = fi.Name.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)[1];
                            //objR.AttachmentExtension = extension.Split(',');

                            string[] files = objcol[i].Attachment.Split(',');
                            string[] filextensions = new string[files.Count()];

                            for (int icnt = 0; icnt <= files.GetUpperBound(0); icnt++)
                            {
                                string[] filecomps = files[icnt].Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries);
                                if (filecomps.GetUpperBound(0) >= 1)
                                {
                                    filextensions[icnt] = filecomps[1];
                                }
                            }


                            objR.AttachmentExtension = filextensions;
                        }
                        objR.LocationCoordinates = objcol[i].LocationCoordinates;
                        objR.FromType = objcol[i].FromType;
                        objR.ToType = objcol[i].ToType;
                        objR.Status = objcol[i].Status;
                        objR.ProcessDate = objcol[i].ProcessDate;
                        objR.FromName = objcol[i].FromName;
                        objR.userType = objcol[i].userType;
                        objR.physicianId = objcol[i].physicianId;
                        objR.MessageRepliedTo = objcol[i].MessageRepliedTo;
                        objR.IsMessageRead = objcol[i].IsMessageRead;
                        objR.MessageSignatureId = objcol[i].MessageSignatureId;
                        objR.MessageSignatureName = objcol[i].MessageSignatureName;
                        objR.MessageSignatureOffcName = objcol[i].MessageSignatureOffcName;
                        objBox[i] = objR;
                    }
                    return objBox;
                }
                objArray[0] = obj2;
                return objArray;
            }
            else
            {
                var objArray = new MessageBox[1];
                MessageBox obj2 = new MessageBox();
                obj2.ErrorMessage = "No messages found";
                obj2.MessengerMessage = "No messages found";
                objArray[0] = obj2;
                return objArray;
            }
        }
        public MessageBox[] GetAttachment(Stream message)
        {
            MessageBox objInput = JSonHelper.JsonDeserialize<MessageBox>(new StreamReader(message).ReadToEnd());
            if (System.Configuration.ConfigurationManager.AppSettings[objInput.Pin] == null)
            {
                var objArray = new MessageBox[1];
                MessageBox obj2 = new MessageBox();
                obj2.ErrorMessage = "Invalid PIN";
                obj2.MessengerMessage = "Invalid PIN";
                objArray[0] = obj2;
                return objArray;
            }
            if (objInput.Pin != null && objInput.Pin.Length > 0)
            {
                var objArray = new MessageBox[1];
                MessageBox obj2 = new MessageBox();
                obj2.ErrorMessage = "No messages found";
                obj2.MessengerMessage = "No messages found";
                List<MessageInfo> objcol = new List<MessageInfo>();
                MessageInfo obj = new MessageInfo();
                MessageBLL objbll = new MessageBLL();
                obj.MessageId = objInput.MessageId;
                obj.Pin = System.Configuration.ConfigurationManager.AppSettings[objInput.Pin].ToString();
                objcol = objbll.GetAttachmentByMesageId(obj);
                if (objcol.Count() > 0)
                {
                    var objBox = new MessageBox[objcol.Count()];
                    for (int i = 0; i < objcol.Count(); i++)
                    {
                        MessageBox objR = new MessageBox();
                        if (objcol[i].Attachment != null && objcol[i].Attachment.Length > 0)
                        {
                            string[] filenames = objcol[i].Attachment.Split(',');
                            string[] filecont = new string[1];
                            string[] fileext = new string[1];
                            for (int icnt = 0; icnt <= filenames.GetUpperBound(0); icnt++)
                            {
                                if (icnt == objInput.AttachmentIndex)
                                {
                                    byte[] filecontent = File.ReadAllBytes(filenames[icnt]);
                                    FileInfo fi = new FileInfo(filenames[icnt]);
                                    filecont[0] = Convert.ToBase64String(filecontent);
                                    fileext[0] = fi.Name.Split(new string[] { "." }, StringSplitOptions.RemoveEmptyEntries)[1];
                                    objR.Attachment = filecont;
                                    objR.AttachmentExtension = fileext;
                                    break;
                                }

                            }

                        }
                        objBox[i] = objR;
                    }
                    return objBox;
                }
                objArray[0] = obj2;
                return objArray;
            }
            else
            {
                var objArray = new MessageBox[1];
                MessageBox obj2 = new MessageBox();
                obj2.ErrorMessage = "PIN is a required field";
                obj2.MessengerMessage = "Pin is a required field";
                objArray[0] = obj2;
                return objArray;
            }
        }