Skip to content

Commit

Permalink
Add IsAdmin & IsAuthor checks (#111)
Browse files Browse the repository at this point in the history
* Add IsAdmin, IsAuthor, and GetPuzzles methods
* Add xml comments
* Migration to remove EventOwners and add Events table
* Move GetPuzzlesFor Author out of data model.
  • Loading branch information
asyasky authored Dec 5, 2018
1 parent 64dd075 commit 74d1ec6
Show file tree
Hide file tree
Showing 10 changed files with 1,064 additions and 80 deletions.
2 changes: 1 addition & 1 deletion Data/DataModel/EventAdmins.cs
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ public class EventAdmins
/// Foreign key - event table
/// </summary
[ForeignKey("Event.ID")]
public virtual EventOwners Event { get; set; }
public virtual Event Event { get; set; }

/// <summary>
/// Foreign key - user table
Expand Down
26 changes: 0 additions & 26 deletions Data/DataModel/EventOwners.cs

This file was deleted.

23 changes: 22 additions & 1 deletion Data/DataModel/PuzzleUser.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
using System.ComponentModel.DataAnnotations;
using System.Collections.Generic;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using Microsoft.AspNetCore.Identity;
Expand Down Expand Up @@ -32,5 +33,25 @@ public static PuzzleUser GetPuzzleUser(string identityUserId, PuzzleServerContex
{
return dbContext.PuzzleUsers.Where(user => user.IdentityUserId == identityUserId).FirstOrDefault();
}

/// <summary>
/// Returns whether or not a user is an author for the given event
/// </summary>
/// <param name="thisEvent">The event that's being checked</param>
/// <param name="puzzleServerContext">Current PuzzleServerContext</param>
public bool IsAuthorForEvent(PuzzleServerContext puzzleServerContext, Event thisEvent)
{
return puzzleServerContext.EventAuthors.Where(a => a.Author.ID == ID && a.Event.ID == thisEvent.ID).Any();
}

/// <summary>
/// Returns whether or not a user is an admin for the given event
/// </summary>
/// <param name="thisEvent">The event that's being checked</param>
/// <param name="puzzleServerContext">Current PuzzleServerContext</param>
public bool IsAdminForEvent (PuzzleServerContext dbContext, Event thisEvent)
{
return dbContext.EventAdmins.Where(a => a.Admin.ID == ID && a.Event.ID == thisEvent.ID).Any();
}
}
}
1 change: 0 additions & 1 deletion Data/IPuzzleServerContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@ public interface IPuzzleServerContext
DbSet<Event> Events { get; set; }
DbSet<EventAdmins> EventAdmins { get; set; }
DbSet<EventAuthors> EventAuthors { get; set; }
DbSet<EventOwners> EventOwners { get; set; }
DbSet<EventTeams> EventTeams { get; set; }
DbSet<Feedback> Feedback { get; set; }
DbSet<Invitation> Invitations { get; set; }
Expand Down
Loading

0 comments on commit 74d1ec6

Please sign in to comment.