public GroupComment GetLastComment(string userid) { //var comments = groupCommentRepository.GetMany(c => c.UserId == userid).Last(); var comments = new GroupComment(); return(comments); }
public static JToken ToJson(GroupComment c) { var obj = (JObject)ToJson((BaseComment)c); obj["type"] = "GroupComment"; return(obj); }
public async Task <string> Create(GroupComment item, string groupId) { var result = _mapper.Map <GroupCommentDB>(item); var modelUser = (await _dataBase.Find <GroupUserDB>( x => x.UserId == result.CommentatorId && x.GroupId == groupId)).FirstOrDefault(); if (modelUser == null) { throw new ValidationException("User not found"); } var modelBoard = (await _dataBase.Find <GroupBoardDB>( x => x.Id == result.GroupBoardId && x.GroupId == groupId)).FirstOrDefault(); if (modelBoard == null) { throw new ValidationException("Board not found"); } result.Id = Guid.NewGuid().ToString(); result.Modified = DateTime.UtcNow; _dataBase.Create(result); await _dataBase.Save(); return(result.Id); }
public async Task <IActionResult> Edit(int id, [Bind("GroupCommentId,CommentText,GroupUpdateId,CommentDate")] GroupComment groupComment) { if (id != groupComment.GroupCommentId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(groupComment); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GroupCommentExists(groupComment.GroupCommentId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["GroupUpdateId"] = new SelectList(_context.GroupUpdates, "GroupUpdateId", "GroupUpdateId", groupComment.GroupUpdateId); return(View(groupComment)); }
public async Task Delete(GroupComment item, string groupId) { var result = _mapper.Map <GroupCommentDB>(item); var modelUser = (await _dataBase.Find <GroupUserDB>( x => x.UserId == result.CommentatorId && x.GroupId == groupId)).FirstOrDefault(); if (modelUser == null) { throw new ValidationException("User not found"); } var modelBoard = (await _dataBase.Find <GroupBoardDB>( x => x.Id == result.GroupBoardId && x.GroupId == groupId)).FirstOrDefault(); if (modelBoard == null) { throw new ValidationException("Board not found"); } var model = (await _dataBase.Find <GroupCommentDB>( x => x.Id == result.Id && x.CommentatorId == result.CommentatorId)).FirstOrDefault(); if (model == null) { throw new ValidationException("Comment not found"); } _dataBase.Delete(model); await _dataBase.Save(); }
public async Task <ActionResult <GroupComment> > PostGroupComment(GroupComment groupComment) { _context.GroupComments.Add(groupComment); await _context.SaveChangesAsync(); return(CreatedAtAction("GetGroupComment", new { id = groupComment.GroupCommentId }, groupComment)); }
public async Task <IActionResult> PutGroupComment(int id, GroupComment groupComment) { if (id != groupComment.GroupCommentId) { return(BadRequest()); } _context.Entry(groupComment).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!GroupCommentExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
private List <GroupCommentModel> GetChildren(GroupComment comment) { List <GroupCommentModel> results = new List <GroupCommentModel>(); if (comment.HasChildren) { var children = commentService.GetChildCommentsForGroupComment(comment.GroupCommentId).OrderByDescending(gc => gc.PostDate).ToList(); foreach (var child in children) { var user = userService.GetById(child.UserId); var dateWhen = DateTime.UtcNow - child.PostDate; var childrenOfChildren = GetChildren(child); results.Add(new GroupCommentModel { GroupCommentId = child.GroupCommentId, GroupId = child.GroupId, UserId = child.UserId, ParentId = child.ParentId != null ? (int)(child.ParentId) : child.ParentId, FirstName = user.FirstName, LastName = user.LastName, Comment = child.Comment, Date = GetDateString(dateWhen), HasChildren = child.HasChildren, Children = childrenOfChildren }); } } return(results); }
public async Task <IHttpActionResult> Delete([FromUri] string groupId, [FromUri] string boardId, [FromUri] string commentId, [FromUri] string commentatorId) { var item = new GroupComment { Id = commentId, GroupBoardId = boardId, CommentatorId = commentatorId }; await _groupCommentService.Delete(item, groupId); return(Ok()); }
public void CreateComment(GroupComment comment, string userId) { groupCommentRepository.Add(comment); SaveComment(); var groupCommentUser = new GroupCommentUser { UserId = userId, GroupCommentId = comment.GroupCommentId }; groupCommentUserRepository.Add(groupCommentUser); SaveComment(); }
public async Task <IActionResult> Create([Bind("GroupCommentId,CommentText,GroupUpdateId,CommentDate")] GroupComment groupComment) { if (ModelState.IsValid) { _context.Add(groupComment); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["GroupUpdateId"] = new SelectList(_context.GroupUpdates, "GroupUpdateId", "GroupUpdateId", groupComment.GroupUpdateId); return(View(groupComment)); }
public GroupFeedbackProgramme ExportGroupFeedbackProgramme() { Session["email"] = null; //get rating var dt = DataLayer.GetGroupFeedbackProgramme(); var modelList = new List <GroupRating>(); foreach (DataRow item in dt.Rows) { var model = new GroupRating { GroupId = item["GroupId"].ToString(), GroupName = item["GroupName"].ToString(), GroupAveRating = float.Parse(item["GroupAverageRating"].ToString()), OverallRating = float.Parse(item["OverallRating"].ToString()), TimeAllocatedRating = float.Parse(item["TimeAllocatedRating"].ToString()), ClassSizeRating = float.Parse(item["ClassSizeRating"].ToString()), ClassRoomRating = float.Parse(item["ClassRoomRating"].ToString()) }; modelList.Add(model); } //get comments dt = DataLayer.GetGroupFeedbackComments(); var modelComment = new List <GroupComment>(); foreach (DataRow item in dt.Rows) { var _model = new GroupComment { FullName = item["FullName"].ToString(), Comment = item["PComment"].ToString(), }; modelComment.Add(_model); } var progmodel = new GroupFeedbackProgramme(); progmodel.GroupRatings = modelList; progmodel.GroupComments = modelComment; return(progmodel); }
public void TestCaseSetup() { _groupComment = new GroupComment { Id = "00000000-0000-0000-0000-000000000000", Comment = "comment", CommentatorId = "2", GroupBoardId = "00000000-0000-0000-0000-000000000000" }; _groupCommentDB = new GroupCommentDB { Id = "00000000-0000-0000-0000-000000000000", Comment = "comment", CommentatorId = "2", GroupBoardId = "00000000-0000-0000-0000-000000000000" }; _groupBoardDB = new GroupBoardDB { Id = "00000000-0000-0000-0000-000000000000", CreatorId = "2", Information = "Some product", Name = "Best", Created = DateTime.UtcNow, Deleted = null, IsNotDeleted = true, Modified = DateTime.UtcNow, GroupId = "00000000-0000-0000-0000-000000000001", GroupProducts = null }; _groupUserDB = new GroupUserDB { GroupId = "00000000-0000-0000-0000-000000000001", RightToCreateBoards = true }; _groupRepositoryMock = new Mock <IGroupRepository>(); var config = new MapperConfiguration(cfg => { cfg.AddProfile(new GroupProfile()); cfg.AddProfile(new GroupBoardProfile()); cfg.AddProfile(new GroupProductProfile()); cfg.AddProfile(new GroupUserProfile()); cfg.AddProfile(new GroupCommentProfile()); }); _mapper = (new Mapper(config)).DefaultContext.Mapper; _groupCommentService = new GroupCommentService(_groupRepositoryMock.Object, _mapper); _selectedCommentList = new List <GroupCommentDB>(); _selectedBoardList = new List <GroupBoardDB>(); _selectedUserList = new List <GroupUserDB>(); }
/// <summary> /// Adds a group comment to the database /// </summary> /// <param name="groupComment"></param> /// <returns></returns> public int AddGroupComment(GroupComment groupComment) { if (groupComment != null) { _context.GroupComment.Add(groupComment); if (groupComment.ParentId != null) { var entity = _context.GroupComment.FirstOrDefault(gc => gc.GroupCommentId == groupComment.ParentId); if (!entity.HasChildren) { entity.HasChildren = true; _context.GroupComment.Update(entity); } } _context.SaveChanges(); } return(groupComment.GroupCommentId); }
public async Task <IHttpActionResult> Update([FromUri] string groupId, GroupComment item) { await _groupCommentService.Update(item, groupId); return(Ok(item)); }