Esempio n. 1
0
        public async Task<IEnumerable<Models.NoteType>> UpdateMultipleNoteTypes( NoteType[] values, string name ) {
            foreach ( Models.NoteType nt in values ) {
                if ( !await ValidateNoteType( nt ) ) {
                    throw new HttpResponseException( System.Net.HttpStatusCode.BadRequest );
                }

            }
            await noteTypesDAL.UpdateMultipleNoteTypes( values, name );
            Signalr.SnooNoteUpdates.Instance.RefreshNoteTypes( values.Select( nt => nt.SubName ).Distinct() );
            return values;
        }
Esempio n. 2
0
 public async Task UpdateMultipleNoteTypes( NoteType[] ntypes, string uname ) {
     List<Dictionary<string, object>> ntypeParams = new List<Dictionary<string, object>>();
     foreach ( NoteType nt in ntypes ) {
         ntypeParams.Add( new Dictionary<string, object>() { { "NoteTypeID", nt.NoteTypeID }, { "SubName", nt.SubName }, { "DisplayName", nt.DisplayName }, { "ColorCode", nt.ColorCode }, { "DisplayOrder", nt.DisplayOrder }, { "Bold", nt.Bold }, { "Italic", nt.Italic }, { "uname", uname } } );
     }
     using ( SqlConnection con = new SqlConnection( constring ) ) {
         string query = "update NoteTypes set DisplayName = @DisplayName , ColorCode = @ColorCode , DisplayOrder = @DisplayOrder , Bold = @Bold , Italic = @Italic " +
             " OUTPUT GETUTCDATE() as 'HistTimestamp','U' as 'HistAction',@uname as 'HistUser',INSERTED.NoteTypeID,INSERTED.SubredditID,INSERTED.DisplayName,INSERTED.ColorCode,INSERTED.DisplayOrder,INSERTED.Bold,INSERTED.Italic,INSERTED.Disabled INTO " +
                 "NoteTypes_History(HistTimestamp,HistAction,HistUser,NoteTypeID,SubredditID,DisplayName,ColorCode,DisplayOrder,Bold,Italic,Disabled) " +
             " where NoteTypeID = @NoteTypeID";
         await con.ExecuteAsync( query, ntypeParams );
     }
 }
Esempio n. 3
0
        public async Task<IEnumerable<int>> DeleteMultipleNoteTypes( NoteType[] values, string name ) {
            if ( !await noteTypesDAL.ValidateNoteTypesInSubs( values ) ) {
                throw new HttpResponseException( new System.Net.Http.HttpResponseMessage( System.Net.HttpStatusCode.BadRequest ) { ReasonPhrase = "You gone and changed a NoteType to a different Subreddit ya goof!" } );
            }
            foreach ( NoteType nt in values ) {

                if ( !ClaimsPrincipal.Current.HasClaim( $"urn:snoonotes:subreddits:{nt.SubName.ToLower()}:admin", "true" ) )
                    throw new UnauthorizedAccessException( "You are not an admin of this subreddit!" );

            }
            await noteTypesDAL.DeleteMultipleNoteTypes( values, name );
            Signalr.SnooNoteUpdates.Instance.RefreshNoteTypes( values.Select( nt => nt.SubName ).Distinct() );
            return values.Select( nt => nt.NoteTypeID );
        }