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 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); }