Esempio n. 1
0
        public bool UpdateSMSStatus(string smsID, string status)
        {
            DatabaseImpl dbImpl = new DatabaseImpl();
            bool         ret    = dbImpl.UpdateAttendaceSMSStatus(smsID, status);

            Logger.Debug(String.Format("SMS status update({0}): {1}", smsID, ret));
            return(ret);
        }
Esempio n. 2
0
        public Task <bool> SendSMS(SendRequestData requestData)
        {
            TaskCompletionSource <bool> taskCompletion = new TaskCompletionSource <bool>();
            bool ret = false;

            if (String.IsNullOrWhiteSpace(requestData.URL))
            {
                Logger.Error("Failed to send SMS: URL is not setup.");
                taskCompletion.SetResult(ret);
                return(taskCompletion.Task);
            }

            RestClient  client  = new RestClient(requestData.URL);
            RestRequest request = new RestRequest(Method.POST);

            request.AddJsonBody(new {
                number = requestData.Number,
                text   = requestData.Text
            });

            try
            {
                client.ExecuteAsync(request, response =>
                {
                    if (response.StatusCode == HttpStatusCode.OK)
                    {
                        Dictionary <string, string> values = JsonConvert.DeserializeObject <Dictionary <string, string> >(response.Content);
                        string smsID = values["id"];

                        if (!string.IsNullOrEmpty(requestData.AttendanceID))
                        {
                            DatabaseImpl dbImpl = new DatabaseImpl();
                            ret = dbImpl.UpdateAttendanceSMSID(requestData.AttendanceID, requestData.IsTimeIn, smsID);
                            Logger.Debug(String.Format("SMS ID update({0}): {1}", smsID, ret));
                        }
                        else
                        {
                            // For bulk sending
                            ret = true;
                        }
                    }
                    else
                    {
                        Logger.Error(String.Format("Failed to send SMS({0}): {1}", requestData.URL, response.ErrorMessage));
                    }
                    taskCompletion.SetResult(ret);
                });
            }
            catch (Exception error)
            {
                taskCompletion.SetResult(ret);
                Logger.Error("Error encountered when sending SMS: ", error);
            }

            return(taskCompletion.Task);
        }