// GET: api/NoteType/5 public async Task <Models.NoteType> Get(int id) { Models.NoteType ntype = await noteTypeBLL.GetNoteType(id); if (ntype != null && ClaimsPrincipal.Current.IsInRole(ntype.SubName)) { return(ntype); } return(null); }
// GET: api/NoteType/5 public async Task <Models.NoteType> Get(int id) { Models.NoteType ntype = await noteTypeBLL.GetNoteType(id); if (ntype != null && User.IsInRole(ntype.SubName)) { return(ntype); } return(null); }
private async Task <bool> ValidateNoteType(Models.NoteType ntype, ClaimsPrincipal user) { if (String.IsNullOrEmpty(ntype.SubName) || !user.IsInRole(ntype.SubName.ToLower())) { return(false); //doesn't mod sub or empty/null sub, insta FAIL } if (ntype.NoteTypeID == -1) { //adding new note } else { var toModNT = await GetNoteType(ntype.NoteTypeID); if (toModNT == null) { return(false); //NoteTypeID doesn't exist, FAIL } if (toModNT.SubName.ToLower() != ntype.SubName.ToLower()) { return(false); //Subreddit name changed, FAIL } } if (String.IsNullOrEmpty(ntype.ColorCode)) { return(false); //No color code, FAIL } else if (ntype.ColorCode.Length != 3 && ntype.ColorCode.Length != 6) { return(false); //Color code wrong length, FAIL } else if (!System.Text.RegularExpressions.Regex.IsMatch(ntype.ColorCode, @"\A\b[0-9a-fA-F]+\b\Z")) { return(false); //Color code not valid hex, FAIL } if (String.IsNullOrEmpty(ntype.DisplayName)) { return(false); //Null or empty display name, FAIL } else if (ntype.DisplayName.Length > 20) { return(false); //Displayname too long, FAIL } return(true); }