예제 #1
0
        public async Task <SalesFilteredResponse <object> > UpdateSale(UpdateSaleRequestModel request)
        {
            try {
                var updateSale = request.SaleViewModel;

                var changedSale = _context
                                  .CSVSales
                                  .FirstOrDefault(u => u.ID == updateSale.ID);

                if (changedSale == null)
                {
                    throw new EntityNotFoundException();
                }

                changedSale.Region        = updateSale.Region;
                changedSale.Country       = updateSale.Country;
                changedSale.ItemType      = updateSale.ItemType;
                changedSale.SalesChannel  = updateSale.SalesChannel;
                changedSale.OrderPriority = updateSale.OrderPriority;
                changedSale.OrderDate     = updateSale.OrderDate;
                changedSale.OrderID       = updateSale.OrderID;
                changedSale.ShipDate      = updateSale.ShipDate;
                changedSale.UnitsSold     = updateSale.UnitsSold;
                changedSale.UnitPrice     = updateSale.UnitPrice;
                changedSale.UnitCost      = updateSale.UnitCost;
                changedSale.TotalRevenue  = updateSale.TotalRevenue;
                changedSale.TotalCost     = updateSale.TotalCost;
                changedSale.TotalProfit   = updateSale.TotalProfit;

                _context.SaveChanges();

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

                return(await GetSearchDDLModel.ReturnSales(_context, csvSales, request));
            } catch (Exception ex) {
                throw ex;
            }
        }
예제 #2
0
        //PUT : /api/Users/Update
        public async Task <ActionResult <IEnumerable <object> > > Update([FromBody] UpdateSaleRequestModel request)
        {
            var update = new UpdateSaleCommand(_context);

            return(Ok(await Task.Run(() => update.UpdateSale(request))));
        }