public async Task <CreateSaleFilteringResponse <object> > CreateSale(SearchSaleRequestModel request)
        {
            try {
                var newSale = request.SaleViewModel;
                var addSale = new CSVSale {
                    Region        = newSale.Region,
                    Country       = newSale.Country,
                    ItemType      = newSale.ItemType,
                    SalesChannel  = newSale.SalesChannel,
                    OrderPriority = newSale.OrderPriority,
                    OrderDate     = newSale.OrderDate,
                    OrderID       = newSale.OrderID,
                    ShipDate      = newSale.ShipDate,
                    UnitsSold     = newSale.UnitsSold,
                    UnitPrice     = newSale.UnitPrice,
                    UnitCost      = newSale.UnitCost,
                    TotalRevenue  = newSale.TotalRevenue,
                    TotalCost     = newSale.TotalCost,
                    TotalProfit   = newSale.TotalProfit
                };

                _context.CSVSales.Add(addSale);
                await _context.SaveChangesAsync();

                var csvSales = _context.CSVSales
                               .OrderBy(x => x.OrderDate)
                               .AsNoTracking();


                var result = await GetSearchDDLModel.ReturnSales(_context, csvSales, request);

                return(new CreateSaleFilteringResponse <object> {
                    Total = result.Total,
                    Length = result.Length,
                    Data = result.Data,
                    DropDownLists = result.DropDownLists,
                    NewSaleId = addSale.ID
                });
            } catch (Exception ex) {
                throw ex;
            }
        }
Beispiel #2
0
        //POST : /api/Users/Search
        public async Task <ActionResult <IEnumerable <object> > > Search([FromBody] SearchSaleRequestModel request)
        {
            var search = new SearchSalesQuery(_context);

            return(Ok(await Task.Run(() => search.SearchSales(request))));
        }
Beispiel #3
0
        public async Task <SalesFilteredResponse <object> > SearchSales(SearchSaleRequestModel request)
        {
            try {
                var saleViewModel = request.SaleViewModel;
                var csvSales      = _context.CSVSales
                                    .OrderBy(x => x.OrderDate)
                                    .AsNoTracking();

                if (saleViewModel.ID > 0)
                {
                    csvSales = csvSales.Where(x => x.ID == saleViewModel.ID);
                }
                if (!String.IsNullOrEmpty(saleViewModel.Region))
                {
                    csvSales = csvSales.Where(x => x.Region == saleViewModel.Region);
                }
                if (!String.IsNullOrEmpty(saleViewModel.Country))
                {
                    csvSales = csvSales.Where(x => x.Country == saleViewModel.Country);
                }
                if (!String.IsNullOrEmpty(saleViewModel.ItemType))
                {
                    csvSales = csvSales.Where(x => x.ItemType == saleViewModel.ItemType);
                }
                if (!String.IsNullOrEmpty(saleViewModel.SalesChannel))
                {
                    csvSales = csvSales.Where(x => x.SalesChannel == saleViewModel.SalesChannel);
                }
                if (!String.IsNullOrEmpty(saleViewModel.OrderPriority))
                {
                    csvSales = csvSales.Where(x => x.OrderPriority == saleViewModel.OrderPriority);
                }
                if (saleViewModel.OrderID > 0)
                {
                    csvSales = csvSales.Where(x => x.OrderID == saleViewModel.OrderID);
                }

                var totalCount = await csvSales.LongCountAsync();

                var countrys = await _context
                               .CSVSales.Select(p => p.Country)
                               .OrderBy(x => x)
                               .Distinct()
                               .ToListAsync();

                var itemTypes = await _context
                                .CSVSales.Select(p => p.ItemType)
                                .OrderBy(x => x)
                                .Distinct()
                                .ToListAsync();

                var regions = await _context
                              .CSVSales.Select(p => p.Region)
                              .OrderBy(x => x)
                              .Distinct()
                              .ToListAsync();

                var salesChannels = await _context
                                    .CSVSales.Select(p => p.SalesChannel)
                                    .OrderBy(x => x)
                                    .Distinct()
                                    .ToListAsync();

                if (csvSales == null || totalCount == 0)
                {
                    return(new SalesFilteredResponse <object>());
                }

                var paginatedCSVSales = await csvSales
                                        .Paginate(request)
                                        .ToListAsync();

                return(new SalesFilteredResponse <object> {
                    Total = totalCount,
                    Length = paginatedCSVSales.Count,
                    Data = paginatedCSVSales,
                    DropDownLists = new DropDownLists()
                    {
                        CountryList = countrys,
                        ItemTypeList = itemTypes,
                        RegionList = regions,
                        SalesChannelList = salesChannels
                    }
                });
            } catch (Exception ex) {
                throw ex;
            }
        }
Beispiel #4
0
        //POST : /api/Users/Create
        public async Task <ActionResult <IEnumerable <object> > > Create([FromBody] SearchSaleRequestModel request)
        {
            var create = new CreateSaleCommand(_context);

            return(Ok(await Task.Run(() => create.CreateSale(request))));
        }