示例#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));
     }
 }
示例#2
0
        public ForumCommentsViewModel GetAllCommentsByForumId(ForumPageRequest model)
        {
            //Creates a dictionary of forum comments in order to insert data directly into a specific comment
            Dictionary <int, ForumComment> CommentDict = new Dictionary <int, ForumComment>();
            ForumCommentsViewModel         fcModel     = new ForumCommentsViewModel();

            //Initializes the two lists so we can insert things into them
            fcModel.Comments    = new List <ForumComment>();
            fcModel.TeamMembers = new List <ForumCommentPerson>();
            //Runs the stored procedure
            DataProvider.ExecuteCmd(
                "Forum_Comment_SelectByForumId",
                inputParamMapper : delegate(SqlParameterCollection paramCol)
            {
                paramCol.AddWithValue("@ForumId", model.ForumId);
                paramCol.AddWithValue("@PageSize", model.PageSize);
                paramCol.AddWithValue("@PageNum", model.PageNum);
            },
                singleRecordMapper : delegate(IDataReader reader, short set)
            {
                //Switches between each sql select statement
                switch (set)
                {
                //Gets the project information
                case 0:
                    fcModel.Name        = reader.GetSafeString(0);
                    fcModel.Description = reader.GetSafeString(1);
                    break;

                //Gets the total number of comments
                case 1:
                    fcModel.TotalComments = reader.GetSafeInt32(0);
                    break;

                //Gets the list of comments
                case 2:
                    ForumComment fc = MapComment(reader);
                    fc.FileIds      = new List <int>();
                    CommentDict.Add(fc.Id, fc);
                    fcModel.Comments.Add(fc);
                    break;

                //Gets the list of files and adds them to their comment
                case 3:
                    int fCommId = reader.GetSafeInt32(0);
                    int fileId  = reader.GetSafeInt32(1);
                    CommentDict[fCommId].FileIds.Add(fileId);
                    break;

                //Gets the information for each person and adds them to their comment
                case 4:
                    ForumCommentPersonFull cp = new ForumCommentPersonFull();
                    int index                = 0;
                    int cpId                 = reader.GetSafeInt32(index++);
                    cp.FirstName             = reader.GetSafeString(index++);
                    cp.LastName              = reader.GetSafeString(index++);
                    cp.Role                  = reader.GetSafeString(index++);
                    cp.IsCaptain             = reader.GetSafeBool(index++);
                    cp.ProfilePic            = reader.GetSafeString(index++);
                    CommentDict[cpId].Person = cp;
                    break;

                //Gets comment quotes and adds them to their comment
                case 5:
                    ForumCommentQuote cq = new ForumCommentQuote();
                    int idx               = 0;
                    int Id                = reader.GetSafeInt32(idx++);
                    cq.Text               = reader.GetSafeString(idx++);
                    cq.FirstName          = reader.GetSafeString(idx++);
                    cq.LastName           = reader.GetSafeString(idx++);
                    cq.CreatedDate        = reader.GetSafeDateTime(idx++);
                    CommentDict[Id].Quote = cq;
                    break;

                //Gets the list of team members for this forum
                case 6:
                    ForumCommentPerson p = new ForumCommentPerson();
                    int i       = 0;
                    p.FirstName = reader.GetSafeString(i++);
                    p.LastName  = reader.GetSafeString(i++);
                    p.IsCaptain = reader.GetSafeBool(i++);
                    fcModel.TeamMembers.Add(p);
                    break;
                }
            }
                );
            return(fcModel);
        }