Example #1
0
        public JsonResult GetMessages(int?id, int?_START_LIMIT, int?_END_LIMIT)    // id_dosar
        {
            MesajView mv     = new MesajView();
            string    conStr = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
            int       uid    = Convert.ToInt32(Session["CURENT_USER_ID"]);
            Mesaj     mesaj  = new Mesaj(uid, conStr);

            Utilizator[] us = (Utilizator[])mesaj.GetReceivers().Result;
            Utilizator   s  = (Utilizator)mesaj.GetSender().Result;
            Nomenclator  n  = (Nomenclator)mesaj.GetTipMesaj().Result;
            DateTime?    da = (DateTime?)mesaj.GetMessageReadDate(uid).Result;
            Dosar        d  = new Dosar(uid, conStr, Convert.ToInt32(id));

            mv.MesajJson       = new MesajJson(mesaj, d, s, us, n, da);
            mv.InvolvedParties = (Utilizator[])d.GetInvolvedParties().Result;
            mv.TipuriMesaj     = (Nomenclator[])(new NomenclatoareRepository(uid, conStr).GetAll("tip_mesaje").Result);
            List <MesajJson> ls = new List <MesajJson>();

            Mesaj[] ms = null;

            if (id != null)
            {
                d  = new Dosar(uid, conStr, Convert.ToInt32(id));
                ms = (Mesaj[])d.GetMesaje().Result;
            }
            else
            {
                Utilizator u = (Utilizator)Session["CURENT_USER"];
                ms = (Mesaj[])u.GetMesaje(_START_LIMIT, _END_LIMIT).Result;
            }

            /*
             * foreach(Mesaj m in ms)
             * {
             *  //ls.Add(new MesajJson(m, (Dosar)m.GetDosar().Result, (Utilizator)m.GetSender().Result, (Utilizator[])m.GetReceivers().Result, (Nomenclator)m.GetTipMesaj().Result, (DateTime?)m.GetMessageReadDate(uid).Result));
             *  MesajJson mj = new MesajJson(m);
             *  mj.DataCitire = (DateTime?)m.GetMessageReadDate(uid).Result;
             *  ls.Add(mj);
             * }
             * mv.MesajeJson = ls.ToArray();
             */
            mv.MesajeJson = new MesajJson[ms.Length];
            for (int i = 0; i < ms.Length; i++)
            {
                mv.MesajeJson[i]            = new MesajJson(ms[i]);
                mv.MesajeJson[i].DataCitire = (DateTime?)ms[i].GetMessageReadDate(uid).Result;
            }

            //return PartialView("_MesajeView", mv);
            return(Json(mv, JsonRequestBehavior.AllowGet));
        }