Beispiel #1
0
 public IList<UniUser> GetUsersByYear(int year)
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             return db.UniUsers.Where(u => u.EnrolementYear.Year == year && u.IsActive)
                 .Include(u => u.PermissionLevel)
                 .Include(u => u.Photographs)
                 .ToList();
         }
     }
     catch (Exception e)
     {
         throw new Exception("Error Returning All Users For Year:" + year, e);
     }
 }
Beispiel #2
0
 public IList<UniUser> GetAll()
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             return db.UniUsers
                 .Include(u => u.PermissionLevel)
                 .Include(u => u.Photographs)
                 .ToList();
         }
     }
     catch (Exception e)
     {
         throw new Exception("Error Returning All Users", e);
     }
 }
Beispiel #3
0
 public UniUser GetById(int userId)
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             UniUser usr = db.UniUsers.Where(u => u.UserId == userId)
                 .Include(u => u.PermissionLevel)
                 .Include(u => u.Photographs)
                 .SingleOrDefault();
             return usr;
         }
     }
     catch (Exception e)
     {
         throw new Exception("Error Returning User for Id:" + userId, e);
     }
 }
Beispiel #4
0
 public int AddOrUpdate(UniUser user)
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             db.UniUsers.AddOrUpdate(user);
             db.SaveChanges();
             return user.UserId;
         }
     }
     catch (Exception e)
     {
         if (user == null)
         {
             throw new Exception("Error Adding Updating User: User null", e);
         }
         throw new Exception(
             "Error Adding/Updating User: {Id:" + user.UserId + " Email:" + user.EmailAddress + "}", e);
     }
 }
Beispiel #5
0
 public bool Remove(UniUser user)
 {
     try
     {
         using (UniUserDbContext db = new UniUserDbContext(ConnectionString))
         {
             db.UniUsers.Attach(user);
             db.UniUsers.Remove(user);
             db.SaveChanges();
             return true;
         }
     }
     catch (Exception e)
     {
         if (user == null)
         {
             throw new Exception("Error Removing User: User null", e);
         }
         throw new Exception("Error Removing User: {Id:" + user.UserId + " Email:" + user.EmailAddress + "}", e);
     }
 }