예제 #1
0
        public async Task <Session> UpdateSessionCount(SessionOperationViewModel sessionOperationViewModel)
        {
            using (var db = new MercuryDataContext())
            {
                var session
                    = await db.Sessions
                      .Where(m => m.Id == sessionOperationViewModel.SessionId)
                      .FirstOrDefaultAsync();

                switch (sessionOperationViewModel.SessionOperation)
                {
                case SessionOperationEnum.INCREMENT:
                    session.CurrentCount = session.CurrentCount + 1;
                    break;

                case SessionOperationEnum.DECREMENT:
                    var count = session.CurrentCount - 1;
                    session.CurrentCount = count >= 0 ? count : 0;
                    break;

                default: break;
                }

                session.DateModified      = DateTime.UtcNow;
                session.UpdatedTimesCount = session.UpdatedTimesCount + 1;

                db.Sessions.Update(session);
                await db.SaveChangesAsync();

                return(session);
            }
        }
예제 #2
0
 public async Task DeleteSession(Session session)
 {
     using (var db = new MercuryDataContext())
     {
         db.Sessions.Remove(session);
         await db.SaveChangesAsync();
     }
 }
예제 #3
0
 public async Task CreateSession(Session session)
 {
     using (var db = new MercuryDataContext())
     {
         db.Sessions.Add(session);
         await db.SaveChangesAsync();
     }
 }
예제 #4
0
 public async Task CreateNewUser(User user)
 {
     using (var db = new MercuryDataContext())
     {
         db.Users.Add(user);
         await db.SaveChangesAsync();
     }
 }
예제 #5
0
        public async Task RemoveUserFromSession(User user, Session session)
        {
            using (var db = new MercuryDataContext())
            {
                var existingUserSession
                    = await db.UserSessions
                      .Where(s => s.UserId == user.Id && s.SessionId == session.Id)
                      .FirstOrDefaultAsync();

                db.UserSessions.Remove(existingUserSession);
                await db.SaveChangesAsync();
            }
        }
예제 #6
0
        public async Task AddUserToSession(User user, Session session)
        {
            using (var db = new MercuryDataContext())
            {
                var existingUserSession
                    = await db.UserSessions
                      .Where(s => s.UserId == user.Id && s.SessionId == session.Id)
                      .FirstOrDefaultAsync();

                if (existingUserSession != null)
                {
                    return;
                }

                var sessionUser = new UserSession
                {
                    UserId    = user.Id,
                    SessionId = session.Id
                };

                db.UserSessions.Add(sessionUser);
                await db.SaveChangesAsync();
            }
        }