public UTILISATEUR GetUtilisateur(Guid id)
        {
            redactapplicationEntities db = new Models.redactapplicationEntities();
            UTILISATEUR utilisateur      = db.UTILISATEURs.SingleOrDefault(x => x.userId == id);

            return(utilisateur);
        }
        public List <int> GetUtilisateurRole(Guid id)
        {
            redactapplicationEntities db = new Models.redactapplicationEntities();
            UTILISATEUR utilisateur      = db.UTILISATEURs.SingleOrDefault(x => x.userId == id);
            var         data             = (from idrole in db.UserRoles
                                            where idrole.idUser == utilisateur.userId
                                            select(int) idrole.idRole).ToList <int>();

            return(data);
        }
Beispiel #3
0
        public IEnumerable <NOTIFICATIONViewModel> GetAllMessages(Guid?redactId)
        {
            var messages = new List <NOTIFICATIONViewModel>();

            using (var connection = new SqlConnection(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString))
            {
                connection.Open();
                using (var command = new SqlCommand(@"SELECT * FROM [dbo].[NOTIFICATION] where toId ='" + redactId + "' and statut = 1", connection))
                {
                    command.Notification = null;

                    var dependency = new SqlDependency(command);
                    dependency.OnChange += new OnChangeEventHandler(dependency_OnChange);

                    if (connection.State == ConnectionState.Closed)
                    {
                        connection.Open();
                    }

                    var reader = command.ExecuteReader();

                    while (reader.Read())
                    {
                        UTILISATEUR fromUser = GetUtilisateur((Guid)reader["fromId"]);
                        UTILISATEUR toUser   = GetUtilisateur((Guid)reader["toId"]);
                        COMMANDE    commande = (!string.IsNullOrEmpty(reader["commandeId"].ToString()))? GetCommande((Guid)reader["commandeId"]) : new COMMANDE();
                        if ((bool)reader["statut"])
                        {
                            messages.Add(item: new NOTIFICATIONViewModel()
                            {
                                notificationId = (Guid)reader["notificationId"],
                                commandeId     = (Guid)reader["commandeId"],
                                commanderef    = (int)commande.commandeREF,
                                statut         = (bool)reader["statut"],
                                fromId         = (Guid)reader["fromId"],
                                fromUserName   = fromUser.userNom,
                                toId           = (Guid)reader["toId"],
                                message        = reader["message"].ToString(),

                                datenotif = Convert.ToDateTime(reader["datenotif"])
                            });
                        }
                    }
                }
            }

            return(messages.OrderByDescending(x => x.datenotif).Take(6));
        }