예제 #1
0
        public IActionResult List([FromBody] SmartTableParam param)
        {
            var query = _userRepository.Query()
                        .Include(x => x.Roles)
                        .ThenInclude(x => x.Role)
                        .Include(x => x.CustomerGroups)
                        .ThenInclude(x => x.CustomerGroup)
                        .Where(x => !x.IsDeleted);

            long guestroleId = 3;

            query = query.Where(x => x.Roles.Any(r => r.RoleId != guestroleId));

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;

                if (search.Email != null)
                {
                    string email = search.Email;
                    query = query.Where(x => x.Email.Contains(email));
                }

                if (search.FullName != null)
                {
                    string fullName = search.FullName;
                    query = query.Where(x => x.FullName.Contains(fullName));
                }

                if (search.RoleId != null)
                {
                    long roleId = search.RoleId;
                    query = query.Where(x => x.Roles.Any(r => r.RoleId == roleId));
                }

                if (search.CustomerGroupId != null)
                {
                    long customerGroupId = search.CustomerGroupId;
                    query = query.Where(x => x.CustomerGroups.Any(g => g.CustomerGroupId == customerGroupId));
                }

                if (search.CreatedOn != null)
                {
                    if (search.CreatedOn.before != null)
                    {
                        DateTimeOffset before = search.CreatedOn.before;
                        query = query.Where(x => x.CreatedOn <= before);
                    }

                    if (search.CreatedOn.after != null)
                    {
                        DateTimeOffset after = search.CreatedOn.after;
                        query = query.Where(x => x.CreatedOn >= after);
                    }
                }
            }

            var users = query.ToSmartTableResultNoProjection(
                param,
                user => new
            {
                user.Id,
                user.Email,
                user.FullName,
                user.CreatedOn,
                Roles          = user.Roles.Select(x => x.Role.Name),
                CustomerGroups = user.CustomerGroups.Select(x => x.CustomerGroup.Name)
            });

            return(Json(users));
        }
예제 #2
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var cities = await _cityService.Search(param);

            return(Ok(cities));
        }
예제 #3
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var campaignOrders = await _campaignOrderService.Search(param);

            return(Ok(campaignOrders));
        }
예제 #4
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var wareHouses = await _wareHouseService.Search(param);

            return(Ok(wareHouses));
        }
예제 #5
0
        public async Task <IActionResult> ExportToXlsxAsync([FromBody] SmartTableParam param)
        {
            var result = await _cityService.ExportToXlsx(param);

            return(Ok(result));
        }
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var result = await _productCategoryService.Search(param);

            return(Ok(result));
        }
예제 #7
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var result = await CommentService.Search(param);

            return(Ok(result));
        }
예제 #8
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var AttributeValues = await _attributeValueService.Search(param);

            return(Ok(AttributeValues));
        }
예제 #9
0
        public async Task <ActionResult <OrderLineExportVm> > OrderLinesExport([FromBody] SmartTableParam param, [FromServices] IRepository <OrderItem> orderItemRepository)
        {
            var query = orderItemRepository.Query();

            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin"))
            {
                query = query.Where(x => x.Order.VendorId == currentUser.VendorId);
            }

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;
                if (search.Id != null)
                {
                    long id = search.Id;
                    query = query.Where(x => x.Id == id);
                }

                if (search.Status != null)
                {
                    var status = (OrderStatus)search.Status;
                    query = query.Where(x => x.Order.OrderStatus == status);
                }

                if (search.CustomerName != null)
                {
                    string customerName = search.CustomerName;
                    query = query.Where(x => x.Order.Customer.FullName.Contains(customerName));
                }

                if (search.CreatedOn != null)
                {
                    if (search.CreatedOn.before != null)
                    {
                        DateTimeOffset before = search.CreatedOn.before;
                        query = query.Where(x => x.Order.CreatedOn <= before);
                    }

                    if (search.CreatedOn.after != null)
                    {
                        DateTimeOffset after = search.CreatedOn.after;
                        query = query.Where(x => x.Order.CreatedOn >= after);
                    }
                }
            }

            var orderItems = await query
                             .Select(x => new OrderLineExportVm()
            {
                Id                                 = x.Id,
                OrderStatus                        = (int)x.Order.OrderStatus,
                IsMasterOrder                      = x.Order.IsMasterOrder,
                DiscountAmount                     = x.Order.DiscountAmount,
                CreatedOn                          = x.Order.CreatedOn,
                OrderStatusString                  = x.Order.OrderStatus.ToString(),
                PaymentFeeAmount                   = x.Order.PaymentFeeAmount,
                OrderTotal                         = x.Order.OrderTotal,
                Subtotal                           = x.Order.SubTotal,
                SubtotalWithDiscount               = x.Order.SubTotalWithDiscount,
                PaymentMethod                      = x.Order.PaymentMethod,
                ShippingAmount                     = x.Order.ShippingFeeAmount,
                ShippingMethod                     = x.Order.ShippingMethod,
                TaxAmount                          = x.Order.TaxAmount,
                CustomerId                         = x.Order.CustomerId,
                CustomerName                       = x.Order.Customer.FullName,
                CustomerEmail                      = x.Order.Customer.Email,
                LatestUpdatedOn                    = x.Order.LatestUpdatedOn,
                Coupon                             = x.Order.CouponCode,
                Items                              = x.Order.OrderItems.Count(),
                BillingAddressId                   = x.Order.BillingAddressId,
                BillingAddressAddressLine1         = x.Order.BillingAddress.AddressLine1,
                BillingAddressAddressLine2         = x.Order.BillingAddress.AddressLine2,
                BillingAddressContactName          = x.Order.BillingAddress.ContactName,
                BillingAddressCountryName          = x.Order.BillingAddress.Country.Name,
                BillingAddressDistrictName         = x.Order.BillingAddress.District.Name,
                BillingAddressZipCode              = x.Order.BillingAddress.ZipCode,
                BillingAddressPhone                = x.Order.BillingAddress.Phone,
                BillingAddressStateOrProvinceName  = x.Order.BillingAddress.StateOrProvince.Name,
                ShippingAddressAddressLine1        = x.Order.ShippingAddress.AddressLine1,
                ShippingAddressAddressLine2        = x.Order.ShippingAddress.AddressLine2,
                ShippingAddressId                  = x.Order.ShippingAddressId,
                ShippingAddressContactName         = x.Order.ShippingAddress.ContactName,
                ShippingAddressCountryName         = x.Order.ShippingAddress.Country.Name,
                ShippingAddressDistrictName        = x.Order.ShippingAddress.District.Name,
                ShippingAddressPhone               = x.Order.ShippingAddress.Phone,
                ShippingAddressStateOrProvinceName = x.Order.ShippingAddress.StateOrProvince.Name,
                ShippingAddressZipCode             = x.Order.ShippingAddress.ZipCode,
                OrderLineDiscountAmount            = x.DiscountAmount,
                OrderLineQuantity                  = x.Quantity,
                OrderLineTaxAmount                 = x.TaxAmount,
                OrderLineTaxPercent                = x.TaxPercent,
                OrderLineId                        = x.Id,
                ProductId                          = x.ProductId,
                ProductName                        = x.Product.Name,
                ProductPrice                       = x.ProductPrice
            })
                             .ToListAsync();

            foreach (var item in orderItems)
            {
                item.SubtotalString             = _currencyService.FormatCurrency(item.Subtotal);
                item.DiscountAmountString       = _currencyService.FormatCurrency(item.DiscountAmount);
                item.SubtotalWithDiscountString = _currencyService.FormatCurrency(item.SubtotalWithDiscount);
                item.TaxAmountString            = _currencyService.FormatCurrency(item.TaxAmount);
                item.ShippingAmountString       = _currencyService.FormatCurrency(item.ShippingAmount);
                item.PaymentFeeAmountString     = _currencyService.FormatCurrency(item.PaymentFeeAmount);
                item.OrderTotalString           = _currencyService.FormatCurrency(item.OrderTotal);

                item.OrderLineTaxAmountString      = _currencyService.FormatCurrency(item.OrderLineTaxAmount);
                item.OrderLineProductPriceString   = _currencyService.FormatCurrency(item.ProductPrice);
                item.OrderLineDiscountAmountString = _currencyService.FormatCurrency(item.OrderLineDiscountAmount);
                item.OrderLineTotalString          = _currencyService.FormatCurrency(item.OrderLineTotal);
                item.OrderLineRowTotalString       = _currencyService.FormatCurrency(item.OrderLineRowTotal);
            }

            var csvString = CsvConverter.ExportCsv(orderItems);
            var csvBytes  = Encoding.UTF8.GetBytes(csvString);
            // MS Excel need the BOM to display UTF8 Correctly
            var csvBytesWithUTF8BOM = Encoding.UTF8.GetPreamble().Concat(csvBytes).ToArray();

            return(File(csvBytesWithUTF8BOM, "text/csv", "order-lines-export.csv"));
        }
예제 #10
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var ProductImages = await _ProductImageService.Search(param);

            return(Ok(ProductImages));
        }
예제 #11
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var image = await _Service.Search(param);

            return(Ok(image));
        }
예제 #12
0
        public async Task <IActionResult> List([FromBody] SmartTableParam param)
        {
            var query       = _productRepository.Query().Where(x => !x.IsDeleted);
            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin"))
            {
                query = query.Where(x => x.VendorId == currentUser.VendorId);
            }

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;
                if (search.Name != null)
                {
                    string name = search.Name;
                    query = query.Where(x => x.Name.Contains(name));
                }

                if (search.Provider != null)
                {
                    string provider = search.Provider;
                    query = query.Where(x => x.Provider.Contains(provider));
                }

                if (search.From != null)
                {
                    string from = search.From;
                    query = query.Where(x => x.ShortDescription.Contains(from));
                }

                if (search.To != null)
                {
                    string to = search.To;
                    query = query.Where(x => x.Description.Contains(to));
                }

                if (search.HasOptions != null)
                {
                    bool hasOptions = search.HasOptions;
                    query = query.Where(x => x.HasOptions == hasOptions);
                }

                if (search.IsVisibleIndividually != null)
                {
                    bool isVisibleIndividually = search.IsVisibleIndividually;
                    query = query.Where(x => x.IsVisibleIndividually == isVisibleIndividually);
                }

                if (search.IsPublished != null)
                {
                    bool isPublished = search.IsPublished;
                    query = query.Where(x => x.IsPublished == isPublished);
                }

                if (search.CreatedOn != null)
                {
                    if (search.CreatedOn.before != null)
                    {
                        DateTimeOffset before = search.CreatedOn.before;
                        query = query.Where(x => x.CreatedOn <= before);
                    }

                    if (search.CreatedOn.after != null)
                    {
                        DateTimeOffset after = search.CreatedOn.after;
                        query = query.Where(x => x.CreatedOn >= after);
                    }
                }
            }

            var gridData = query.ToSmartTableResult(
                param,
                x => new ProductListItem
            {
                Id                    = x.Id,
                Name                  = x.Name,
                HasOptions            = x.HasOptions,
                IsVisibleIndividually = x.IsVisibleIndividually,
                IsFeatured            = x.IsFeatured,
                IsAllowToOrder        = x.IsAllowToOrder,
                IsCallForPricing      = x.IsCallForPricing,
                StockQuantity         = x.StockQuantity,
                CreatedOn             = x.CreatedOn,
                IsPublished           = x.IsPublished,
                From                  = x.ShortDescription,
                To                    = x.Description,
                Provider              = x.Provider,
                DepartureDate         = x.SpecialPriceStart,
                LandingDate           = x.SpecialPriceEnd
            });

            return(Json(gridData));
        }
예제 #13
0
        public async Task <SmartTableResult <Dto.Items.Orders.OrderItemItem> > Search(SmartTableParam param)
        {
            var query = _Repository.Query();

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;
                if (search.Keyword != null)
                {
                    string keyword = search.Keyword;
                    keyword = keyword.Trim().ToLower();
                    query   = query.Where(x => x.OrderId.ToString().Contains(keyword));
                }

                if (search.CreateStart != null)
                {
                    DateTime createStart = DateTime.Parse(search.CreateStart.ToString());
                    DateTime startOfDay  = createStart.StartOfDay();
                    query = query.Where(x => x.CreatedTime >= startOfDay);
                }

                if (search.CreateEnd != null)
                {
                    DateTime createEnd = DateTime.Parse(search.CreateEnd.ToString());
                    DateTime endOfDay  = createEnd.EndOfDay();
                    query = query.Where(x => x.CreatedTime <= endOfDay);
                }
            }
            //  param.Sort = new Sort() { Predicate = "DisplayOrder", Reverse = false };
            var gridData = query.ToSmartTableResult(param, x => x.ToItem());

            return(gridData);
        }
예제 #14
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var products = await _productService.Search(param);

            return(Ok(products));
        }
        public IActionResult Search([FromBody] SmartTableParam param)
        {
            var products = _emailAccountService.Search(param);

            return(Ok(products));
        }
예제 #16
0
        public async Task <ActionResult> List([FromBody] SmartTableParam param)
        {
            var query = _orderRepository
                        .Query();

            var currentUser = await _workContext.GetCurrentUser();

            if (!User.IsInRole("admin"))
            {
                query = query.Where(x => x.VendorId == currentUser.VendorId);
            }

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;
                if (search.Id != null)
                {
                    long id = search.Id;
                    query = query.Where(x => x.Id == id);
                }

                if (search.Status != null)
                {
                    var status = (OrderStatus)search.Status;
                    query = query.Where(x => x.OrderStatus == status);
                }

                if (search.CustomerName != null)
                {
                    string customerName = search.CustomerName;
                    query = query.Where(x => x.Customer.FullName.Contains(customerName));
                }

                if (search.CreatedOn != null)
                {
                    if (search.CreatedOn.before != null)
                    {
                        DateTimeOffset before = search.CreatedOn.before;
                        query = query.Where(x => x.CreatedOn <= before);
                    }

                    if (search.CreatedOn.after != null)
                    {
                        DateTimeOffset after = search.CreatedOn.after;
                        query = query.Where(x => x.CreatedOn >= after);
                    }
                }
            }

            var orders = query.ToSmartTableResult(
                param,
                order => new
            {
                order.Id,
                CustomerName = order.Customer.FullName,
                order.OrderTotal,
                OrderTotalString = _currencyService.FormatCurrency(order.OrderTotal),
                OrderStatus      = order.OrderStatus.ToString(),
                order.CreatedOn
            });

            return(Json(orders));
        }
예제 #17
0
        public async Task <ActionResult <SmartTableResult <MangeWarehouseProductItemVm> > > GetProducts(long warehouseId, [FromBody] SmartTableParam param)
        {
            var currentUser = await _workContext.GetCurrentUser();

            var warehouse = _warehouseRepository.Query().FirstOrDefault(x => x.Id == warehouseId);

            if (warehouse == null)
            {
                return(NotFound());
            }

            if (!User.IsInRole("admin") && warehouse.VendorId != currentUser.VendorId)
            {
                return(BadRequest(new { error = "You don't have permission to manage this warehouse" }));
            }

            var query = _productRepository
                        .Query()
                        .Where(x => !x.HasOptions && x.VendorId == warehouse.VendorId);

            var joinedQuery = query.GroupJoin
                              (
                _stockRepository.Query().Where(x => x.WarehouseId == warehouseId),
                product => product.Id, stock => stock.ProductId,
                (product, stock) => new { product, stock }
                              )
                              .SelectMany(x => x.stock.DefaultIfEmpty(), (x, stock) => new MangeWarehouseProductItemVm
            {
                Id       = x.product.Id,
                Name     = x.product.Name,
                Sku      = x.product.Sku,
                Quantity = stock.Quantity
            });

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;

                if (search.ProductName != null)
                {
                    string productName = search.ProductName;
                    joinedQuery = joinedQuery.Where(x => x.Name.Contains(productName));
                }

                if (search.ProductSku != null)
                {
                    string productSku = search.productSku;
                    joinedQuery = joinedQuery.Where(x => x.Sku.Contains(productSku));
                }

                if (search.IsExistInWarehouse != null)
                {
                    bool isExistInWarehouse = search.IsExistInWarehouse;
                    if (isExistInWarehouse)
                    {
                        joinedQuery = joinedQuery.Where(x => x.Quantity != null);
                    }
                    else
                    {
                        joinedQuery = joinedQuery.Where(x => x.Quantity == null);
                    }
                }
            }

            var products = joinedQuery.ToSmartTableResult(param);

            return(Ok(products));
        }
예제 #18
0
        public async Task <IActionResult> Search([FromBody] SmartTableParam param)
        {
            var discounts = await _discountService.Search(param);

            return(Ok(discounts));
        }
예제 #19
0
        public IActionResult List([FromBody] SmartTableParam param)
        {
            var query = _productRepository.Query().Where(x => !x.IsDeleted);

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;
                if (search.Name != null)
                {
                    string name = search.Name;
                    query = query.Where(x => x.Name.Contains(name));
                }

                if (search.HasOptions != null)
                {
                    bool hasOptions = search.HasOptions;
                    query = query.Where(x => x.HasOptions == hasOptions);
                }

                if (search.IsVisibleIndividually != null)
                {
                    bool isVisibleIndividually = search.IsVisibleIndividually;
                    query = query.Where(x => x.IsVisibleIndividually == isVisibleIndividually);
                }

                if (search.IsPublished != null)
                {
                    bool isPublished = search.IsPublished;
                    query = query.Where(x => x.IsPublished == isPublished);
                }

                if (search.CreatedOn != null)
                {
                    if (search.CreatedOn.before != null)
                    {
                        DateTimeOffset before = search.CreatedOn.before;
                        before = before.Date.AddDays(1);
                        query  = query.Where(x => x.CreatedOn <= before);
                    }

                    if (search.CreatedOn.after != null)
                    {
                        DateTimeOffset after = search.CreatedOn.after;
                        after = after.Date;
                        query = query.Where(x => x.CreatedOn >= after);
                    }
                }
            }

            var gridData = query.ToSmartTableResult(
                param,
                x => new ProductListItem
            {
                Id                    = x.Id,
                Name                  = x.Name,
                HasOptions            = x.HasOptions,
                IsVisibleIndividually = x.IsVisibleIndividually,
                IsFeatured            = x.IsFeatured,
                IsAllowToOrder        = x.IsAllowToOrder,
                IsCallForPricing      = x.IsCallForPricing,
                StockQuantity         = x.StockQuantity,
                CreatedOn             = x.CreatedOn,
                IsPublished           = x.IsPublished
            });

            return(Json(gridData));
        }
예제 #20
0
        public async Task <BaseResult> ExportToXlsx(SmartTableParam param)
        {
            var rs = new BaseResult()
            {
                Result = Result.Success
            };

            SmartTableResult <WardItem> wards = Search(param).Result;
            List <WardItem>             list  = wards.Items.ToList();

            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

            var workbook  = new ExcelFile();
            var worksheet = workbook.Worksheets.Add("Quản lí xã, phường");


            var style = worksheet.Rows[0].Style;

            style.Font.Weight         = ExcelFont.BoldWeight;
            style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[0].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[4].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[5].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[6].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[7].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;

            worksheet.Columns[0].SetWidth(50, LengthUnit.Pixel);
            worksheet.Columns[1].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[2].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[3].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[5].SetWidth(100, LengthUnit.Pixel);
            worksheet.Columns[6].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[7].SetWidth(150, LengthUnit.Pixel);

            worksheet.Cells["A1"].Value = "ID";
            worksheet.Cells["B1"].Value = "Tên Xã/Phường";
            worksheet.Cells["C1"].Value = "Huyện/Quận";
            worksheet.Cells["D1"].Value = "Tỉnh/Thành Phố";
            worksheet.Cells["E1"].Value = "Mã";
            worksheet.Cells["F1"].Value = "Miền";
            worksheet.Cells["G1"].Value = "Ngày Tạo";
            worksheet.Cells["H1"].Value = "Ngày Cập Nhật";

            worksheet.Tables.Add("Table1", "A1:H" + (list.Count + 1).ToString(), true);


            for (int r = 1; r <= list.Count; r++)
            {
                var item = list[r - 1];
                worksheet.Cells[r, 0].Value = item.Id;
                worksheet.Cells[r, 1].Value = item.Name;
                worksheet.Cells[r, 2].Value = item.District.Name;
                worksheet.Cells[r, 3].Value = item.District.City.Name;
                worksheet.Cells[r, 4].Value = item.Code;
                worksheet.Cells[r, 5].Value = item.CityRealmStr;
                worksheet.Cells[r, 6].Value = item.CreatedTimeDisplay;
                worksheet.Cells[r, 7].Value = item.UpdatedTimeDisplay;
            }
            string fileName = "ExportFile.xlsx";

            workbook.Save(fileName);

            rs.Message = "Thành Công!";
            return(rs);
        }
예제 #21
0
        public IActionResult List([FromBody] SmartTableParam param)
        {
            var query = _userRepository.Query()
                        .Include(x => x.Roles)
                        .ThenInclude(x => x.Role)
                        .Include(x => x.CustomerGroups)
                        .ThenInclude(x => x.CustomerGroup)
                        .Where(x => !x.IsDeleted);

            if (param.Search.PredicateObject != null)
            {
                dynamic search = param.Search.PredicateObject;

                if (search.Email != null)
                {
                    string email = search.Email;
                    query = query.Where(x => x.Email.Contains(email));
                }

                if (search.FullName != null)
                {
                    string fullName = search.FullName;
                    query = query.Where(x => x.FullName.Contains(fullName));
                }

                if (search.Role != null)
                {
                    string roleName = search.Role;
                    query = ((from i in query
                              from p in i.Roles
                              where p.Role.Name.Contains(roleName)
                              select i) as IQueryable <User>);
                }

                if (search.CustomerGroup != null)
                {
                    string customerGroupName = search.CustomerGroup;
                    query = ((from i in query
                              from p in i.CustomerGroups
                              where p.CustomerGroup.Name.Contains(customerGroupName)
                              select i) as IQueryable <User>);
                }

                if (search.CreatedOn != null)
                {
                    if (search.CreatedOn.before != null)
                    {
                        DateTimeOffset before = search.CreatedOn.before;
                        query = query.Where(x => x.CreatedOn <= before);
                    }

                    if (search.CreatedOn.after != null)
                    {
                        DateTimeOffset after = search.CreatedOn.after;
                        query = query.Where(x => x.CreatedOn >= after);
                    }
                }
            }

            var users = query.ToSmartTableResult(
                param,
                user => new
            {
                Id             = user.Id,
                Email          = user.Email,
                FullName       = user.FullName,
                CreatedOn      = user.CreatedOn,
                Roles          = string.Join(", ", user.Roles.Select(x => x.Role.Name)),
                CustomerGroups = string.Join(", ", user.CustomerGroups.Select(x => x.CustomerGroup.Name))
            });

            return(Json(users));
        }
예제 #22
0
        public async Task <BaseResult> ExportToXlsx(SmartTableParam param)
        {
            var rs = new BaseResult()
            {
                Result = Result.Success
            };

            SmartTableResult <WareHouseItem> warehouses = Search(param).Result;
            List <WareHouseItem>             list       = warehouses.Items.ToList();

            SpreadsheetInfo.SetLicense("FREE-LIMITED-KEY");

            var workbook  = new ExcelFile();
            var worksheet = workbook.Worksheets.Add("Quản lí nhà kho");


            var style = worksheet.Rows[0].Style;

            style.Font.Weight         = ExcelFont.BoldWeight;
            style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[0].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[3].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[4].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[7].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;
            worksheet.Columns[8].Style.HorizontalAlignment = HorizontalAlignmentStyle.Center;

            worksheet.Columns[0].SetWidth(50, LengthUnit.Pixel);
            worksheet.Columns[1].SetWidth(200, LengthUnit.Pixel);
            worksheet.Columns[2].SetWidth(200, LengthUnit.Pixel);
            worksheet.Columns[5].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[6].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[7].SetWidth(150, LengthUnit.Pixel);
            worksheet.Columns[8].SetWidth(150, LengthUnit.Pixel);

            worksheet.Cells["A1"].Value = "ID";
            worksheet.Cells["B1"].Value = "Tên Nhà Kho";
            worksheet.Cells["C1"].Value = "Địa Chỉ";
            worksheet.Cells["D1"].Value = "Vĩ Độ";
            worksheet.Cells["E1"].Value = "Kinh Độ";
            worksheet.Cells["F1"].Value = "SĐT Người Liên Hệ";
            worksheet.Cells["G1"].Value = "Tên Người Liên Hệ";
            worksheet.Cells["H1"].Value = "Ngày Tạo";
            worksheet.Cells["I1"].Value = "Ngày Cập Nhật";

            worksheet.Tables.Add("Table1", "A1:I" + (list.Count + 1).ToString(), true);


            for (int r = 1; r <= list.Count; r++)
            {
                var item = list[r - 1];
                worksheet.Cells[r, 0].Value = item.Id;
                worksheet.Cells[r, 1].Value = item.Name;
                worksheet.Cells[r, 2].Value = item.Address;
                worksheet.Cells[r, 3].Value = item.Latitude;
                worksheet.Cells[r, 4].Value = item.Longtitude;
                worksheet.Cells[r, 5].Value = item.PhoneNumber;
                worksheet.Cells[r, 6].Value = item.ContactName;
                worksheet.Cells[r, 7].Value = item.CreatedTimeDisplay;
                worksheet.Cells[r, 8].Value = item.UpdatedTimeDisplay;
            }
            string fileName = "ExportFile.xlsx";

            workbook.Save(fileName);

            rs.Message = "Thành Công!";
            return(rs);
        }