示例#1
0
 private void ValidateTake(ref SkipTakeModel model, int howManyTake)
 {
     if (model.Take == 0)
     {
         model.Take = howManyTake;
     }
 }
示例#2
0
    /// <summary>
    /// 根据总数,每页数,和当前第几页,算出应该skip多少条,超出最大页数之后,返回最后一页面数据
    /// </summary>
    /// <param name="allcount">信息总数</param>
    /// <param name="pagesize">每页条数</param>
    /// <param name="pageindex">当前页</param>
    /// <returns></returns>
    public static SkipTakeModel GetSkipShowFinalPage(int allcount, int pagesize, int pageindex)
    {
        SkipTakeModel model = new SkipTakeModel();

        if (pageindex > 0)
        {
            int maxpage = allcount / pagesize;
            if (allcount % pagesize > 0)
            {
                maxpage++;
            }
            pageindex = Math.Min(maxpage, pageindex);
            var max = Math.Max(0, pagesize * (pageindex - 1));
            model.Skip    = max;
            model.Take    = pagesize;
            model.MaxPage = maxpage;
        }
        else
        {
            model.Skip    = 0;
            model.Take    = pagesize;
            model.MaxPage = 1;
        }
        return(model);
    }
示例#3
0
        public async Task <IActionResult> GetLastCoinsValues([FromBody] SkipTakeModel skipTake)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            ValidateTake(ref skipTake, 10);
            try
            {
                var getLatestCoinsValue = await this.coinService.TakeAndSkipLatestCoinsValue(skipTake.Skip, skipTake.Take);

                return(Ok(getLatestCoinsValue));
            }
            catch (Exception ex)
            {
                return(BadRequest(ex.Message));
            }
        }