Example #1
0
        protected async Task <RepositoryResponse <FileViewModel> > ExportListAsync(Expression <Func <TModel, bool> > predicate)
        {
            string type    = typeof(TModel).Name;
            var    getData = await _repo.GetModelListByAsync(predicate, _context);

            var jData = new List <JObject>();

            if (getData.IsSucceed)
            {
                string exportPath = $"{MixFolders.ExportFolder}/{typeof(TModel).Name}";
                foreach (var item in JArray.FromObject(getData.Data))
                {
                    jData.Add(JObject.FromObject(item));
                }

                var result = Lib.ViewModels.MixDatabaseDatas.Helper.ExportAttributeToExcel(
                    jData, string.Empty, exportPath, $"{type}", null);

                return(result);
            }
            else
            {
                return(new RepositoryResponse <FileViewModel>()
                {
                    Errors = getData.Errors
                });
            }
        }
        public virtual async Task <ActionResult <PaginationModel <TView> > > Get()
        {
            bool isFromDate = DateTime.TryParse(Request.Query[MixRequestQueryKeywords.FromDate], out DateTime fromDate);
            bool isToDate   = DateTime.TryParse(Request.Query[MixRequestQueryKeywords.ToDate], out DateTime toDate);

            int.TryParse(Request.Query[MixRequestQueryKeywords.PageIndex], out int pageIndex);
            bool isDirection = Enum.TryParse(Request.Query[MixRequestQueryKeywords.Direction], out Heart.Enums.DisplayDirection direction);
            bool isPageSize  = int.TryParse(Request.Query[MixRequestQueryKeywords.PageSize], out int pageSize);

            RequestPaging request = new RequestPaging()
            {
                PageIndex = pageIndex,
                PageSize  = isPageSize ? pageSize : 100,
                OrderBy   = Request.Query[MixRequestQueryKeywords.OrderBy].ToString().ToTitleCase(),
                Direction = direction
            };
            Expression <Func <TModel, bool> >             predicate = null;
            RepositoryResponse <PaginationModel <TView> > getData   = null;

            if (!string.IsNullOrEmpty(_lang))
            {
                predicate = ReflectionHelper.GetExpression <TModel>(MixQueryColumnName.Specificulture, _lang, Heart.Enums.ExpressionMethod.Eq);
                getData   = await _repo.GetModelListByAsync(
                    predicate,
                    request.OrderBy, request.Direction,
                    request.PageSize, request.PageIndex, null, null)
                            .ConfigureAwait(false);
            }
            else
            {
                getData = await _repo.GetModelListAsync(
                    request.OrderBy, request.Direction, request.PageSize, request.PageIndex, null, null).ConfigureAwait(false);
            }

            if (getData.IsSucceed)
            {
                return(Ok(getData.Data));
            }
            else
            {
                return(BadRequest(getData.Errors));
            }
        }