private void LoadStoredSessions() { var settings = new UserSettings(); try { var sessions = _sessionRepository.ReadXml(settings.SessionXMLFilename); _sessionRepository.Add(sessions); } catch (InvalidOperationException) { } PlayingSessions = PlayingSession.GroupToPlayingSessions(_sessionRepository.GetAll()); }
public Session CreateSession(string sessionKey, int customerId) { var existingSession = _sessionRepository.GetSingleBySessionKey(sessionKey); if (existingSession != null) { return(existingSession); } var session = new Session() { SessionKey = sessionKey, StoreId = 1, UserId = 1, CustomerId = customerId }; try { _sessionRepository.Add(session); _sessionRepository.Commit(); } catch (Exception ex) { Console.WriteLine(ex.Message); Console.WriteLine(ex.StackTrace); } return(session); }
public HttpResponseMessage Post(string username, string password) { var user = _userRepository.Get(username, password); if (user == null) { return(Request.CreateResponse(HttpStatusCode.NotFound, new[] { new Error { FriendlyMessage = "User not found", Type = "not-found", } })); } var session = Persistence.Models.UserSession.Create(user); _sessionRepository.Add(session); var cookie = CreateSessionCookie(session.Token, DateTime.UtcNow.AddYears(1)); var response = new HttpResponseMessage(); response.Headers.AddCookies(new[] { cookie }); return(response); }
public IActionResult Create(Session session, SessionViewModel svm, User user = null) { if (ModelState.IsValid) { IEnumerable <Formula> formulasOfDay = _formulaRepository.GetByTrainingDay(_trainingDayRepository.getById(svm.TrainingDayId)); IList <Member> members = new List <Member>(); foreach (var formula in formulasOfDay) { foreach (var member in _userRepository.GetByFormula(formula)) { members.Add(member); } } IEnumerable <Member> membersSession = new List <Member>(members); Teacher t = (Teacher)_userRepository.GetByEmail(user.Email); session.PutFormulas(formulasOfDay.ToList()); session.Teacher = t; session.Members = membersSession; session.TrainingDay = _trainingDayRepository.getById(svm.TrainingDayId); if (session.SessionId == svm.SessionId) { _sessionRepository.Add(session); _sessionRepository.SaveChanges(); } svm.Change(session); return(View("Register", svm)); } return(RedirectToAction(nameof(Create))); }
public async Task <Session> BeginSession( string userName, string accountId, string clientId, string accessToken, bool isSupportUser, string deviceKey) { await slimLock.WaitAsync(); try { var existingSession = isSupportUser ? await sessionRepository.GetByUser(userName) : await sessionRepository.GetByAccount(accountId); if (existingSession?.SameDevice(deviceKey) ?? false) { existingSession = existingSession.AddToken(accessToken); await sessionRepository.Update(existingSession); logger.LogDebug($"Session resolved by existing cache. {nameof(userName)}: {userName}, {nameof(accountId)}: {accountId}, {nameof(existingSession.SessionId)}: {existingSession.SessionId}, {nameof(existingSession.IsSupportUser)}: {existingSession.IsSupportUser}."); return(existingSession); } var sessionId = await GenerateSessionId(); var newSession = new Session(userName, sessionId, accountId, accessToken, clientId, isSupportUser, deviceKey); await sessionRepository.Add(newSession); if (!newSession.IsSupportUser) { await activityService.PublishActivity(newSession, SessionActivityType.Login); } else if (!string.IsNullOrEmpty(newSession.AccountId)) { await MakeAndPublishOnBehalfActivity(SessionActivityType.OnBehalfSupportConnected, newSession); } if (existingSession != null) { await TerminateSession(existingSession, SessionActivityType.DifferentDeviceTermination); logger.LogWarning(StatusCode.IF_ATH_502.ToMessage()); } logger.LogWarning(StatusCode.IF_ATH_501.ToMessage()); return(newSession); } finally { slimLock.Release(); } }
public int Post(Session session) { if (session == null) { throw new HttpResponseException(new HttpResponseMessage(HttpStatusCode.BadRequest)); } ValidateEventAuthorization(session.EventDefinitionId); return(_sessionRepository.Add(session)); }
public void GenerateSession(Admin loggedUser) { Session s = new Session() { Id = Guid.NewGuid(), AdminId = loggedUser.Id }; sessionRepository.Add(s); sessionRepository.SaveChanges(); }
public async Task GenerateSession(User loggedUser) { Session s = new Session() { Id = Guid.NewGuid(), UserId = loggedUser.Id }; sessionRepository.Add(s); await sessionRepository.SaveChangesAsync().ConfigureAwait(false); }
public Response <string> Create(string accessKey) { var computerRepository = _repositoryFactory.GetComputerRepository(); var computer = computerRepository.Get(accessKey); var session = Persistence.Models.WebHookSession.Create(computer); _sessionRepository.Add(session); return(Response.Create(session.Token)); }
public Task <Unit> Handle(InitSessionRequest request, CancellationToken cancellationToken) { var session = new Session( request.RefreshToken, request.UserId, request.Token, expiresOn: dateTimeOffsetService.UtcNow().Add(request.ValidFor), createdOn: dateTimeOffsetService.UtcNow()); sessionRepository.Add(session); return(Unit.Task); }
/// <summary> /// No checks are being made here. Function assumes that you pass proper data. /// </summary> /// <param name="parameters"></param> /// <returns></returns> public Session CreateSession(CreateSessionParameters parameters) { var session = new Session() { CitizenID = parameters.CitizenID, Cookie = CreateCookie(parameters.IP, DateTime.Now, parameters.CitizenID), ExpirationDate = DateTime.Now + TimeSpan.FromHours(1), IP = parameters.IP, RememberMe = parameters.RememberMe }; if (parameters.RememberMe) { session.ExpirationDate = session.ExpirationDate.AddDays(7); } var citizen = citizensRepository.GetById(session.CitizenID); citizen.LastActivityDay = GameHelper.CurrentDay; sessionRepository.Add(session); sessionRepository.SaveChanges(); return(session); }
private void SaveSession(Session session) { bool isUpdate = session.SessionId > 0; if (isUpdate) { var sessionToUpdate = _sessionRepository.Get(session.SessionId); MapSession(sessionToUpdate, session); _sessionRepository.Update(sessionToUpdate); } else { _sessionRepository.Add(session); } }
public async Task <SignalRMessage> ExecuteAsync(StartSessionCommand command, SignalRMessage previousResult) { var session = new Models.Session() { Id = Guid.NewGuid() }; await _sessionRepository.Add(session); return(new SignalRMessage { Arguments = new object[] { session }, GroupName = null, Target = "startSessionCommandNotification", }); }
public Core.Models.Result.Result Add(string code, string userId, string ip) { SessionEntity session = new SessionEntity( ip: ip, userId: userId, code: code); bool addResult = _sessionRepository.Add(session); if (!addResult) { _logger.LogError($"Failed to add session. UserId {userId}"); return(Core.Models.Result.Result.Fail("error", "Error")); } return(Core.Models.Result.Result.Ok()); }
public long Add(SessionAddCommand session) { var sessionAdd = Mapper.Map <SessionAddCommand, Session>(session); var movie = MovieRepository.GetById(session.MovieId); sessionAdd.Movie = movie; sessionAdd.setHour(); sessionAdd.SetDuration(); sessionAdd.SetEndDate(); var newSession = SessionRepository.Add(sessionAdd); return(newSession.Id); }
public Session StartSession(int userId, DateTime timeStamp) { var testSession = _sessionRepository.GetLastSessionForUser(userId); string errorMessage; if (_sessionValidator.IsActiveSession(testSession, out errorMessage)) { throw new Exception($"{errorMessage}"); } var createdAt = timeStamp; var expiresAt = createdAt + _sessionTimeout; var session = new Session(userId, createdAt, expiresAt, SessionStatus.ACTIVE); _sessionRepository.Add(session); _logger.LogInformation("Start sessionId:{0} for userId:{1}", session.SessionID, userId); return(session); }
public async Task <Response> Handle(Request request, CancellationToken cancellationToken) { var user = await _context.Users .SingleOrDefaultAsync(x => x.Username.ToLower() == request.Username.ToLower()); if (user == null) { throw new DomainException("Invalid Username!"); } if (_passwordHasher.HashPassword(user.Salt, request.Password) != user.Password) { throw new DomainException("Invalid Password!"); } var activeSessions = await _repository.GetConnectedSessionsAsync(); if (activeSessions.Count() >= _authenticationSettings.Value.MaximumUsers) { throw new DomainException("Exceeded Maximum Users!"); } if (activeSessions.Where(x => x.Username == request.Username).SingleOrDefault() != null) { throw new DomainException("Already logged In!"); } var accessToken = _tokenManager.Issue(request.Username); _repository.Add(new Session() { AccessToken = accessToken, Username = request.Username, SessionStatus = SessionStatus.LoggedIn }); await _repository.SaveChangesAsync(cancellationToken); return(new Response() { AccessToken = accessToken, UserId = user.UserId }); }
public IActionResult Create(Session model) { if (ModelState.IsValid) { Session newSession = new Session { ClassName = model.ClassName, InstructorName = model.InstructorName, SessionStartTime = model.SessionStartTime, SessionEndTime = model.SessionEndTime, Day = model.Day }; _sessionRepository.Add(newSession); return(RedirectToAction("index")); } return(View()); }
public Session GetSession(User user) { Session session = _sessionRepository.Find(s => s.UserId == user.Id); if (session == null) { session = new Session() { UserId = user.Id, ExpireDate = DateTime.Now, Token = Convert.ToBase64String(Guid.NewGuid().ToByteArray()) }; _sessionRepository.Add(session); } else { session.ExpireDate = DateTime.Now; _sessionRepository.Update(session); } return(session); }
public IActionResult Create() { int weekday = ((int)DateTime.Now.DayOfWeek == 0) ? 7 : (int)DateTime.Now.DayOfWeek; if (!_formulaRepository.GetByWeekDay(weekday).Any()) { TempData["error"] = $"Er zijn geen formules gevonden die vandaag plaatsvinden!"; return(RedirectToAction("Index", "Home")); } if (_sessionRepository.GetLatest() != null && _sessionRepository.GetLatest().Date == DateTime.Now.Date) { TempData["error"] = $"De sessie van vandaag is al gedaan!"; return(RedirectToAction("Index", "Home")); } Session sessie = new Session { Day = (Weekday)weekday, Date = DateTime.Now.Date, Attendances = new List <Attendance>() }; sessie.StateSerialized = JsonConvert.SerializeObject(new RegistrationState(sessie).GetType()); _sessionRepository.Add(sessie); _sessionRepository.SaveChanges(); return(RedirectToAction("Index", "Session")); }
public ISession Add(ISession session) { return(_sessionRepository.Add(session)); }
private int DownloadAndSaveSessionData(string eventName, string year) { var countOfSessions = 0; var sessionFeed = new SessionFeed(eventName, year); using (var webClient = new System.Net.WebClient()) { try { webClient.Headers.Add(System.Net.HttpRequestHeader.ContentType, "application/json; charset=utf-8"); var sessionJson = webClient.DownloadString(sessionFeed.SessionFeedUrl); var sessionList = JsonConvert.DeserializeObject <List <Session> >(sessionJson); if (sessionList != null) { //de-dup sessionList = sessionList.Distinct().ToList(); foreach (var session in sessionList) { session.EventYear = year; session.EventName = eventName; var foundSession = _sessionRepository.FindByTitleAndEventYear(session.Title, year); if (foundSession == null) { var insertedSession = _sessionRepository.Add(session); session.Id = insertedSession.Id; } } countOfSessions = sessionList.Count; foreach (var s in sessionList) { //Save tags to categories table SaveSessionCategories(s.Id, s.Tags); //Save all media if (!string.IsNullOrEmpty(s.Wmvhq)) { SaveMediaData("wmvhigh", s.Wmvhq, s.Id); } if (!string.IsNullOrEmpty(s.Wmv)) { SaveMediaData("wmv", s.Wmv, s.Id); } if (!string.IsNullOrEmpty(s.Mp4high)) { SaveMediaData("mp4high", s.Mp4high, s.Id); } if (!string.IsNullOrEmpty(s.Mp4med)) { SaveMediaData("mp4med", s.Mp4med, s.Id); } if (!string.IsNullOrEmpty(s.Mp4low)) { SaveMediaData("mp4", s.Mp4low, s.Id); } } } } catch (System.Net.WebException webExc) { Debug.WriteLine(webExc.ToString()); } //catch (Exception) //{ // throw; //} } return(countOfSessions); }
private static void AddToDataBase() { _repository.Add(GameSessionStatistic); }
public void AddSession(Session session) { _sessionRepository.Add(session); _sessionRepository.SaveChanges(); }