Пример #1
0
        public Notification Create(Notification notification)
        {
            var createdNotification = new Notification();


            using (var dbconn = new SqlConnection(ConfigurationManager.ConnectionStrings["dbconn"].ConnectionString))
            {
                if (dbconn.State == ConnectionState.Open)
                {
                    dbconn.Close();
                }
                dbconn.Open();

                using (var cmd = new SqlCommand("spCreateNotification", dbconn))
                {
                    try
                    {
                        cmd.CommandType = CommandType.StoredProcedure;
                        cmd.Parameters.AddWithValue("@title", notification.Title);
                        cmd.Parameters.AddWithValue("@comment", notification.Description);
                        cmd.Parameters.AddWithValue("@userID", notification.UserId);
                        cmd.Parameters.AddWithValue("@action", notification.Action);

                        var reader = cmd.ExecuteReader();

                        while (reader.Read())
                        {
                            createdNotification      = _notificationTransformer.Transform(reader);
                            createdNotification.User = _userTransformer.Transform(reader);
                        }
                    }
                    catch (Exception)
                    {
                        // ignored
                    }
                }
            }

            return(createdNotification);
        }
Пример #2
0
        public Notification Create(Notification notification)
        {
            var createdNotification = new Notification();

            using (var sp = new StoredProcedure("spCreateNotification"))
            {
                sp.SqlCommand.Parameters.AddWithValue("@title", notification.Title);
                sp.SqlCommand.Parameters.AddWithValue("@comment", notification.Description);
                sp.SqlCommand.Parameters.AddWithValue("@userID", notification.UserId);
                sp.SqlCommand.Parameters.AddWithValue("@action", notification.Action);

                var reader = sp.SqlCommand.ExecuteReader();

                while (reader.Read())
                {
                    createdNotification      = _notificationTransformer.Transform(reader);
                    createdNotification.User = _userTransformer.Transform(reader);
                }
            }

            return(createdNotification);
        }