Пример #1
0
        public async Task <ActionResult> PostReply(ReplyModel reply)
        {
            if (reply.CommentId == null && reply.Body == null)
            {
                return(BadRequest(new { ValidationError = "body can not be null" }));
            }

            try
            {
                var model = _mapper.Map <ReplyModel, Reply>(reply);
                model.DatePosted = DateTime.Now;
                var result = await _replyContext.Add(model);

                if (!result.Succeeded)
                {
                    return(StatusCode(statusCode: StatusCodes.Status500InternalServerError, result.Error));
                }
                var comments = await _commemtContext.GetAllPostComment(reply.CommentId);

                var newModel = _mapper.Map <IEnumerable <Comment>, IEnumerable <CommentsViewModel> >(comments);
                await _hub.Clients.All.SendAsync("comment", newModel);
            }
            catch (Exception e)
            {
                _logger.LogError(e.InnerException?.ToString() ?? e.Message);
                _mailService.SendMail(string.Empty, e.InnerException?.ToString() ?? e.Message, "error");
                return(StatusCode(500, "Internal server error"));
            }

            return(Ok(new { Success = true }));
        }
Пример #2
0
        public static int AddReply(ReplyInfo reply)
        {
            IReply dal = Factory <IReply> .Create("Reply");

            int replyid = dal.Add(reply);

            return(replyid);
        }
Пример #3
0
 public static bool Add(ReplyInfo info)
 {
     return(dal.Add(info));
 }