public StationResponse Post(StationRequest request) { this.log.Debug("Got POST request: " + request); var session = this.GetSession() as CustomUserSession; if (session == null) { // This really shouldn't happen since we have attributed for authenticate this.log.Error("Session is null in POST request."); throw new Exception("You need to authenticate"); } this.logic.CurrentUser = session.User; this.log.Debug("User is " + this.logic.CurrentUser); if (string.IsNullOrEmpty(request.StationId)) { this.log.Debug("Adding a station."); return new StationResponse( this.logic.AddStation(request.CompetitionId, request.GetDatabaseStation())); } this.log.Debug("Updating a station."); return new StationResponse( this.logic.UpdateStation( request.CompetitionId, request.GetDatabaseStation())); }
/// <summary> /// The any. /// </summary> /// <param name="request"> /// The request. /// </param> /// <returns> /// The <see cref="CompetitionResponse"/>. /// </returns> public List<StationResponse> Get(StationRequest request) { try { this.log.DebugFormat("Got GET request: {0}.", request); var authSession = this.GetSession() as CustomUserSession; this.logic.CurrentUser = authSession == null ? null : authSession.User; var stations = this.logic.GetStations(request.CompetitionId); var responses = (from dbstation in stations select new StationResponse(dbstation)).ToList().OrderBy(x => x.StationNumber); return responses.ToList(); } catch (Exception exception) { this.log.ErrorFormat("Exception while retrieving stations from request ({0}): {1}", request, exception); throw; } }