Exemplo n.º 1
0
        public async Task <TResponse <PageResult <ProductModel> > > GetPaging(int userId,
                                                                              GetProductPageModel request,
                                                                              int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var result = await ReadOnlyRepository.QueryMultipleLFAsync <ProductModel, int>(string.Format(SqlQuery.PRODUCT_GET_BY_PAGING,
                                                                                                                 request.ColumnOrder,
                                                                                                                 request.SortDir.ToUpper()),
                                                                                                   new
                    {
                        Name        = $"%{request.Name}%",
                        Description = $"%{request.Description}%",
                        request.ProductGroupId,
                        request.ProductStatusId,
                        request.ProductUnitId,
                        request.ManufacturerId,
                        request.CountryId,
                        Skip = (request.Page - 1) * request.PageSize,
                        Take = request.PageSize
                    });

                    if (result.IsSuccess)
                    {
                        return(await Ok(new PageResult <ProductModel>(request.Page,
                                                                      request.PageSize,
                                                                      result.Data.Item2,
                                                                      result.Data.Item1)));
                    }

                    return(await Fail <PageResult <ProductModel> >(result.Message));
                }

                return(await Fail <PageResult <ProductModel> >(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <ProductModel> >(exception));
            }
        }
Exemplo n.º 2
0
        public async Task <TResponse <PageResult <UserPageModel> > > GetPaging(int userId,
                                                                               GetUserPageModel request,
                                                                               int permissionId)
        {
            try
            {
                var checkValid = await CheckPermission(userId,
                                                       permissionId);

                if (checkValid.IsSuccess)
                {
                    var result = await ReadOnlyRepository.QueryMultipleLFAsync <UserPageModel, int>(string.Format(SqlQuery.USER_GET_BY_PAGING,
                                                                                                                  request.ColumnOrder,
                                                                                                                  request.SortDir.ToUpper()),
                                                                                                    new
                    {
                        Username    = $"%{request.Username}%",
                        DisplayName = $"%{request.DisplayName}%",
                        FullName    = $"%{request.FullName}%",
                        PhoneNumber = $"%{request.PhoneNumber}%",
                        request.BranchId,
                        request.RoleId,
                        Skip = (request.Page - 1) * request.PageSize,
                        Take = request.PageSize
                    });

                    if (result.IsSuccess)
                    {
                        return(await Ok(new PageResult <UserPageModel>(request.Page,
                                                                       request.PageSize,
                                                                       result.Data.Item2,
                                                                       result.Data.Item1)));
                    }

                    return(await Fail <PageResult <UserPageModel> >(result.Message));
                }

                return(await Fail <PageResult <UserPageModel> >(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <UserPageModel> >(exception));
            }
        }
Exemplo n.º 3
0
        /// <summary>
        ///     Get User By Paging
        /// </summary>
        /// <param name="req"></param>
        /// <returns></returns>
        public async Task <TResponse <PageResult <UserModel> > > GetPaging(GetUserByPagingModel req)
        {
            try
            {
                if (req.Page <= 1)
                {
                    req.Page = 1;
                }

                if (req.PageSize <= 5)
                {
                    req.PageSize = 5;
                }

                var result = await ReadOnlyRepository.QueryMultipleLFAsync <UserModel, int>(
                    string.Format(SqlQuery.USER_GET_PAGING, req.ColumnOrder, req.SortDir), new
                {
                    Username = $"%{req.Username}%",
                    Skip     = (req.Page - 1) * req.PageSize,
                    Take     = req.PageSize
                });

                if (result != null)
                {
                    if (result.IsSuccess)
                    {
                        return(await Ok(new PageResult <UserModel>(req.Page, req.PageSize, result.Data.Item2,
                                                                   result.Data.Item1)));
                    }

                    return(await Fail <PageResult <UserModel> >(result.Message));
                }

                return(await Ok(new PageResult <UserModel>(1, req.PageSize, 0, null)));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <UserModel> >(exception));
            }
        }
Exemplo n.º 4
0
        public async Task <TResponse <PageResult <RoleModel> > > GetPaging(int userId,
                                                                           GetRolePageModel request,
                                                                           int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId,
                                                                    permissionId);

                if (checkValid.IsSuccess)
                {
                    var result = await ReadOnlyRepository.QueryMultipleLFAsync <RoleModel, int>(SqlQuery.ROLE_GET_BY_PAGING,
                                                                                                new
                    {
                        Name = $"%{request.Name}%",
                        Skip = (request.Page - 1) * request.PageSize,
                        Take = request.PageSize
                    });

                    if (result.IsSuccess)
                    {
                        return(await Ok(new PageResult <RoleModel>(request.Page,
                                                                   request.PageSize,
                                                                   result.Data.Item2,
                                                                   result.Data.Item1)));
                    }

                    return(await Fail <PageResult <RoleModel> >(result.Message));
                }

                return(await Fail <PageResult <RoleModel> >(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <RoleModel> >(exception));
            }
        }
Exemplo n.º 5
0
        public async Task <TResponse <PageResult <InvoiceModel> > > GetPaging(int userId, GetInvoicePageModel request,
                                                                              int permissionId)
        {
            try
            {
                var checkValid = await _userService.CheckPermission(userId, permissionId);

                if (checkValid.IsSuccess)
                {
                    var page = request.Page;
                    if (page <= 1)
                    {
                        page = 1;
                    }

                    var pageSize = request.PageSize;
                    if (pageSize <= 0)
                    {
                        pageSize = 20;
                    }

                    var result = await ReadOnlyRepository.QueryMultipleLFAsync <InvoiceModel, int>(
                        SqlQuery.INVOICE_GET_BY_PAGING, new
                    {
                        CustomerName  = $"%{request.Customer}%",
                        CustomerPhone = $"%{request.CustomerPhone}%",
                        CustomerCode  = $"%{request.CustomerCode}%",
                        Code          = $"%{request.Code}%",
                        request.BranchId,
                        request.InvoiceStatusId,
                        request.UserSellId,
                        request.UserCreatedId,
                        request.FromDate,
                        request.ToDate,
                        Skip = (page - 1) * pageSize,
                        Take = pageSize
                    });

                    if (result.IsSuccess)
                    {
                        if (result.Data.Item1 != null && result.Data.Item1.Any())
                        {
                            var count    = result.Data.Item2;
                            var invoices = result.Data.Item1.ToList();

                            foreach (var invoice in invoices)
                            {
                                var products = await ReadOnlyRepository.QueryAsync <string>(
                                    SqlQuery.INVOICE_GET_PRODUCT_BY_INVOICE_ID, new
                                {
                                    InvoiceId = invoice.Id
                                });

                                if (products.IsSuccess && products.Data != null)
                                {
                                    invoice.Products.AddRange(products.Data);
                                }

                                var users = await ReadOnlyRepository.QueryAsync <string>(
                                    SqlQuery.INVOICE_GET_USER_DELIVERY_BY_INVOICE_ID, new
                                {
                                    InvoiceId = invoice.Id
                                });

                                if (users.IsSuccess && users.Data != null)
                                {
                                    invoice.UserDelivery.AddRange(users.Data);
                                }
                            }

                            return(await Ok(new PageResult <InvoiceModel>(page, pageSize, result.Data.Item2,
                                                                          result.Data.Item1)));
                        }


                        return(await Ok(new PageResult <InvoiceModel>(page, pageSize, result.Data.Item2,
                                                                      new List <InvoiceModel>())));
                    }

                    return(await Fail <PageResult <InvoiceModel> >(result.Message));
                }

                return(await Fail <PageResult <InvoiceModel> >(checkValid.Message));
            }
            catch (Exception exception)
            {
                return(await Fail <PageResult <InvoiceModel> >(exception));
            }
        }