Esempio n. 1
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));
     }
 }