Пример #1
0
        public COMMANDE GetCommande(Guid?id)
        {
            redactapplicationEntities db = new Models.redactapplicationEntities();
            COMMANDE commande            = db.COMMANDEs.SingleOrDefault(x => x.commandeId == id);

            return(commande);
        }
Пример #2
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));
        }