Ejemplo n.º 1
0
        /// <summary>
        /// Deletes and attendee by session id and email
        /// </summary>
        /// <param name="sessionId"></param>
        /// <param name="email"></param>
        /// <returns></returns>
        public bool DeleteByEmail(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("DELETE", BuildRoute($"session/{sessionId}/attendee/{email}"));
            var response = HttpWebClient.SendWebRequest(request);

            error = null;
            bool success = false;

            if (response != null)
            {
                success = response.StatusCode == HttpStatusCode.NoContent;

                if (!success)
                {
                    error = response.ToErrorResponse();
                }
            }

            return(success);
        }
Ejemplo n.º 2
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);
        }
Ejemplo n.º 3
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);
        }
Ejemplo n.º 4
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);
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Deletes a user by user id
        /// </summary>
        /// <param name="userId"></param>
        /// <returns></returns>
        public bool DeleteByUserId(string userId, out ApiErrorResponse error)
        {
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

            var request  = HttpWebClient.CreateWebRequest("DELETE", BuildRoute($"user/{userId}"));
            var response = HttpWebClient.SendWebRequest(request);

            error = null;
            bool success = false;

            if (response != null)
            {
                success = response.StatusCode == HttpStatusCode.NoContent;

                if (!success)
                {
                    error = response.ToErrorResponse();
                }
            }

            return(success);
        }
Ejemplo n.º 6
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);
        }
Ejemplo n.º 7
0
        /// <summary>
        /// Changes user's password.
        /// </summary>
        /// <param name="userId"></param>
        /// <param name="password"></param>
        /// <returns></returns>
        public bool ChangeUserPassword(string userId, string password, out ApiErrorResponse error)
        {
            if (String.IsNullOrEmpty(userId))
            {
                throw new ArgumentNullException(nameof(userId));
            }

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

            var request  = HttpWebClient.CreateWebRequest("PUT", BuildRoute($"user/{userId}/password?password={password}"));
            var response = HttpWebClient.SendWebRequest(request, password);

            error = null;
            bool success = false;

            if (response != null)
            {
                success = response.StatusCode == HttpStatusCode.NoContent;

                if (!success)
                {
                    error = response.ToErrorResponse();
                }
            }

            return(success);
        }
Ejemplo n.º 8
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);
        }
Ejemplo n.º 9
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);
        }
Ejemplo n.º 10
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);
        }
Ejemplo n.º 11
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);
        }