public string ComposeReply(Stream message)
        {
            try
            {
                ComposeMessage objInput = JSonHelper.JsonDeserialize<ComposeMessage>(new StreamReader(message).ReadToEnd());
                if (System.Configuration.ConfigurationManager.AppSettings[objInput.Pin] == null)
                {

                    return "Invalid PIN";
                }
                if (objInput.Pin != null && objInput.Pin.Length > 0)
                {
                    MessageInfo obj = new MessageInfo();
                    MessageBLL objbll = new MessageBLL();
                    string filepath = "";
                    if (objInput.Attachment != null && objInput.Attachment.GetUpperBound(0) >= 0)
                    {
                        for (int ictr = 0; ictr <= objInput.Attachment.GetUpperBound(0); ictr++)
                        {
                            if (filepath.Length <= 0)
                            {
                                filepath = System.Configuration.ConfigurationManager.AppSettings["messageattachmentfolder"].ToString() + "\\" + Guid.NewGuid().ToString() + "." + objInput.Attachmentextension[ictr];

                                File.WriteAllBytes(filepath, Convert.FromBase64String(objInput.Attachment[ictr]));
                            }
                            else
                            {
                                string filepath1 = System.Configuration.ConfigurationManager.AppSettings["messageattachmentfolder"].ToString() + "\\" + Guid.NewGuid().ToString() + "." + objInput.Attachmentextension[ictr];

                                File.WriteAllBytes(filepath1, Convert.FromBase64String(objInput.Attachment[ictr]));

                                filepath = filepath + "," + filepath1;
                            }
                        }
                    }
                    obj.MessageSignatureId = objInput.MessageSignatureId;
                    obj.FromId = objInput.FromId;
                    obj.FromType = objInput.FromType;

                    obj.Pin = System.Configuration.ConfigurationManager.AppSettings[objInput.Pin].ToString();

                    PhysicianInfo objinfo = new PhysicianInfo();
                    PhysicianBLL objphy = new PhysicianBLL();
                    int PhysicianId = objInput.PhysicianId;
                    objinfo = objphy.GetPhysicianInfoByPatientId(PhysicianId, obj.Pin);
                    if (objinfo.UserType == 24)
                    {
                        obj.ToId = objInput.ToId;//Convert.ToInt32(dd_To.SelectedValue.ToString());
                        obj.ToType = objInput.ToType;
                    }
                    else if (objinfo.UserType == 23)
                    {
                        obj.ToId = objInput.ToId;//Convert.ToInt32(dd_To.SelectedValue.ToString());
                        obj.ToType = 23;
                    }
                    else
                    {
                        obj.ToId = objInput.ToId;//Convert.ToInt32(dd_To.SelectedValue.ToString());
                        obj.ToType = objInput.ToType;
                    }

                    obj.ToEmailId = objInput.ToEmailId;
                    obj.Subject = objInput.Subject;
                    obj.Message = objInput.Message;
                    if (objInput.Status != null && objInput.Status.Length > 0)
                    {
                        obj.Status = objInput.Status;  // R for reply message "O";
                        if (obj.Status == "R")
                        {
                            obj.MessageRepliedTo = objInput.MessageRepliedTo;
                        }
                    }
                    else
                    {
                        obj.Status = "R";
                    }
                    obj.LocationCoordinates = objInput.LocationCoordinates;
                    if (objInput.MessageId != 0)
                        obj.MessageId = objInput.MessageId;
                    else
                        obj.MessageId = 0;
                    if (filepath != null && filepath.Length > 0)
                        obj.Attachment = filepath;
                    int i = objbll.insertmessage(obj);
                    if (i > 0)
                        return "message sent successfully";
                    else
                        return "message not sent";
                }
                else
                {
                    return "Pin is a required field";
                }
            }
            catch (Exception ex)
            {
                return ex.Message;
            }
        }