Beispiel #1
0
        int SendNotificacion(NotificacionModel notiModel)
        {
            using (var client = new HttpClient())
            {
                //setup client
                client.BaseAddress = new Uri(this.Server);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.Token);



                var content = new StringContent(
                    Newtonsoft.Json.JsonConvert.SerializeObject(notiModel),
                    Encoding.UTF8,
                    "application/json");

                var responseMessage = client.PostAsync("api/Notificaciones/Create", content).Result;

                //get access token from response body
                var responseJson = responseMessage.Content.ReadAsStringAsync().Result;
                var jObject      = JObject.Parse(responseJson);

                JToken tokenError = "";
                var    hasError   = jObject.TryGetValue("error", out tokenError);

                if (hasError)
                {
                    JToken tokenMsgError = "";
                    jObject.TryGetValue("error_description", out tokenMsgError);
                    throw new Exception(string.Format("Error - {0}: {1}", tokenError, tokenMsgError));
                }

                var notiModelResult = Newtonsoft.Json.JsonConvert.DeserializeObject <NotificacionModel>(responseJson);

                if (notiModelResult == null || !notiModelResult.NotificacionId.HasValue)
                {
                    throw  new Exception("Error creando notificacion");
                }


                return(notiModelResult.NotificacionId.Value);// notiCreated.NotificacionId.Value;
            }
        }
        private void btnCrear_Click(object sender, EventArgs e)
        {
            try
            {
                validaCampos();
                var notiApi = new NotificacionesApi(txtServer.Text, txtUser.Text, txtPass.Text);
                var objNotiModel = new NotificacionModel
                                       {
                                           Titulo = txtTitulo.Text,
                                           Nota = txtMsg.Text,
                                           Link = txtLink.Text,
                                           Usuarios = new List<string> {txtUsuarios.Text}
                                       };

                var idNotificacion = notiApi.CrearNotificacion(objNotiModel);
                MessageBox.Show(string.Format("Se creo la notificacion NO. {0} ", idNotificacion));
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.InnerException != null ? ex.InnerException.Message : ex.Message);
            }
        }
Beispiel #3
0
 public int CrearNotificacion(NotificacionModel notiModel)
 {
     notiModel.Aplicacion = this.App;
     return(SendNotificacion(notiModel));
 }
        internal NotificacionModel UpdateNotificacion(NotificacionModel notificacionModel)
        {
            var app = notificacionModel.AplicacionId > 0
                        ? _ctx.Clients.FirstOrDefault(s => s.Id == notificacionModel.AplicacionId)
                        : _ctx.Clients.FirstOrDefault(s => s.Name == notificacionModel.Aplicacion);

            if (app != null)
            {
                notificacionModel.Aplicacion = app.Name;
                notificacionModel.AplicacionId = app.Id;
            }

            notificacionModel.Tipo = KeyValuePar.GetDescriptionFromEnumValue((Enumeraciones.TiposNotificaciones)notificacionModel.IdTipo);
            notificacionModel.TipoVigencia = KeyValuePar.GetDescriptionFromEnumValue((Enumeraciones.TipoVigencia)notificacionModel.IdTipo);

            var oldNotificacion = _ctx.Notificacions.FirstOrDefault(s => s.NotificacionId == notificacionModel.NotificacionId);
            var result = Notificacion.UpdateFromModel(oldNotificacion, notificacionModel);
            _ctx.SaveChanges();
            notificacionModel.NotificacionId = result.NotificacionId;
            saveNotificationLog(result, notificacionModel.Usuarios);
            return notificacionModel;
        }
        internal NotificacionModel CreateNotificacion(NotificacionModel notificacionModel)
        {
            notificacionModel.FechaCreacion = DateTime.Now;

            var app = notificacionModel.AplicacionId > 0
                          ? _ctx.Clients.FirstOrDefault(s => s.Id == notificacionModel.AplicacionId)
                          : _ctx.Clients.FirstOrDefault(s => s.Name == notificacionModel.Aplicacion);

            if (app != null)
            {
                notificacionModel.Aplicacion = app.Name;
                notificacionModel.AplicacionId = app.Id;
            }

            notificacionModel.Tipo = KeyValuePar.GetDescriptionFromEnumValue((Enumeraciones.TiposNotificaciones)notificacionModel.IdTipo);
            notificacionModel.TipoVigencia = KeyValuePar.GetDescriptionFromEnumValue((Enumeraciones.TipoVigencia)notificacionModel.IdTipo);

            var result = _ctx.Notificacions.Add(Notificacion.FillEntitie(notificacionModel));
            _ctx.SaveChanges();
            saveNotificationLog(result,notificacionModel.Usuarios);
            notificacionModel.NotificacionId = result.NotificacionId;
            return notificacionModel;
        }
        internal static Notificacion UpdateFromModel(Notificacion oldNotificacion, NotificacionModel notificacionModel)
        {
            oldNotificacion.NotificacionId = notificacionModel.NotificacionId.HasValue
                                                 ? notificacionModel.NotificacionId.Value
                                                 : 0;
            oldNotificacion.AplicacionId = notificacionModel.AplicacionId;
            oldNotificacion.Aplicacion = notificacionModel.Aplicacion;
            oldNotificacion.Titulo = notificacionModel.Titulo;
            oldNotificacion.Link = notificacionModel.Link;
            oldNotificacion.Tipo = notificacionModel.Tipo;
            oldNotificacion.IdTipo = notificacionModel.IdTipo;
            oldNotificacion.IdTipoVigencia = notificacionModel.IdTipoVigencia;
            oldNotificacion.TipoVigencia = notificacionModel.TipoVigencia;
            oldNotificacion.Nota = notificacionModel.Nota;
            oldNotificacion.Vigencia = notificacionModel.Vigencia;
            oldNotificacion.Usuarios = notificacionModel.Usuarios != null
                                           ? notificacionModel.Usuarios.ListToString()
                                           : null;
            oldNotificacion.Activo = notificacionModel.Activo;
            oldNotificacion.FechaCreacion = notificacionModel.FechaCreacion;
            oldNotificacion.Intervalo = notificacionModel.Intervalo;

            return oldNotificacion;
        }
 public static Notificacion FillEntitie(NotificacionModel notiModel)
 {
     return new Notificacion
                {
                    NotificacionId = notiModel.NotificacionId.HasValue ? notiModel.NotificacionId.Value : 0,
                    AplicacionId = notiModel.AplicacionId,
                    Aplicacion = notiModel.Aplicacion,
                    Titulo = notiModel.Titulo,
                    Link = notiModel.Link,
                    IdTipo = notiModel.IdTipo,
                    Tipo = notiModel.Tipo,
                    IdTipoVigencia = notiModel.IdTipoVigencia,
                    TipoVigencia = notiModel.TipoVigencia,
                    Nota = notiModel.Nota,
                    Vigencia = notiModel.Vigencia,
                    Usuarios = notiModel.Usuarios != null ? notiModel.Usuarios.ListToString() : null,
                    Activo = notiModel.Activo,
                    FechaCreacion = notiModel.FechaCreacion,
                    Intervalo = notiModel.Intervalo
                };
 }
 private void updateAppField(NotificacionModel notificacionModel)
 {
     var _repoCliente = new ClienteRepository();
     var cliente = _repoCliente.FindClient(notificacionModel.Aplicacion);
     if (cliente != null)
         notificacionModel.AplicacionId = cliente.Id;
 }
 public int CrearNotificacion(NotificacionModel notiModel)
 {
     notiModel.Aplicacion = this.App;
     return SendNotificacion(notiModel);
 }
        int SendNotificacion(NotificacionModel notiModel)
        {
            using (var client = new HttpClient())
            {
                //setup client
                client.BaseAddress = new Uri(this.Server);
                client.DefaultRequestHeaders.Accept.Clear();
                client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
                client.DefaultRequestHeaders.Add("Authorization", "Bearer " + this.Token);

                var content = new StringContent(
                    Newtonsoft.Json.JsonConvert.SerializeObject(notiModel),
                    Encoding.UTF8,
                    "application/json");

                var responseMessage = client.PostAsync("api/Notificaciones/Create", content).Result;

                //get access token from response body
                var responseJson = responseMessage.Content.ReadAsStringAsync().Result;
                var jObject = JObject.Parse(responseJson);

                JToken tokenError = "";
                var hasError = jObject.TryGetValue("error", out tokenError);

                if (hasError)
                {
                    JToken tokenMsgError = "";
                    jObject.TryGetValue("error_description", out tokenMsgError);
                    throw new Exception(string.Format("Error - {0}: {1}", tokenError, tokenMsgError));
                }

                var notiModelResult = Newtonsoft.Json.JsonConvert.DeserializeObject<NotificacionModel>(responseJson);

                if (notiModelResult == null || !notiModelResult.NotificacionId.HasValue)
                    throw  new Exception("Error creando notificacion");

                return notiModelResult.NotificacionId.Value;// notiCreated.NotificacionId.Value;
            }
        }