public void DeleteIdeaComment(IIdeaDatabaseDataContext dc, IdeaComment ideaComment) { if (ideaComment != null) { dc.IdeaComments.Remove(ideaComment); } }
public void AddIdeaComment(IIdeaDatabaseDataContext dc, IdeaComment ideaComment) { if (ideaComment != null) { dc.IdeaComments.Add(ideaComment); } }
public async Task SendComment(IdeaComment comment) { try { if (_projectDal.AddComment(comment)) { var commentToReturn = new { Id = comment.Id, CommentText = comment.CommentText, UserId = comment.UserId, IdeaId = comment.IdeaId, CreateDate = comment.CreateDate, ParrentComment = comment.ParrentComment, User = _userDal.GetUserById(comment.UserId) }; await Clients.All.SendAsync("RecieveComment", JsonConvert.SerializeObject(commentToReturn)); await Clients.Caller.SendAsync("SuccessfulAdd"); } else { await Clients.Caller.SendAsync("ErrorWhileAdding", "error"); } } catch (Exception e) { await Clients.Caller.SendAsync("ErrorWhileAdding", e); } }
public IdeaCommentDiscussion InsertCommentReply(ResponseBase response, int IdeaCommentId, int UserId, string DiscussionDescription) { IdeaCommentDiscussion ideaCommentDiscussion = null; DatabaseWrapper.databaseOperation(response, (context, query) => { IdeaComment ideaComment = query.GetIdeaCommentById(context, IdeaCommentId); if (ideaComment != null) { ideaCommentDiscussion = new IdeaCommentDiscussion() { IdeaCommentId = ideaComment.IdeaCommentId, UserId = UserId, DiscussionDescription = DiscussionDescription, CreatedDate = DateTime.UtcNow, ModifiedDate = DateTime.UtcNow }; query.AddIdeaCommentDiscussion(context, ideaCommentDiscussion); response.Status = Success; } else { response.ErrorList.Add(Faults.IdeaCommentNotFound); response.Status = Failure; return; } context.SubmitChanges(); } , readOnly: false ); return(ideaCommentDiscussion); }
public RestAPIDeleteIdeaResponse DeleteIdeaComment(ResponseBase response, int IdeaCommentId) { RestAPIDeleteIdeaResponse restAPIDeleteIdeaResponse = new RestAPIDeleteIdeaResponse(); DatabaseWrapper.databaseOperation(response, (context, query) => { IdeaComment ideaComment = query.GetIdeaCommentById(context, IdeaCommentId); if (ideaComment != null) { query.DeleteIdeaComment(context, ideaComment); response.Status = Success; } else { response.ErrorList.Add(Faults.IdeaCommentNotFound); response.Status = Failure; return; } context.SubmitChanges(); } , readOnly: false ); if (response == null && response.ErrorList.Count != 0) { response.ErrorList.Add(Faults.ServerIsBusy); restAPIDeleteIdeaResponse.ErrorList = response.ErrorList; } return(restAPIDeleteIdeaResponse); }
public RESTAPIIdeaCommentInterchange(IdeaComment ideaComment) { List <RESTAPIIdeaDiscussionInterchange> DiscussionList = null; List <RESTAPIIdeaDiscussionInterchange> discussionInterchangeList = null; if (ideaComment != null) { discussionInterchangeList = new List <RESTAPIIdeaDiscussionInterchange>(); IdeaCommentId = ideaComment.IdeaCommentId; IdeaID = ideaComment.IdeaId; CommentDescription = ideaComment.CommentDescription; CreatedDate = ideaComment.CreatedDate.ToString("yyyy'-'MM'-'dd'T'HH':'mm':'ss'.'fff'Z'");; CommentByUserid = ideaComment.CommentByUserId; CommentByUserName = ideaComment.User.FirstName; if (ideaComment.IdeaCommentDiscussions != null) { DiscussionList = new List <RESTAPIIdeaDiscussionInterchange>(); foreach (IdeaCommentDiscussion ideaCommentDiscussion in ideaComment.IdeaCommentDiscussions) { discussionInterchangeList.Add(new RESTAPIIdeaDiscussionInterchange(ideaCommentDiscussion)); } } if (discussionInterchangeList != null && discussionInterchangeList.Count > 0) { DiscussionList.AddRange(discussionInterchangeList); } CommentDiscussion = DiscussionList; } }
private void SetupUI() { loadingCircle = FindViewById <ProgressBar>(Resource.Id.loadingCircle); commentsRecycler = FindViewById <RecyclerView>(Resource.Id.commentsRecycler); emptyState = FindViewById(Resource.Id.empty); commentTb = FindViewById <EditText>(Resource.Id.commentTb); commentBtn = FindViewById <ImageView>(Resource.Id.commentBtn); commentBtn.Enabled = (Global.LoginData != null); commentBtn.RequestFocus(); commentBtn.Click += delegate { if (commentTb.Text.Length > 0) { var now = DateTime.Now; var comment = new IdeaComment { Author = Global.LoginData.Email, Comment = commentTb.Text, Created = GetJavascriptMillis() }; PostComment(comment); } else { Toast.MakeText(this, "Comment cannot be empty", ToastLength.Long).Show(); } }; }
public bool AddComment(IdeaComment comment) { using (var db = new ActiveCitizenContext()) { db.IdeaComment.Add(comment); db.DirectionIdea.Find(comment.IdeaId).CountOfComments++; return(db.SaveChanges() > 1); } }
public async Task <ActionResult> DeleteConfirmed(int id) { IdeaComment ideaComment = await db.IdeaComments.FindAsync(id); db.IdeaComments.Remove(ideaComment); await db.SaveChangesAsync(); return(RedirectToAction("Index")); }
public static TModel FromIdeaComment <TModel>(IdeaComment ideaComment) where TModel : IdeaCommentApiModel, new() { var model = new TModel(); model.Id = ideaComment.Id; model.TenantId = ideaComment.TenantId; model.HtmlBody = ideaComment.HtmlBody; model.IdeaId = ideaComment.IdeaId; return(model); }
public ActionResult Comment(int IdeaID) { var CommentList = context.CommentOnIdeas.Where(x => x.IdeaID == IdeaID).ToList(); var Idea = context.Ideas.Where(x => x.IdeaID == IdeaID).FirstOrDefault(); IdeaComment ic = new IdeaComment(); ic.Idea = Idea; ic.CommentOnIdeas = CommentList; ic.IdeaID = IdeaID; return(View("Comment", ic)); }
public void DeleteIdeaCommentsTest() { RestAPIDeleteIdeaResponse response = new RestAPIDeleteIdeaResponse(); IdeaComment ideaComment = new IdeaComment(); int IdeaCommentId = 1; queryUtilMock.Setup(x => x.GetIdeaCommentById(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <int>())).Returns(ideaComment); submitIdeaMock.Setup(x => x.DeleteIdeaComment(It.IsAny <RestAPIDeleteIdeaResponse>(), It.IsAny <int>())); submitIdeaUtil.DeleteIdeaComment(response, IdeaCommentId); Assert.IsTrue(response.ErrorList.Count == 0); }
public async Task <ActionResult> Edit([Bind(Include = "CommentID,UserID,UserComment,CreationDate,BusinessChannelID")] IdeaComment ideaComment) { if (ModelState.IsValid) { db.Entry(ideaComment).State = EntityState.Modified; await db.SaveChangesAsync(); return(RedirectToAction("Index")); } ViewBag.BusinessChannelID = new SelectList(db.BusinessChannels, "BusinessChannelID", "Title", ideaComment.BusinessChannelID); return(View(ideaComment)); }
public async Task <IActionResult> CreateComment(IdeaComment ideaComment, int ideaId) { var uid = userManager.GetUserId(HttpContext.User); EIdeasUser user = await userManager.FindByIdAsync(uid); Idea idea = db.Ideas.First(i => i.IdeaId == ideaId); ideaComment.EIdeasUser = user; idea.IdeaComments.Add(ideaComment); db.SaveChanges(); return(RedirectToAction("Index", ideaId)); }
// GET: IdeaComments/Details/5 public async Task <ActionResult> Details(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IdeaComment ideaComment = await db.IdeaComments.FindAsync(id); if (ideaComment == null) { return(HttpNotFound()); } return(View(ideaComment)); }
// GET: IdeaComments/Edit/5 public async Task <ActionResult> Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } IdeaComment ideaComment = await db.IdeaComments.FindAsync(id); if (ideaComment == null) { return(HttpNotFound()); } ViewBag.BusinessChannelID = new SelectList(db.BusinessChannels, "BusinessChannelID", "Title", ideaComment.BusinessChannelID); return(View(ideaComment)); }
public ActionResult AddComment(IdeaComment ic) { int user = (int)Session["UserId"]; CommentOnIdeaDL coi = new CommentOnIdeaDL(); int id = ic.IdeaID; coi.UserID = user; coi.IdeaID = ic.IdeaID; coi.Comment = ic.Comment; coi.Name = context.Users.Where(x => x.UserID == user).FirstOrDefault().FirstName; context.CommentOnIdeas.Add(coi); context.SaveChanges(); return(RedirectToAction("Comment", new { IdeaID = id })); }
public async Task <AddOrUpdateIdeaCommentResponse> Handle(AddOrUpdateIdeaCommentRequest request) { var entity = await _context.IdeaComments .SingleOrDefaultAsync(x => x.Id == request.IdeaComment.Id && x.TenantId == request.TenantId); if (entity == null) { _context.IdeaComments.Add(entity = new IdeaComment()); } entity.HtmlBody = request.IdeaComment.HtmlBody; entity.IdeaId = request.IdeaComment.IdeaId; entity.TenantId = request.TenantId; await _context.SaveChangesAsync(); return(new AddOrUpdateIdeaCommentResponse()); }
public ActionResult Commented(IdeaComment NewComment) { NewComment.CreatedDate = DateTime.Now; db.IdeaComments.Add(NewComment); db.SaveChanges(); ICollection <Idea> ideas = new List <Idea>(); if (db.Ideas != null) { ideas = db.Ideas.ToList(); } ICollection <EIdeasUser> users = new List <EIdeasUser>(); if (db.Users != null) { users = db.Users.ToList(); } ICollection <Division> divisions = new List <Division>(); if (db.Divisions != null) { divisions = db.Divisions.ToList(); } ICollection <Unit> units = new List <Unit>(); if (db.Units != null) { units = db.Units.ToList(); } return(View(new IdeaModel { Ideas = ideas, Users = users, Divisions = divisions, Units = units, NewIdea = new Idea(), NewComment = new IdeaComment() })); }
private List <IdeaComment> GenerateComments(JObject result) { List <IdeaComment> comments = new List <IdeaComment>(); foreach (var pair in result) { var comment = new IdeaComment { Author = (string)pair.Value["author"], Comment = (string)pair.Value["comment"], Created = (long)pair.Value["created"], Id = pair.Key }; comments.Add(comment); } return(comments); }
public async Task <IActionResult> UpvoteComment([FromBody] int ideaCommentId) { var uid = userManager.GetUserId(HttpContext.User); EIdeasUser user = await userManager.FindByIdAsync(uid); IdeaComment ideaComment = db.IdeaComments.First(a => a.IdeaCommentId == ideaCommentId); CommentUpDoot commentUpDoot = new CommentUpDoot { IdeaCommentId = ideaCommentId, EIdeasUser = user, CreatedDate = DateTime.Now }; ideaComment.CommentUpDoots.Add(commentUpDoot); db.SaveChanges(); return(StatusCode(200)); }
public async Task <IViewComponentResult> InvokeAsync(Idea entity, IdeaComment reply) { // We always need a entity to display tags if (entity == null) { throw new ArgumentNullException(nameof(entity)); } // Get tags and return view var tags = await _tagStore.GetByEntityIdAsync(entity.Id); return(View(new TagListViewModel() { Topic = entity, Reply = reply, Tags = tags? .Where(t => t.EntityReplyId == (reply?.Id ?? 0)) .OrderByDescending(t => t.TotalEntities) })); }
public async Task <ApiResponse <string> > PostCommentAsync(string dataId, IdeaComment comment) { try { var response = await client.PostAsync($"{dbUrl}/{dataId}/comments.json?auth={token}", new StringContent(JsonConvert.SerializeObject(comment), Encoding.UTF8, "application/json")); if (response.IsSuccessStatusCode) { var data = JObject.Parse(await response.Content.ReadAsStringAsync()); return(new ApiResponse <string>((string)data["name"], string.Empty)); } return(new ApiResponse <string>(null, await response.Content.ReadAsStringAsync())); } catch (Exception e) { return(new ApiResponse <string>(null, GetExceptionError(e))); } }
public void InsertIdeaCommentTest() { RestAPIAddUserCommentResponse response = new RestAPIAddUserCommentResponse(); IdeaComment ideaComment = new IdeaComment(); int UserId = 1; RestAPIAddUserCommentRequest request = new RestAPIAddUserCommentRequest() { IdeaID = 1, CommentDescription = "test" }; queryUtilMock.Setup(x => x.GetIdeaById(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <int>())).Returns(new Idea() { IdeaId = 1, Title = "test" }); submitIdeaMock.Setup(x => x.InsertIdeaComment(It.IsAny <RestAPIAddUserCommentResponse>(), It.IsAny <int>(), It.IsAny <string>(), It.IsAny <int>())).Returns(ideaComment); ideaComment = submitIdeaUtil.InsertIdeaComment(response, request.IdeaID, request.CommentDescription, UserId); Assert.IsTrue(response.ErrorList.Count == 0); }
async Task <ICommandResultBase> ResetEditDetails(Idea entity, IdeaComment reply, IUser user) { var result = new CommandResultBase(); // We need to be authenticated to make changes if (user == null) { return(result.Success()); } if (reply != null) { reply.ModifiedUserId = user.Id; reply.ModifiedDate = DateTimeOffset.UtcNow; reply.EditedUserId = 0; reply.EditedDate = null; var updateResult = await _entityReplyStore.UpdateAsync(reply); if (updateResult != null) { return(result.Success()); } } else { entity.ModifiedUserId = user.Id; entity.ModifiedDate = DateTimeOffset.UtcNow; entity.EditedUserId = 0; entity.EditedDate = null; var updateResult = await _entityStore.UpdateAsync(entity); if (updateResult != null) { return(result.Success()); } } return(result.Success()); }
public void GetIdeaCommentsTest() { RestAPIGetUserCommentsResponse response = new RestAPIGetUserCommentsResponse(); IdeaComment ideaComment = new IdeaComment(); int IdeaId = 1; queryUtilMock.Setup(x => x.GetIdeaComment(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <int>())).Returns(new List <IdeaComment>() { new IdeaComment() { IdeaCommentId = 1, CommentDescription = "test", User = new User() { FirstName = "Sanjay" } } }); submitIdeaMock.Setup(x => x.GetUserComments(It.IsAny <RestAPIGetUserCommentsResponse>(), It.IsAny <int>())); submitIdeaUtil.GetUserComments(response, IdeaId); Assert.IsTrue(response.ErrorList.Count == 0); }
public void InsertCommentReplyTest() { RestAPIAddCommentReplyResponse response = new RestAPIAddCommentReplyResponse(); RestAPIAddCommentReplyRequest request = new RestAPIAddCommentReplyRequest() { IdeaCommentID = 1, DiscussionDescription = "test" }; IdeaComment ideaComment = new IdeaComment(); IdeaCommentDiscussion ideaCommentDiscussion = new IdeaCommentDiscussion(); int UserId = 1; int IdeaCommentId = 1; string DiscussionDescription = "test"; queryUtilMock.Setup(x => x.GetIdeaCommentById(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <int>())).Returns(ideaComment); queryUtilMock.Setup(x => x.AddIdeaCommentDiscussion(It.IsAny <IIdeaDatabaseDataContext>(), It.IsAny <IdeaCommentDiscussion>())); submitIdeaMock.Setup(x => x.InsertCommentReply(It.IsAny <RestAPIAddCommentReplyResponse>(), It.IsAny <int>(), It.IsAny <int>(), It.IsAny <string>())).Returns(ideaCommentDiscussion); submitIdeaUtil.InsertCommentReply(response, IdeaCommentId, UserId, DiscussionDescription); Assert.IsTrue(response.ErrorList.Count == 0); }
public IdeaComment InsertIdeaComment(ResponseBase response, int IdeaID, string CommentDescription, int UserId) { IdeaComment ideaComment = null; DatabaseWrapper.databaseOperation(response, (context, query) => { Idea idea = query.GetIdeaById(context, IdeaID); if (idea != null) { ideaComment = new IdeaComment() { IdeaId = IdeaID, CommentDescription = CommentDescription, CommentByUserId = UserId, CreatedDate = DateTime.UtcNow }; query.AddIdeaComment(context, ideaComment); response.Status = Success; } else { response.ErrorList.Add(Faults.IdeaNotFound); response.Status = Failure; return; } context.SubmitChanges(); } , readOnly: false ); if (response == null && response.ErrorList.Count != 0) { response.ErrorList.Add(Faults.ServerIsBusy); } return(ideaComment); }
private async Task PostComment(IdeaComment comment) { loadingCircle.Visibility = ViewStates.Visible; commentBtn.Enabled = false; var response = await IdeaBagApi.Instance.PostCommentAsync(GetDataId(), comment); if (response.Payload != null) { HideEmptyState(); comment.Id = response.Payload; comments.Add(comment); commentsAdapter.NotifyItemInserted(comments.Count - 1); commentTb.Text = string.Empty; } else { Snackbar.Make(commentBtn, "Couldn't add comment. Please retry.", Snackbar.LengthLong).Show(); } loadingCircle.Visibility = ViewStates.Gone; commentBtn.Enabled = true; }
// -------------------- async Task <ICommandResultBase> ApplyLatestHistoryPoint(Idea entity, IdeaComment reply) { // Get current user var user = await _contextFacade.GetAuthenticatedUserAsync(); // We need to be authenticated to make changes if (user == null) { return(await ResetEditDetails(entity, reply, user)); } // Get newest / most recent history entry var histories = await _entityHistoryStore.QueryAsync() .Take(1, false) .Select <EntityHistoryQueryParams>(q => { q.EntityId.Equals(entity.Id); q.EntityReplyId.Equals(reply?.Id ?? 0); }) .OrderBy("Id", OrderBy.Desc) .ToList(); // No history point, return success if (histories == null) { return(await ResetEditDetails(entity, reply, user)); } // No history point, return success if (histories.Data == null) { return(await ResetEditDetails(entity, reply, user)); } // No history point, return success if (histories.Data.Count == 0) { return(await ResetEditDetails(entity, reply, user)); } var history = histories.Data[0]; // No history available reset edit details if (history == null) { return(await ResetEditDetails(entity, reply, user)); } // Update edit details based on latest history point var result = new CommandResultBase(); if (reply != null) { reply.ModifiedUserId = user.Id; reply.ModifiedDate = DateTimeOffset.UtcNow; reply.EditedUserId = history.CreatedUserId; reply.EditedDate = history.CreatedDate; // Update reply to history point var updateResult = await _entityReplyStore.UpdateAsync(reply); if (updateResult != null) { return(result.Success()); } } else { entity.ModifiedUserId = user.Id; entity.ModifiedDate = DateTimeOffset.UtcNow; entity.EditedUserId = history.CreatedUserId; entity.EditedDate = history.CreatedDate; // Update entity to history point var updateResult = await _entityStore.UpdateAsync(entity); if (updateResult != null) { return(result.Success()); } } return(result.Success()); }