Esempio n. 1
0
        public async Task <ResponseModel> CreateCommentAsync(Guid userId, Guid shopId, CommentManageModel commentManageModel)
        {
            if (userId == null)
            {
                return(new ResponseModel()
                {
                    Message = MessageConstants.INVALID_ACCESS_TOKEN,
                    StatusCode = System.Net.HttpStatusCode.BadRequest
                });
            }
            else
            {
                var comment = new Comment()
                {
                    UserId  = userId,
                    ShopId  = shopId,
                    Content = StringExtension.CustomString(commentManageModel.Content)
                };

                await _commentResponstory.InsertAsync(comment);

                comment = await GetAll().FirstOrDefaultAsync(x => x.Id == comment.Id);

                return(new ResponseModel()
                {
                    Data = new CommentViewModel(comment),
                    Message = MessageConstants.CREATED_SUCCESSFULLY,
                    StatusCode = System.Net.HttpStatusCode.OK
                });
            }
        }
Esempio n. 2
0
        public async Task <ResponseModel> UpdateCommentAsync(Guid userId, Guid shopId, Guid commentId, CommentManageModel commentManageModel)
        {
            if (userId == null)
            {
                return(new ResponseModel()
                {
                    Message = MessageConstants.INVALID_ACCESS_TOKEN,
                    StatusCode = System.Net.HttpStatusCode.BadRequest
                });
            }
            else
            {
                var comment = await GetAll().FirstOrDefaultAsync(x => x.Id == commentId && x.ShopId == shopId && x.UserId == userId);

                if (comment == null)
                {
                    return(new ResponseModel()
                    {
                        Message = MessageConstants.INVALID_ACCESS_TOKEN,
                        StatusCode = System.Net.HttpStatusCode.BadRequest
                    });
                }

                commentManageModel.SetDataToModel(comment);

                await _commentResponstory.UpdateAsync(comment);

                return(new ResponseModel()
                {
                    Data = new CommentViewModel(comment),
                    Message = MessageConstants.CREATED_SUCCESSFULLY,
                    StatusCode = System.Net.HttpStatusCode.OK
                });
            }
        }