public async Task <HttpResponseMessage> FindAll()
        {
            try
            {
                // Get list of questions for the survey.
                var request = await ApiEndpoints.Forums.AppendPathSegments("groups")
                              .GetAsync();

                var entities = request.Content.ReadAsAsync <List <ForumGroup> >().Result;

                // Return the data
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(entities,
                                                         Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }
Esempio n. 2
0
        public async Task <HttpResponseMessage> FindByUrl(string forumUrlName, string urlName)
        {
            try
            {
                // Get list of questions for the survey.
                var request = await ApiEndpoints.Forums.AppendPathSegments($"threads/findbyurl/{forumUrlName}/{urlName}")
                              .GetAsync();

                var entities = request.Content.ReadAsAsync <ForumThread>().Result;

                // Return the data
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(entities,
                                                         Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }
Esempio n. 3
0
        public async Task <HttpResponseMessage> FetchFullUrl(int id)
        {
            try
            {
                // Get list of questions for the survey.
                var request = await ApiEndpoints.Forums.AppendPathSegments($"posts/fullurl/{id}")
                              .GetAsync();

                var url = request.Content.ReadAsAsync <string>().Result;

                // Return the data
                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(url,
                                                         Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }
Esempio n. 4
0
        public async Task <HttpResponseMessage> IsLoggedOn()
        {
            try
            {
                var authToken = SecurityHelper.GetAuthToken(Request);
                var req       = await ApiEndpoints.Users.AppendPathSegments("users/isloggedon")
                                .WithOAuthBearerToken(authToken)
                                .GetAsync();

                var authenticated = req.Content.ReadAsAsync <bool>().Result;

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(authenticated, Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }
Esempio n. 5
0
        public async Task <HttpResponseMessage> Login([FromBody] LoginRequest model)
        {
            if (!ModelState.IsValid)
            {
                return(CommonHttpResponse.InvalidModelStateResponse(ModelState));
            }

            try
            {
                var login = await ApiEndpoints.Users.AppendPathSegments("users/login").PostJsonAsync(model);

                var user = login.Content.ReadAsAsync <AuthenticationModel>().Result;

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(user, Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }
Esempio n. 6
0
        public async Task <HttpResponseMessage> Register([FromBody] RegistrationRequest model)
        {
            try
            {
                var register = await ApiEndpoints.Users.AppendPathSegment("users/register")
                               .PostJsonAsync(model);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(true, Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }
Esempio n. 7
0
        public async Task <HttpResponseMessage> Add(ForumThread request)
        {
            try
            {
                // Save the record away
                var postRequest = await ApiEndpoints.Forums.AppendPathSegments($"threads")
                                  .PostJsonAsync(request);

                return(new HttpResponseMessage(HttpStatusCode.OK)
                {
                    Content = new ObjectContent <object>(null,
                                                         Configuration.Formatters.JsonFormatter)
                });
            }
            catch (FlurlHttpException ex)
            {
                return(CommonHttpResponse.FlurlExceptionResponse(ex, Request));
            }
            catch (Exception ex)
            {
                return(CommonHttpResponse.GenericExceptionResponse(ex, Request));
            }
        }