public async Task<object> UpdateSubreddit( Models.Subreddit sub ) { if ( sub.Settings.AccessMask < 64 || sub.Settings.AccessMask <= 0 || sub.Settings.AccessMask >= 128 ) { throw new HttpResponseException( new HttpResponseMessage() { ReasonPhrase = "Invalid AccessMask", StatusCode = HttpStatusCode.BadRequest, Content = new StringContent( "Access Mask was invalid" ) } ); } else if ( ClaimsPrincipal.Current.IsInRole( sub.SubName.ToLower() ) && ClaimsPrincipal.Current.HasClaim( "urn:snoonotes:subreddits:" + sub.SubName.ToLower() + ":admin", "true" ) ) { DAL.NoteTypesDAL ntDAL = new DAL.NoteTypesDAL(); var noteTypes = await ntDAL.GetNoteTypesForSubs( new List<string>() { sub.SubName } ); if ( sub.Settings.PermBanID.HasValue && !noteTypes.Any( nt => nt.NoteTypeID == sub.Settings.PermBanID.Value ) ) { throw new HttpResponseException( new HttpResponseMessage() { ReasonPhrase = "Invalid Perm Ban ID", StatusCode = HttpStatusCode.BadRequest, Content = new StringContent( "Perm Ban id was invalid" ) } ); } if ( sub.Settings.TempBanID.HasValue && !noteTypes.Any( nt => nt.NoteTypeID == sub.Settings.TempBanID.Value ) ) { throw new HttpResponseException( new HttpResponseMessage() { ReasonPhrase = "Invalid Temp Ban ID", StatusCode = HttpStatusCode.BadRequest, Content = new StringContent( "Temp Ban id was invalid" ) } ); } await subDAL.UpdateSubredditSettings( sub ); bool updated = await Utilities.AuthUtils.UpdateModsForSub( sub ); if ( updated ) { return new { error = false, message = "Settings have been saved and moderator list has been updated!" }; } else { return new { error = false, message = "Settings have been saved and moderator list will be refreshed within 2 hours!" }; } } else { throw new UnauthorizedAccessException( "You are not a moderator of that subreddit, or you don't have full permissions!" ); } }
public async Task <Dictionary <string, IEnumerable <BasicNoteType> > > GetNoteTypesForSubs(IEnumerable <string> subs) { Dictionary <string, IEnumerable <BasicNoteType> > toReturn = new Dictionary <string, IEnumerable <BasicNoteType> >(); var notetypes = await noteTypesDAL.GetNoteTypesForSubs(subs); foreach (string sub in subs) { var basicNoteTypesForSub = notetypes.Where(t => t.SubName.ToLower() == sub).Select(t => new BasicNoteType() { Bold = t.Bold, ColorCode = t.ColorCode, DisplayName = t.DisplayName, DisplayOrder = t.DisplayOrder, Italic = t.Italic, NoteTypeID = t.NoteTypeID }).OrderBy(bt => bt.DisplayOrder); toReturn.Add(sub, basicNoteTypesForSub); } return(toReturn); }
public async Task <object> UpdateSubreddit(Models.Subreddit sub) { if (sub.Settings.AccessMask < 64 || sub.Settings.AccessMask <= 0 || sub.Settings.AccessMask >= 128) { throw new HttpResponseException(new HttpResponseMessage() { ReasonPhrase = "Invalid AccessMask", StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Access Mask was invalid") }); } else if (ClaimsPrincipal.Current.IsInRole(sub.SubName.ToLower()) && ClaimsPrincipal.Current.HasClaim("urn:snoonotes:subreddits:" + sub.SubName.ToLower() + ":admin", "true")) { DAL.NoteTypesDAL ntDAL = new DAL.NoteTypesDAL(); var noteTypes = await ntDAL.GetNoteTypesForSubs(new List <string>() { sub.SubName }); if (sub.Settings.PermBanID.HasValue && !noteTypes.Any(nt => nt.NoteTypeID == sub.Settings.PermBanID.Value)) { throw new HttpResponseException(new HttpResponseMessage() { ReasonPhrase = "Invalid Perm Ban ID", StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Perm Ban id was invalid") }); } if (sub.Settings.TempBanID.HasValue && !noteTypes.Any(nt => nt.NoteTypeID == sub.Settings.TempBanID.Value)) { throw new HttpResponseException(new HttpResponseMessage() { ReasonPhrase = "Invalid Temp Ban ID", StatusCode = HttpStatusCode.BadRequest, Content = new StringContent("Temp Ban id was invalid") }); } await subDAL.UpdateSubredditSettings(sub); bool updated = await Utilities.AuthUtils.UpdateModsForSub(sub); if (updated) { return(new { error = false, message = "Settings have been saved and moderator list has been updated!" }); } else { return(new { error = false, message = "Settings have been saved and moderator list will be refreshed within 2 hours!" }); } } else { throw new UnauthorizedAccessException("You are not a moderator of that subreddit, or you don't have full permissions!"); } }