public async Task <PagedList <TheoDoi> > GetTheoDoiLastestForPagination(TheoDoiParameters theoDoiParameters) { return(await PagedList <TheoDoi> .ToPagedList(FindAll() .Include(m => m.User) .Include(m => m.Truyen) .OrderByDescending(on => on.TheoDoiID).Take(theoDoiParameters.PageSize), theoDoiParameters.PageNumber, theoDoiParameters.PageSize)); }
public async Task <IActionResult> GetTruyenByTheoDoiForPagination([FromQuery] TheoDoiParameters theoDoiParameters) { var apiKeyAuthenticate = APICredentialAuth.APIKeyCheck(Request.Headers[NamePars.APIKeyStr]); if (apiKeyAuthenticate.StatusCode == ResponseCode.Error) { return(BadRequest(new ResponseDetails() { StatusCode = ResponseCode.Exception, Message = apiKeyAuthenticate.Message })); } if (theoDoiParameters.GetAll) { var truyens = await _repository.TheoDoi.GetTruyenByTheoDoiForPagination(theoDoiParameters); var metadata = new { truyens.TotalCount, truyens.PageSize, truyens.CurrentPage, truyens.TotalPages, truyens.HasNext, truyens.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(truyens)); } if (theoDoiParameters.LastestUpdate) { var theoDois = await _repository.TheoDoi.GetTheoDoiLastestForPagination(theoDoiParameters); var metadata = new { theoDois.TotalCount, theoDois.PageSize, theoDois.CurrentPage, theoDois.TotalPages, theoDois.HasNext, theoDois.HasPrevious }; Response.Headers.Add("X-Pagination", JsonConvert.SerializeObject(metadata)); return(Ok(theoDois)); } else { return(BadRequest("wrong request to get theo doi pagination")); } }
public async Task <PagedList <Truyen> > GetTruyenByTheoDoiForPagination(TheoDoiParameters theoDoiParameters) { return(await PagedList <Truyen> .ToPagedList( (from m in _context.Truyens join n in _context.TheoDois on m.TruyenID equals n.TruyenID join c in _context.Users on n.UserID equals c.UserID where c.UserID.ToString() == theoDoiParameters.UserID && !m.TinhTrang && !c.TinhTrang select m).Include(m => m.Chuongs) .OrderBy(on => on.TruyenID), theoDoiParameters.PageNumber, theoDoiParameters.PageSize)); }
public async Task <IActionResult> DeleteTheoDoiForUser([FromQuery] TheoDoiParameters theoDoiParameters) { try { var apiKeyAuthenticate = APICredentialAuth.APIKeyCheck(Request.Headers[NamePars.APIKeyStr]); if (apiKeyAuthenticate.StatusCode == ResponseCode.Error) { return(BadRequest(new ResponseDetails() { StatusCode = ResponseCode.Exception, Message = apiKeyAuthenticate.Message })); } var theoDoi = await _repository.TheoDoi.GetTheoDoiByUserIdAndTruyenIdAsync(theoDoiParameters.UserID, theoDoiParameters.TruyenID); if (theoDoi == null) { return(NotFound(new ResponseDetails() { StatusCode = ResponseCode.Error, Message = "ID TheoDoi không tồn tại" })); } ResponseDetails response = _repository.TheoDoi.DeleteTheoDoi(theoDoi); if (response.StatusCode == ResponseCode.Success) { _repository.Save(); } return(Ok(response)); } catch (Exception ex) { _logger.LogError("Gặp lỗi khi xóa theo dõi có userID " + theoDoiParameters.UserID + " và truyện ID " + theoDoiParameters.TruyenID + ": " + ex); return(BadRequest(new ResponseDetails() { StatusCode = ResponseCode.Exception, Message = "Lỗi execption ở hàm DeleteTheoDoiForUser" })); } }