public async Task <ActionResult <PublicApi.v1.DTO.Comment> > GetComment(int id) { var comment = await _bll.Comments.GetCommentByIdAndShop(id, User.GetShopId()); if (comment == null) { return(NotFound()); } return(CommentMapper.MapFromBLL(comment)); }
public async Task <ActionResult <PublicApi.v1.DTO.Comment> > DeleteComment(int id) { var comment = await _bll.Comments.FindAsync(id); if (comment == null) { return(NotFound()); } // check, that the object being used is really belongs to logged in user if (!await _bll.Comments.BelongsToUserAsync(comment.AppUserId, User.GetUserId())) { return(NotFound()); } _bll.Comments.Remove(comment); await _bll.SaveChangesAsync(); return(CommentMapper.MapFromBLL(comment)); }
public async Task <ActionResult <IEnumerable <PublicApi.v1.DTO.Comment> > > GetComments(string search, int?pageIndex, int?pageSize) { if ((pageIndex != null && pageIndex < 1) || (pageSize != null && pageSize < 1)) { return(BadRequest()); } //var comment = await _bll.Comments.AllAsync(); var comment = (await _bll.Comments.GetAllWithProductByShopAsync(User.GetShopId(), search, pageIndex, pageSize)).Select(e => CommentMapper.MapFromBLL(e)).ToList(); return(comment); }