public RatingDTO GetRating(long id) { var lawyer = LawyerRepository.Get(s => s.Id == id, includeProperties: "Reviews,Reviews.User,Reviews.Replies,Reviews.Replies.User").FirstOrDefault(); var reviews = lawyer.Reviews.Select(r => new ReviewDTO { Id = r.Id, Rate = r.Rate, Title = r.Title, UserId = r.UserId, UserName = r.User.UserName, Name = r.User.Name, NameEn = r.User.NameEn, Replies = r.Replies?.Select(w => ReplyDTO.ToReviewReplyDTO(w)) }); return(new RatingDTO { LawyerRate = LawyerDTO.CalculateRate(lawyer.Reviews).Value, Rate1 = lawyer.Reviews.Where(s => s.Rate == 1).Count(), Rate2 = lawyer.Reviews.Where(s => s.Rate == 2).Count(), Rate3 = lawyer.Reviews.Where(s => s.Rate == 3).Count(), Rate4 = lawyer.Reviews.Where(s => s.Rate == 4).Count(), Rate5 = lawyer.Reviews.Where(s => s.Rate == 5).Count(), TotalRating = lawyer.Reviews.Count(), Reviews = reviews }); }
public async Task <Response <ReplyDTO> > GetReplyById(string id) { var userReply = await _repliesRepo.GetById(id); Response <ReplyDTO> response = new Response <ReplyDTO>(); if (userReply == null) { response.Message = "oops! something went wrong"; return(response); } var clientReply = new ReplyDTO { Id = userReply.Id, Reply = userReply.Reply, UserId = userReply.UserId, CommentId = userReply.CommentId }; response.Success = true; response.Data = clientReply; response.Message = userReply.Reply; return(response); }
public bool Delete(Reply reply) { ReplyDTO dto = new ReplyDTO(); dto = converter.ModelToDTO(reply); context.Delete(dto); return(true); }
public void ReplyGetByIdTest(int id, string content, bool pinned, int postid, int accountid, string username) { ReplyDTO dto = new ReplyDTO(id, content, pinned, postid, accountid, username); ReplyDTO result = converter.ModelToDTO(container.GetById(id)); dto.Should().BeEquivalentTo(result); }
public IHttpActionResult UpdateEntity([FromBody] ReplyDTO reply) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _replyService.Update(reply); return(StatusCode(HttpStatusCode.NoContent)); }
public Reply GetById(int id) { ReplyDTO dto = new ReplyDTO(); dto = context.GetById(id); Reply reply = converter.DtoToModel(dto); return(reply); }
public long Insert(ReplyDTO dto) { if (tests == null) { throw new NullReferenceException("No value returned"); } tests.Add(dto); return(tests[0].Id); }
public bool Delete(ReplyDTO dto) { tests.Add(dto); if (tests == null) { throw new NullReferenceException("No value returned"); } return(true); }
public List <ReplyDTO> GetAll() { ReplyDTO dto = new ReplyDTO(1, "Content", false, 1, 1, "binsjee"); tests.Add(dto); if (tests == null) { throw new NullReferenceException("No value returned"); } return(tests); }
public Reply Create(ReplyDTO dto) { return(new Reply() { ReplyId = dto.ReplyId, ReplyDtime = dto.ReplyDtime, ReplyText = dto.ReplyText, UserId = dto.UserId, TicketId = dto.TicketId, ReplyIdentifier = dto.ReplyIdentifier }); }
public bool Delete(ReplyDTO dto) { try { string sql = "DELETE FROM Reply WHERE ID = @ID"; List <KeyValuePair <string, string> > parameters = new List <KeyValuePair <string, string> >() { new KeyValuePair <string, string>("ID", dto.Id.ToString()) }; ExecuteSql(sql, parameters); return(true); } catch (Exception e) { throw e; } }
public async Task <OperationDetails> Edit(ReplyDTO replyDto) { Reply reply = await Database.ReplyManager.GetById(replyDto.Id); if (reply != null) { await Database.ReplyManager.Update(reply); await Database.SaveAsync(); return(new OperationDetails(true, "Відповідь відредаговано успішно!", "")); } else { return(new OperationDetails(true, "Сталася помилка!", "")); } }
public async Task <ICollection <ReplyDTO> > GetAll() { IEnumerable <Reply> replies = await Database.ReplyManager.GetAll(); ICollection <ReplyDTO> list = new List <ReplyDTO>(); ReplyDTO dTO; foreach (Reply item in replies) { dTO = new ReplyDTO { Id = item.Id, QuestionId = item.QuestionId, UserPosted = item.UserPosted, ReplyText = item.ReplyText }; list.Add(dTO); } return(list); }
public List <ReplyDTO> GetAll() { List <ReplyDTO> replies = new List <ReplyDTO>(); try { string sql = "SELECT ID, ReplyContent, Pinned, ReactionTime, PostID, AccountID, Username FROM Reply"; DataSet results = ExecuteSql(sql, new List <KeyValuePair <string, string> >()); for (int x = 0; x < results.Tables[0].Rows.Count; x++) { ReplyDTO dto = DataSetParser.DataSetToReply(results, x); replies.Add(dto); } return(replies); } catch (Exception e) { throw e; } }
public HttpResponseMessage Reply(ReplyDTO postData) { try { var body = HttpUtility.UrlDecode(postData.Body); body = WebUtility.HtmlEncode(body); var messageId = InternalMessagingController.Instance.ReplyMessage(postData.ConversationId, body, postData.FileIds); var message = this.ToExpandoObject(InternalMessagingController.Instance.GetMessage(messageId)); var portalId = PortalController.GetEffectivePortalId(UserController.Instance.GetCurrentUserInfo().PortalID); var totalNewThreads = InternalMessagingController.Instance.CountUnreadMessages(this.UserInfo.UserID, portalId); var totalThreads = InternalMessagingController.Instance.CountMessagesByConversation(postData.ConversationId); var totalArchivedThreads = InternalMessagingController.Instance.CountArchivedMessagesByConversation(postData.ConversationId); return(this.Request.CreateResponse(HttpStatusCode.OK, new { Conversation = message, TotalNewThreads = totalNewThreads, TotalThreads = totalThreads, TotalArchivedThreads = totalArchivedThreads })); } catch (Exception ex) { var message = "An unexpected error occurred while attempting to reply to a conversation, see the server logs for more information."; Logger.Error(message, ex); return(this.Request.CreateResponse(HttpStatusCode.InternalServerError, message)); } }
public async Task <Response <ReplyDTO> > CreateReply(string commentId, User user, AddReplyDTO dto) { var response = new Response <ReplyDTO>(); var comment = _commentsRepo.GetById(commentId); if (comment is null) { response.Message = "Wrong comment id"; return(response); } var reply = new Replies { Reply = dto.Reply, CommentId = commentId, UserId = user.Id }; if (await _repliesRepo.Add(reply)) { var clientReply = new ReplyDTO { Id = reply.Id, Reply = reply.Reply, UserId = user.Id, CommentId = commentId }; response.Success = true; response.Message = "comment added successful"; response.Data = clientReply; return(response); } response.Message = "oops! something went wrong"; return(response); }
public async Task <OperationDetails> CreateNew(ReplyDTO replyDto) { Reply reply = await Database.ReplyManager.GetById(replyDto.Id); if (reply == null) { reply = new Reply { Id = replyDto.Id, UserPosted = replyDto.UserPosted, QuestionId = replyDto.QuestionId, ReplyText = replyDto.ReplyText }; await Database.ReplyManager.Create(reply); await Database.SaveAsync(); return(new OperationDetails(true, "Відповідь додано успішно!", "")); } else { return(new OperationDetails(false, "Сталася помилка", "")); } }
public long Insert(Reply reply) { ReplyDTO dto = converter.ModelToDTO(reply); return(context.Insert(dto)); }
public HttpResponseMessage Reply(ReplyDTO postData) { try { postData.Body = HttpUtility.UrlDecode(postData.Body); var messageId = InternalMessagingController.Instance.ReplyMessage(postData.ConversationId, postData.Body, postData.FileIds); var message = ToExpandoObject(InternalMessagingController.Instance.GetMessage(messageId)); var portalId = PortalController.GetEffectivePortalId(UserController.Instance.GetCurrentUserInfo().PortalID); var totalNewThreads = InternalMessagingController.Instance.CountUnreadMessages(UserInfo.UserID, portalId); var totalThreads = InternalMessagingController.Instance.CountMessagesByConversation(postData.ConversationId); var totalArchivedThreads = InternalMessagingController.Instance.CountArchivedMessagesByConversation(postData.ConversationId); return Request.CreateResponse(HttpStatusCode.OK, new { Conversation = message, TotalNewThreads = totalNewThreads, TotalThreads = totalThreads, TotalArchivedThreads = totalArchivedThreads }); } catch (Exception exc) { Logger.Error(exc); return Request.CreateErrorResponse(HttpStatusCode.InternalServerError, exc); } }
public IHttpActionResult Post([FromBody] ReplyDTO reply) { var replyAdded = _replyService.Add(reply); return(CreatedAtRoute("DefaultApi", new { id = reply.ReplyId }, replyAdded)); }