Exemple #1
0
        public JsonResult GetStadiuCurent(int id)
        {
            response             r               = new response();
            string               conStr          = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
            int                  _CURENT_USER_ID = Convert.ToInt32(Session["CURENT_USER_ID"]);
            Proces               p               = new Proces(_CURENT_USER_ID, conStr, id);
            ProcesStadiu         ps              = (ProcesStadiu)p.GetStadiuCurent().Result;
            ProcesStadiuExtended toReturn        = new ProcesStadiuExtended(ps);

            return(Json(JsonConvert.SerializeObject(toReturn, Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter()
            {
                DateTimeFormat = CommonFunctions.DATE_FORMAT
            }), JsonRequestBehavior.AllowGet));
        }
Exemple #2
0
        public JsonResult Edit(ProcesStadiuExtended ProcesStadiuExtended)
        {
            response     toReturn = new response();
            string       conStr   = Session["conStr"].ToString(); //ConfigurationManager.ConnectionStrings["MySQLConnectionString"].ConnectionString;
            int          uid      = Convert.ToInt32(Session["CURENT_USER_ID"]);
            Sentinta     s        = null;
            ProcesStadiu ps       = null;

            if (ProcesStadiuExtended != null)
            {
                if (ProcesStadiuExtended.Sentinta != null && ProcesStadiuExtended.ProcesStadiu.ID_SENTINTA != null)
                {
                    s = new Sentinta(uid, conStr);
                    PropertyInfo[] pis = ProcesStadiuExtended.Sentinta.GetType().GetProperties();
                    foreach (PropertyInfo pi in pis)
                    {
                        pi.SetValue(s, pi.GetValue(ProcesStadiuExtended.Sentinta));
                    }
                }

                ps = new ProcesStadiu(uid, conStr);
                PropertyInfo[] pis2 = ProcesStadiuExtended.ProcesStadiu.GetType().GetProperties();
                foreach (PropertyInfo pi in pis2)
                {
                    pi.SetValue(ps, pi.GetValue(ProcesStadiuExtended.ProcesStadiu));
                }
            }
            if (ps.ID == null) // insert
            {
                if (!ProcesStadiuExtended.Stadiu.STADIU_CU_SENTINTA)
                {
                    ps.ID_SENTINTA = null;
                    s = null;
                }
                if (s != null)
                {
                    toReturn = s.Insert();
                }
                if (s == null || toReturn.Status)
                {
                    toReturn         = ps.Insert();
                    toReturn.Message = JsonConvert.SerializeObject(new ProcesStadiuExtended(ps), Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter()
                    {
                        DateTimeFormat = CommonFunctions.DATE_FORMAT
                    });
                }
            }
            else //update
            {
                ProcesStadiu existingPS = new ProcesStadiu(uid, conStr, Convert.ToInt32(ps.ID));
                if (!ProcesStadiuExtended.Stadiu.STADIU_CU_SENTINTA)
                {
                    ps.ID_SENTINTA = null;
                }
                if (existingPS.ID_SENTINTA != null && ps.ID_SENTINTA != null)
                {
                    toReturn = s.Update();
                }
                if (existingPS.ID_SENTINTA == null && ps.ID_SENTINTA != null)
                {
                    toReturn = s.Insert();
                    if (toReturn.Status)
                    {
                        ps.ID_SENTINTA = toReturn.InsertedId;
                    }
                }
                if (existingPS.ID_SENTINTA != null && ps.ID_SENTINTA == null)
                {
                    if (s != null)
                    {
                        toReturn = s.Delete();
                    }
                }

                if (toReturn.Status)
                {
                    toReturn         = ps.Update();
                    toReturn.Message = JsonConvert.SerializeObject(new ProcesStadiuExtended(ps), Formatting.None, new Newtonsoft.Json.Converters.IsoDateTimeConverter()
                    {
                        DateTimeFormat = CommonFunctions.DATE_FORMAT
                    });
                }
            }

            return(Json(toReturn, JsonRequestBehavior.AllowGet));
        }