예제 #1
0
        public async Task <IActionResult> QueryStatistics([FromRoute] string key, [FromBody] QueryDwzStatisticsViewModel model)
        {
            var c = currentUserService.CurrentUser;
            var m = await dWZServices.Load(key).ConfigureAwait(true);

            if (m == null)
            {
                return(new JsonResult(ActionStatusMessage.StaticMessage.ResourceNotExist));
            }
            if (!userActionServices.Permission(c.Application.Permission, DictionaryAllPermission.Resources.ShortUrl, Operation.Query, c.Id, m.CreateBy.CompanyInfo.CompanyCode))
            {
                return(new JsonResult(ActionStatusMessage.Account.Auth.Invalid.Default));
            }
            var result = await dWZServices.QueryStatistics(m, model).ConfigureAwait(true);

            var statistics = result.Item1;
            var totalCount = result.Item2;

            return(new JsonResult(new ShortUrlStatisticsViewModel()
            {
                Data = new ShortUrlStatisticsDataModel()
                {
                    ShortUrl = m.ToDataModel(),
                    Statistics = statistics.Select(s => s.ToDataModel()),
                    TotalCount = totalCount
                }
            }));
        }
        public async Task <Tuple <IEnumerable <ShortUrlStatistics>, int> > QueryStatistics(ShortUrl shortUrl, QueryDwzStatisticsViewModel model)
        {
            if (model == null)
            {
                return(null);
            }
            var res = context.CommonShortUrlStatistics.Where(s => s.Url.Id == shortUrl.Id);

            if (model.Create != null)
            {
                res = res.Where(s => s.Create > model.Create.Start).Where(s => s.Create < model.Create.End);
            }
            if (model.ViewBy != null)
            {
                res = res.Where(s => s.ViewById == model.ViewBy.Value);
            }
            if (model.Device != null)
            {
                res = res.Where(s => s.Device == model.Device.Value);
            }
            if (model.Ip != null)
            {
                res = res.Where(s => s.Ip == model.Ip.Value);
            }
            res = res.OrderByDescending(s => s.Create);
            var result = res.SplitPage(model.Pages);

            return(await Task.FromResult(new Tuple <IEnumerable <ShortUrlStatistics>, int>(result.Item1.ToList(), result.Item2)).ConfigureAwait(true));
        }