Esempio n. 1
0
        /// <summary>
        /// Get attendee by session id and email
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public AttendeeView GetByEmail(string sessionId, string email, out ApiErrorResponse error)
        {
            if (String.IsNullOrEmpty(sessionId))
            {
                throw new ArgumentNullException(nameof(sessionId));
            }

            if (String.IsNullOrEmpty(email))
            {
                throw new ArgumentNullException(nameof(email));
            }

            var          request      = HttpWebClient.CreateWebRequest("GET", BuildRoute($"session/{sessionId}/attendee/{email}"));
            var          response     = HttpWebClient.SendWebRequest(request);
            AttendeeView attendeeView = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    attendeeView = result.ToObject <AttendeeView>();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(attendeeView);
        }
Esempio n. 2
0
        /// <summary>
        /// Updates a user
        /// </summary>
        /// <param name="user"></param>
        /// <returns></returns>
        public UserView UpdateUser(string user_id, PostUserView user, out ApiErrorResponse error)
        {
            if (user is null)
            {
                throw new ArgumentNullException(nameof(user));
            }

            var      request  = HttpWebClient.CreateWebRequest("PUT", BuildRoute($"user/{user_id}"));
            var      response = HttpWebClient.SendWebRequest(request, user);
            UserView userView = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    userView = result.ToObject <UserView>();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(userView);
        }
Esempio n. 3
0
        /// <summary>
        /// Search for attendees in a specefic session
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="attendanceCode"></param>
        /// <returns></returns>
        public List <AttendeeView> SearchAttendees(string sessionId, AttendeeFilter filter, out ApiErrorResponse error)
        {
            if (String.IsNullOrEmpty(sessionId))
            {
                throw new ArgumentNullException(nameof(sessionId));
            }

            var filterQuery = filter.ToQueryString();
            var request     = HttpWebClient.CreateWebRequest("GET", BuildRoute($"session/{sessionId}/attendees?{filterQuery}"));
            var response    = HttpWebClient.SendWebRequest(request);
            List <AttendeeView> attendeeViews = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    attendeeViews = result.ToObject <List <AttendeeView> >();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(attendeeViews);
        }
Esempio n. 4
0
        /// <summary>
        /// Gets a user by username
        /// </summary>
        /// <param name="username"></param>
        /// <returns></returns>
        public UserView GetUserByUsername(string username, out ApiErrorResponse error)
        {
            if (String.IsNullOrEmpty(username))
            {
                throw new ArgumentNullException(nameof(username));
            }

            var      request  = HttpWebClient.CreateWebRequest("GET", BuildRoute($"user/{username}"));
            var      response = HttpWebClient.SendWebRequest(request);
            UserView userView = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    userView = result.ToObject <UserView>();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(userView);
        }
Esempio n. 5
0
        /// <summary>
        /// Creates a session
        /// </summary>
        /// <param name="session">A session view object which holds session data</param>
        /// <returns>The created session object is returned. If an error occurs, error information is returned as well.</returns>
        public SessionView CreateSession(PostSessionView session, out ApiErrorResponse error)
        {
            if (session is null)
            {
                throw new ArgumentNullException(nameof(session));
            }

            var         request     = HttpWebClient.CreateWebRequest("POST", BuildRoute("session"));
            var         response    = HttpWebClient.SendWebRequest(request, session);
            SessionView sessionView = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.Created)
                {
                    sessionView = result.ToObject <SessionView>();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(sessionView);
        }
        public static ApiErrorResponse ToErrorResponse(this HttpWebResponse response, string content = null)
        {
            ApiErrorResponse apiErrorResponse = null;

            if (response is null)
            {
                return(null);
            }

            try
            {
                if (content is null)
                {
                    content = HttpWebClient.GetResponseBody(response);
                }
                if (response.StatusCode == HttpStatusCode.Unauthorized)
                {
                    apiErrorResponse = new ApiErrorResponse(ApiErrorCode.Unauthorized);
                }
                else
                {
                    apiErrorResponse = content.ToObject <ApiErrorResponse>();
                }
            }
            finally
            {
                if (apiErrorResponse is null)
                {
                    apiErrorResponse = new ApiErrorResponse(ApiErrorCode.None);
                }
                apiErrorResponse.HttpStatusCode = response.StatusCode;
            }
            return(apiErrorResponse);
        }
Esempio n. 7
0
        /// <summary>
        /// Adds multiple attendees to a session
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="attendees"></param>
        /// <returns></returns>
        public AttendeesPostResult AddMultiple(string sessionId, IEnumerable <PostAttendeeView> attendees, out ApiErrorResponse error)
        {
            if (String.IsNullOrEmpty(sessionId))
            {
                throw new ArgumentNullException(nameof(sessionId));
            }

            if (attendees is null || attendees.Count() == 0)
            {
                throw new ArgumentException(nameof(attendees));
            }

            var request  = HttpWebClient.CreateWebRequest("POST", BuildRoute($"session/{sessionId}/attendees"));
            var response = HttpWebClient.SendWebRequest(request, attendees);

            AttendeesPostResult resultView = new AttendeesPostResult();

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    resultView = result.ToObject <AttendeesPostResult>();
                }
                else
                {
                    error = response.ToErrorResponse();
                }

                if (error != null && error.Code == ApiErrorCode.MultipleErrors && error.Details != null)
                {
                    resultView.rejected = JsonConvert.DeserializeObject <List <MultipleResponseView> >(JsonConvert.SerializeObject(error.Details));
                }
            }

            return(resultView);
        }
Esempio n. 8
0
        /// <summary>
        /// Search Users using user filter
        /// </summary>
        /// <param name="filter">UserFilter Model</param>
        /// <returns>A user view list object and error info if error occurs</returns>
        public List <UserView> SearchUsers(UserFilter filter, out ApiErrorResponse error)
        {
            var             request   = HttpWebClient.CreateWebRequest("GET", BuildRoute($"user?{filter.ToQueryString()}"));
            var             response  = HttpWebClient.SendWebRequest(request);
            List <UserView> userViews = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    userViews = result.ToObject <List <UserView> >();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(userViews);
        }
Esempio n. 9
0
        /// <summary>
        /// Search Sessions using session filter
        /// </summary>
        /// <param name="filter">SessionFilter Model</param>
        /// <returns>A session view list object and error info if error occurs</returns>
        public List <SessionView> SearchSessions(SessionFilter filter, out ApiErrorResponse error)
        {
            string             query         = filter.ToQueryString();
            var                request       = HttpWebClient.CreateWebRequest("GET", BuildRoute($"session?{query}"));
            var                response      = HttpWebClient.SendWebRequest(request);
            List <SessionView> sessionsViews = null;

            error = null;

            if (response != null)
            {
                string result = HttpWebClient.GetResponseBody(response);
                if (response.StatusCode == HttpStatusCode.OK)
                {
                    sessionsViews = result.ToObject <List <SessionView> >();
                }
                else
                {
                    error = response.ToErrorResponse();
                }
            }

            return(sessionsViews);
        }