/// <summary> /// Permite enviar un SMS /// </summary> /// <param name="recipient">Número del teléfono móvil</param> /// <param name="carrier">ID del carrier. Corresponde a uno de los valores de la tabla SSO_SMS_Carriers</param> /// <param name="text">Texto del mensaje</param> public static void SendSMS(string recipient, int carrier, string text) { text = text.Trim(); if (text.Length < 2) { throw new Exception("Mensaje muy corto"); } else if (String.IsNullOrEmpty(recipient)) { throw new ArgumentNullException("recipient"); } else { using (Data.DataContext DataContext = new Data.DataContext(System.Configuration.ConfigurationManager.ConnectionStrings["SMSServiceConnectionString"].ConnectionString)) { string result = ""; // Crea el registro porque el Webservice de la OPTIC va a consultar este registro para obtener el número de celular var log = new Data.SSO_SMS_Log(); log.sourceUserId = SSOHelper.CurrentIdentity.Id; log.datetime = DateTime.Now; log.result = "Waiting"; log.text = text; log.mobile = recipient; log.idCarrier = carrier; DataContext.SSO_SMS_Log.InsertOnSubmit(log); DataContext.SubmitChanges(); try { string url = String.Format((string)SSOHelper.Configuration["SMS_WebService"], log.id, text); HttpWebRequest request = (HttpWebRequest)WebRequest.Create(url); request.Timeout = 10000; request.Method = "GET"; request.ContentType = "text/html; charset=utf-8"; ServicePointManager.ServerCertificateValidationCallback = SendSMS_ValidateServerCertificate; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); result = response.StatusCode.ToString(); if (response.StatusCode != HttpStatusCode.OK) { throw new Exception("Webservice response: " + response.StatusCode.ToString()); } } catch (Exception exception) { if (String.IsNullOrEmpty(result)) { result = exception.ToString(); } throw exception; } finally { ServicePointManager.ServerCertificateValidationCallback = null; log.result = result; DataContext.SubmitChanges(); } } } }
public void ChangeMessageState(int idMessage, int idState, string rememberOn) { using (Data.DataContext dataContext = SSOHelper.GetDataContext()) { // Controla permisos var query = from r in dataContext.SSO_Messages join t in dataContext.SSO_Messages_Targets on r.id equals t.idMessage where r.id == idMessage && ((t.targetType == (int)SSOMessageTarget.User && t.target == SSOHelper.CurrentIdentity.Id) || (t.targetType == (int)SSOMessageTarget.Role && dataContext.SSO_UserInRole(SSOHelper.CurrentIdentity.Id, t.target) > 0)) select r; if (query.Count() > 0) { Data.SSO_Messages_States state = (from r in dataContext.SSO_Messages_States where r.idMessage == idMessage && r.idUser == SSOHelper.CurrentIdentity.Id select r).SingleOrDefault(); if (state == null) { state = new Data.SSO_Messages_States(); state.idMessage = idMessage; state.idUser = SSOHelper.CurrentIdentity.Id; dataContext.SSO_Messages_States.InsertOnSubmit(state); } state.idState = idState; state.updatedOn = DateTime.Now; state.rememberOn = String.IsNullOrEmpty(rememberOn) ? null : (DateTime?)DateTime.ParseExact(rememberOn, "yyyy/MM/dd", null).Date; dataContext.SubmitChanges(); } } }