public JsonResult DeleteRedirect(int _id)
 {
     try
     {
         var list = WhatsappDB.GetInstance().DeleteRedirectedMessage(_id);
         return(Json(true));
     }
     catch (Exception exc)
     {
         throw exc;
     }
 }
 public JsonResult DeleteMessage(int _messageId)
 {
     try
     {
         var result = WhatsappDB.GetInstance().DeleteMessage(_messageId);
         return(Json(result));
     }
     catch (Exception exc)
     {
         throw exc;
     }
 }
        public JsonResult SaveRedirect(int _messageId, int _departmentId)
        {
            try
            {
                var personId = JsonConvert.DeserializeObject <Person>(HttpContext.Session.GetString("ActivePerson")).Id;
                var obj      = WhatsappDB.GetInstance().SaveMessageRedirect(_messageId, _departmentId, personId);

                if (obj != null)
                {
                    WhatsappDB.GetInstance().DeleteMessage(_messageId);
                }

                return(Json(obj != null));
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }
        public JsonResult GetRedirectedMessagesForHeadOfDepartment()
        {
            try
            {
                var personId = JsonConvert.DeserializeObject <Person>(HttpContext.Session.GetString("ActivePerson")).Id;
                var list     = WhatsappDB.GetInstance().GetRedirectNotifications(personId);


                foreach (var item in list)
                {
                    var attachments = new List <string>();
                    var splitted    = item.Message.Split(new string[] { "||=>||" }, StringSplitOptions.None).ToList();

                    for (var i = 0; i < splitted.Count; i++)
                    {
                        if (splitted[i].StartsWith("{\"Key\""))
                        {
                            attachments.Add(splitted[i]);
                            splitted.RemoveAt(i);
                            i = -1;
                        }
                    }

                    for (var i = 0; i < attachments.Count; i++)
                    {
                        if (attachments[i].StartsWith("{\"Key\""))
                        {
                            var jsonModel = JsonConvert.DeserializeObject <KeyValue>(attachments[i]);
                            attachments[i] = $"<a href=\"javascript:downloadMediaMessageById('{item.MessageId}', '{jsonModel.Value.Substring(jsonModel.Value.Length - 30)}');\">{jsonModel.Key.ToUpper().Replace(".", "")} Dosyası</a>";
                        }
                    }

                    item.Message = string.Join(" ", splitted) + (string.Join(" ", splitted).Length > 0 ? "<br>" : "") + string.Join("&nbsp;|&nbsp", attachments);
                }

                return(Json(list));
            }
            catch (Exception exc)
            {
                throw exc;
            }
        }