Esempio n. 1
0
        public HttpResponseMessage GetApiKey(string provider)
        {
            try
            {
                ItemResponse <string> resp = new ItemResponse <string>();
                //Get the api key from the database based on the provider sent in
                switch (provider)
                {
                case "linkedin": resp.Item = _configService.GetConfigValueByName("linkedin:APIKey").ConfigValue;
                    break;

                case "facebook": resp.Item = _configService.GetConfigValueByName("facebook:APPKey").ConfigValue;
                    break;

                case "google": resp.Item = _configService.GetConfigValueByName("google:clientId").ConfigValue;
                    break;

                default: return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "This provider could not be found"));
                }
                return(Request.CreateResponse(HttpStatusCode.OK, resp));
            }
            catch (Exception ex)
            {
                //If an exception occurs log it and return an error
                log.Error("Error getting " + provider + " api key", ex);
                return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, "Something went wrong"));
            }
        }
Esempio n. 2
0
 public HttpResponseMessage GetCommentsByForumId(ForumPageRequest model)
 {
     try
     {
         //Checks that the passed in model is valid
         if (ModelState.IsValid)
         {
             ItemResponse <ForumCommentsViewModel> resp = new ItemResponse <ForumCommentsViewModel>();
             //Gets the list of forum comments
             resp.Item = _service.GetAllCommentsByForumId(model);
             //Loops through each comment and convert the file ids into the correct file path to show on the page
             foreach (ForumComment comment in resp.Item.Comments)
             {
                 string serverPath = _configServices.GetConfigValueByName("AWS:BaseURL").ConfigValue;
                 comment.UploadedFiles = new List <UploadedFile>();
                 foreach (int fileId in comment.FileIds)
                 {
                     UploadedFile upFile   = _fileService.GetById(fileId);
                     string       filePath = Path.Combine(serverPath, upFile.SystemFileName);
                     upFile.SystemFileName = filePath;
                     comment.UploadedFiles.Add(upFile);
                 }
                 //Gets the user's profile picture
                 comment.Person.ProfilePic = Path.Combine(serverPath, comment.Person.ProfilePic);
             }
             return(Request.CreateResponse(HttpStatusCode.OK, resp));
         }
         else
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ModelState));
         }
     }
     catch (Exception ex)
     {
         //Log any exception that occurs
         log.Error("Error getting comments with forum Id: " + model.ForumId, ex);
         return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message));
     }
 }