예제 #1
0
        public async Task <ActionResult> Get(string Number)
        {
            DBConn dbConn = new DBConn();
            string key    = "user_" + Number;

            if (_redisDB.IsDataAvailable(key))
            {
                return(Content(_redisDB.GetData(key), "application/json"));
            }
            User user = null;

            using (IDatabase db = dbConn.Connect(dbOptions))
            {
                user = (await db.FetchAsync <User>()).Find(x => x.PhoneNumber.Equals(Number));
                if (null != user)
                {
                    user.Appointments = (await db.FetchAsync <Appointment>("where UserId = @0", user.Id));
                }
                db.Dispose();
            }

            dbConn.Dispose(); dbConn = null;
            string str = new JavaScriptSerializer().Serialize(Json(user));

            _redisDB.SendData(key, str);
            return(Content(str, "application/json"));
        }
예제 #2
0
파일: Response.cs 프로젝트: ag1465/project
 public static void DBSendDataCheckResponse()
 {
     using (DBConn DB = new DBConn())
     {
         // Collect count
         if (DB.Connect())
         {
             // Temporary variables for count of rows in SendData
             string sSQL  = "SELECT count(*) AS Count FROM SendData";
             long   count = 0;
             DB.OpenCursor(sSQL);
             if (DB.HasRows())
             {
                 while (DB.Fetch()) // Fetch row-by-row
                 {
                     count = DB.Col2Long("Count");
                 }
             }
             // 0 - 9: ok 10-24: Warning 25+: Critical
             Checkresults checkresults = new Checkresults();
             if ((count >= 10) && (count < 25))
             {
                 if (curstate != "1")
                 {
                     curstate = "1";
                     checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "SendData", "1", "Warning: SendData has more than 10 rows!"));
                     NagiosClient.ReportError(checkresults);
                 }
             }
             else if (count >= 25)
             {
                 if (curstate != "2")
                 {
                     curstate = "2";
                     checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "SendData", "2", "Critical: SendData has more than 25 rows!"));
                     NagiosClient.ReportError(checkresults);
                 }
             }
             else
             {
                 if (curstate != "0")
                 {
                     curstate = "0";
                     checkresults.Add(new Checkresultitem(new Checkresult("service"), "172.20.22.242", "SendData", "0", "SendData is Ok!"));
                     NagiosClient.ReportError(checkresults);
                 }
             }
         }
     }
 }
예제 #3
0
        public async Task <ActionResult> Post([FromForm] string json)
        {
            DBConn dbConn = new DBConn();

            JsonAppointment info;

            //try
            //{
            info = System.Text.Json.JsonSerializer.Deserialize <JsonAppointment>(json);
            using (IDatabase db = dbConn.Connect(dbOptions))
            {
                if (-1 == (await db.FetchAsync <User>()).FindIndex(x => x.PhoneNumber.Equals(info.PhoneNumber)))
                {
                    User user = new User()
                    {
                        Firstname   = info.Firstname,
                        Lastname    = info.Lastname,
                        Patronymic  = info.Patronymic,
                        PhoneNumber = info.PhoneNumber
                    };
                    await db.InsertAsync <User>(user);
                }
                Appointment appointment = new Appointment()
                {
                    Date    = DateTime.Now,
                    Comment = info.Comment,
                    UserId  = (await db.FetchAsync <User>()).Find(x => x.PhoneNumber == info.PhoneNumber).Id
                };
                await db.InsertAsync <Appointment>(appointment);
            }
            //}
            //catch (Exception ex)
            //{
            //    return this.StatusCode(StatusCodes.Status400BadRequest, Json(new ErrorContainer(ex.Message)));
            //}
            dbConn.Dispose(); dbConn = null;
            return(Redirect("~/Api?Number=" + info.PhoneNumber));
        }