Ejemplo n.º 1
0
        public async Task <ViewReplyDto> AddReply(string userId, int commentId, ReplyDto replyDto)
        {
            var comment = await GetComment(commentId);

            var reply = new Reply
            {
                Content   = replyDto.Content,
                CommentId = commentId,
                UserId    = userId
            };

            await Do(async() => await _context.Replies.AddAsync(reply));

            reply.User = await _userService.GetUserById(userId);

            if (userId != comment.UserId)
            {
                await _notificationService.NotifyReply(reply.User, comment, reply.Id);
            }

            var dto = ViewReplyDto.Create(reply);

            _topicsHub.SendReply(comment.TopicId, dto);

            return(dto);
        }
        public async Task <ActionResult <Reply> > AddReply(ReplyDto reply)
        {
            var user_id = Convert.ToInt32(GetClaim("id"));

            Global.LogMessage(JsonConvert.SerializeObject(reply));

            return(Ok(await _commentService.AddReply(user_id, reply)));
        }
Ejemplo n.º 3
0
        public async Task UpdateReply(string userId, int replyId, ReplyDto replyDto)
        {
            var reply = await GetUserReply(userId, replyId);

            reply.Content = replyDto.Content;

            await Do(() => _context.Entry(reply).State = EntityState.Modified);
        }
        public void Execute(ReplyDto request)
        {
            _validator.ValidateAndThrow(request);

            var reply = _mapper.Map <Reply>(request);

            _context.Replies.Add(reply);
            _context.SaveChanges();
        }
Ejemplo n.º 5
0
        public async Task UpdateAsync(ReplyDto reply)
        {
            Reply match = await _unitOfWork.Replies.FindAsync(reply.ReplyId);

            match.Content     = reply.Content ?? match.Content;
            match.Edited      = true;
            match.EditedBy    = reply.EditedBy;
            match.DateReplied = DateTime.UtcNow;
            await _unitOfWork.CompleteAsync();
        }
 public async Task<ActionResult<Message>> SendReply(ReplyDto replyDto)
 {
     Message sent = await _logic.SendReply(replyDto);
     if (sent == null)
     {
        // _logger.LogInformation("Bad Request");
         return BadRequest("Message was not sent");
     }
     return sent;
 }
Ejemplo n.º 7
0
        public async Task <long> UpdateReply(ReplyDto model)
        {
            var replyToUpdate = await _skinHubAppDbContext.Reply.FindAsync(model.ID);

            if (replyToUpdate != null)
            {
                _skinHubAppDbContext.Entry(replyToUpdate).State = EntityState.Modified;
                await _skinHubAppDbContext.SaveChangesAsync();

                return(model.ID);
            }
            return(0);
        }
Ejemplo n.º 8
0
        /// <summary>
        /// takes in a ReplyDto as a parameter and creates and new Message. returns the new message.
        /// </summary>
        /// <param name="replyDto"></param>
        /// <returns></returns>
        public Message BuildMessage(ReplyDto replyDto)
        {
            Message replyMessage = new Message()
            {
                RecipientListID = replyDto.RecipientListID,
                SenderID        = replyDto.SenderID,
                MessageText     = replyDto.MessageText,
                MessageID       = Guid.NewGuid(),
                SentDate        = DateTime.Now
            };

            return(replyMessage);
        }
Ejemplo n.º 9
0
        public ReplyDto GetReplyAsync(int id)
        {
            ReplyDto     reply        = new ReplyDto();
            Entity_Reply reply_entity = _context.Replies.Where(r => r.Id == id).FirstOrDefault();

            if (reply_entity != null)
            {
                reply.Id      = reply_entity.Id;
                reply.Content = reply_entity.Content;
                reply.Type    = reply_entity.Type;
            }

            return(reply);
        }
        public void Execute(ReplyDto request)
        {
            if (_context.Categories.Find(request.Id) == null)
            {
                throw new EntityNotFoundException(request.Id, typeof(Reply));
            }

            _validator.ValidateAndThrow(request);

            var reply = _context.Replies.Find(request.Id);

            _mapper.Map(request, reply);
            _context.SaveChanges();
        }
Ejemplo n.º 11
0
        public async Task <ReplyDto> AddReply(int user_id, ReplyDto newreply)
        {
            if (await _userService.GetUserPoint(user_id) >= 20)
            {
                var reply = new Reply();
                _mapper.Map(newreply, reply);
                await ctx.Replies.AddAsync(reply);

                await ctx.SaveChangesAsync();

                return(newreply);
            }
            else
            {
                return(null);
            }
        }
        public void UpdateReply(ReplyDto replyDto)
        {
            ReplyDE reply = _context.tbl_db_reply.Where(x => x.ReplyId == replyDto.ReplyId).FirstOrDefault();

            if (reply == null)
            {
                throw new AppException("ReplyId does not exist");
            }

            if (!string.IsNullOrEmpty(replyDto.Description))
            {
                reply.Description = replyDto.Description;
            }

            reply.isEdited = true;

            _context.tbl_db_reply.Update(reply);
        }
Ejemplo n.º 13
0
        public IHttpActionResult PostReply(ReplyDto dto)
        {
            var currentUser   = User.Identity.GetUserFirstname();
            var currentUserId = User.Identity.GetUserId();

            var reply = new Reply
            {
                RepliedByName = currentUser,
                RepliedById   = currentUserId,
                Body          = dto.Body,
                DiscussionId  = dto.DiscussionId
            };

            _context.Replies.Add(reply);
            _context.SaveChanges();

            return(Ok(reply));
        }
Ejemplo n.º 14
0
        public async Task <ReplyDto> GetReplyByID(long id)
        {
            var reply = await _skinHubAppDbContext.Reply.Include(p => p.Comment).Where(p => p.ID == id).FirstOrDefaultAsync();

            if (reply != null)
            {
                var model = new ReplyDto
                {
                    ID        = reply.ID,
                    ReplyBody = reply.ReplyBody,
                    CreatedOn = reply.CreatedOn,
                    Author    = reply.Author,
                    CommentID = reply.CommentID,
                    Comment   = reply.Comment.CommentBody,
                };
                return(model);
            }
            return(null);
        }
Ejemplo n.º 15
0
        public async void TestSendReply()
        {
            var options = new DbContextOptionsBuilder <MessageContext>()
                          .UseInMemoryDatabase(databaseName: "p3MessageService")
                          .Options;

            using (var context = new MessageContext(options))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                Repo   r     = new Repo(context, new NullLogger <Repo>());
                Mapper map   = new Mapper();
                Logic  logic = new Logic(r, map, new NullLogger <Repo>());

                var replyDto = new ReplyDto
                {
                    SenderID        = "22343445654",
                    RecipientListID = Guid.NewGuid(),
                    MessageText     = "Hello I am a message!!!!!"
                };

                var message = new Message
                {
                    MessageID       = Guid.NewGuid(),
                    SenderID        = replyDto.SenderID,
                    RecipientListID = Guid.NewGuid(),
                    SentDate        = DateTime.Now,
                    MessageText     = replyDto.MessageText
                };

                r.Messages.Add(message);
                await r.CommitSave();

                var sendreply = await logic.SendReply(replyDto);

                Assert.Equal(message.SenderID, replyDto.SenderID);
                Assert.Equal(message.MessageText, replyDto.MessageText);
            }
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> Update([FromBody] ReplyDto model)
        {
            try
            {
                if (ModelState.IsValid)
                {
                    var update = await _replyServices.GetReplyByID(model.ID);

                    if (update != null)
                    {
                        await _replyServices.UpdateReply(model);

                        return(Ok($"Reply updated Successfully"));
                    }
                }
                return(BadRequest("Update failed, Please try again"));
            }
            catch (Exception ex)
            {
                return(BadRequest($"{ex.Message}, Error! Your task failed, Please try again"));
            }
        }
Ejemplo n.º 17
0
        public IActionResult CreateReply([FromBody] ReplyDto replyDto)
        {
            if (!ModelState.IsValid)
            {
                // return 422
                return(new Helpers.UnprocessableEntityObjectResult(ModelState));
            }

            try
            {
                // save
                var replyFromRepo = _discussionBoardRepository.CreateReply(replyDto);

                var replyToReturn = _mapper.Map <ReplyDto>(replyFromRepo);

                return(Ok(replyToReturn));
            }
            catch (AppException ex)
            {
                // return error message if there was an exception
                return(BadRequest(new { message = ex.Message }));
            }
        }
        public ReplyDE CreateReply(ReplyDto replyDto)
        {
            if (!PostExists(replyDto.PostId))
            {
                throw new AppException("PostId " + replyDto.PostId + " does not exist");
            }

            if (!_userRepository.UserExists(replyDto.CreatedBy))
            {
                throw new AppException("UserId " + replyDto.CreatedBy + " does not exist");
            }

            ReplyDE reply = _mapper.Map <ReplyDE>(replyDto);

            reply.ReplyId   = new Guid();
            reply.CreatedOn = DateTime.Now;
            reply.isEdited  = false;

            _context.tbl_db_reply.Add(reply);
            _context.SaveChanges();

            return(reply);
        }
Ejemplo n.º 19
0
        public IActionResult UpdateReply([FromBody] ReplyDto replyDto)
        {
            try
            {
                if (!ModelState.IsValid)
                {
                    // return 422
                    return(new Helpers.UnprocessableEntityObjectResult(ModelState));
                }

                _discussionBoardRepository.UpdateReply(replyDto);

                if (!_discussionBoardRepository.Save())
                {
                    throw new AppException("Updating post failed on save.");
                }

                return(NoContent());
            }
            catch (AppException ex)
            {
                return(BadRequest(new { message = ex.Message }));
            }
        }
Ejemplo n.º 20
0
        public async Task <bool> AddReply(ReplyDto replyDto)
        {
            Reply reply = this._mapper.Map <ReplyDto, Reply>(replyDto);

            return(await this._userArticleAccessor.AddReply(reply));
        }
Ejemplo n.º 21
0
 public IActionResult Put(int id, [FromBody] ReplyDto dto, [FromServices] IUpdateReplyCommand command)
 {
     dto.Id = id;
     _executor.ExecuteCommand(command, dto);
     return(NoContent());
 }
Ejemplo n.º 22
0
 public IActionResult Post([FromBody] ReplyDto dto, [FromServices] ICreateReplyCommand command)
 {
     _executor.ExecuteCommand(command, dto);
     return(StatusCode(StatusCodes.Status201Created));
 }
Ejemplo n.º 23
0
        /// <summary>
        /// calls the mapperClass BuildMessage() to build a new message, calls sendMessage()
        /// to save the message and the recipient list to the database.
        /// </summary>
        /// <param name="replyDto"></param>
        /// <returns></returns>
        public async Task <Message> SendReply(ReplyDto replyDto)
        {
            Message message = _mapper.BuildMessage(replyDto);

            return(await SendMessage(message));
        }
Ejemplo n.º 24
0
 public async Task <bool> AddReply([FromBody] ReplyDto replyDto)
 {
     return(await this.userArticleManager.AddReply(replyDto));
 }
Ejemplo n.º 25
0
 public async Task CreateAsync(ReplyDto reply)
 {
     _unitOfWork.Replies.Add(_mapper.Map <Reply>(reply));
     await _unitOfWork.CompleteAsync();
 }
Ejemplo n.º 26
0
 public async Task <IActionResult> UpdateReply(int id, ReplyDto replyDto)
 {
     return(await Do(async() => await _commentService.UpdateReply(User.Identity.GetUserId(), id, replyDto)));
 }
Ejemplo n.º 27
0
 public async Task <IActionResult> AddReply(int commentId, ReplyDto replyDto)
 {
     return(await Create(nameof(AddReply), async() => await _commentService.AddReply(User.Identity.GetUserId(), commentId, replyDto)));
 }
Ejemplo n.º 28
0
 public async Task <bool> AddReply(ReplyDto replyDto)
 {
     return(await this._userArticleEngine.AddReply(replyDto));
 }