Ejemplo n.º 1
0
        public async Task <long> AddOrderItem(NewOrderItem model, int corpClientId)
        {
            var order = await orderApp.Get(model.OrderId, corpClientId);

            var prod = await productApp.Get(corpClientId, model.ProductId);

            model.ProductPrice = prod.Price;
            model.ItemNumber   = await orderItemApp.GetLastItemNumber(order.OrderNumber, corpClientId) + 1;

            var units = await measureUnitApp.GetAll();

            var pType = units.FirstOrDefault(u => u.MeasureUnitId == prod.MeasureUnitId).MeasureUnitTypeId;
            var qType = units.FirstOrDefault(u => u.MeasureUnitId == model.MeasureUnitId).MeasureUnitTypeId;

            await CalculateItem(model, prod.MeasureUnitId, pType, qType, corpClientId);

            var result = await orderItemApp.AddOrderItem(model, corpClientId);

            var nextStatus = await GetNextOrderStatus(order.OrderNumber, corpClientId);

            await orderApp.ChangeStatus(new UpdateOrderStatus
            {
                OrderNumber   = order.OrderNumber,
                OrderStatusId = nextStatus
            }, corpClientId);

            return(result);
        }
Ejemplo n.º 2
0
 public async Task<long> AddOrderItem(NewOrderItem model, int corpClientId)
 {
     var orderItem = mapper.Map<EF.OrderItem>(model);
     orderItem.LastStatusDate = DateTimeOffset.UtcNow;
     context.OrderItems.Add(orderItem);
     var result = await context.SaveChangesAsync();
     return orderItem.OrderItemId;
 }
Ejemplo n.º 3
0
        public IActionResult CreateOrderWithProducts([FromBody] NewOrderItem order)
        {
            if (order == null)
            {
                return(BadRequest());
            }

            _context.neworders.Add(order);
            _context.SaveChanges();

            return(CreatedAtRoute("ProductOrderDetails", new { id = order.Id }, order));
        }
Ejemplo n.º 4
0
        private async Task CalculateItem(NewOrderItem item, MeasureUnitEnum prodMeasureUnit, MeasureUnitTypeEnum pType, MeasureUnitTypeEnum qType, int corpClientId)
        {
            item.OriginalPrice = pricingApp.CalculatePricePerTotalWeight(new PriceRequest
            {
                ProductMeasureUnit  = prodMeasureUnit,
                ProductPrice        = item.ProductPrice,
                Quantity            = item.Quantity,
                QuantityMeasureUnit = item.MeasureUnitId
            }, pType, qType);
            var prodSummary = await dataSheetService.CalculateProduction(item.ProductId, item.MeasureUnitId, item.Quantity, corpClientId);

            item.Cost   = prodSummary.ProductionItems.Any() ? prodSummary.ProductionCost : new decimal?();
            item.Profit = prodSummary.ProductionItems.Any() ? (item.PriceAfterDiscount - prodSummary.ProductionCost) : new decimal?();
        }
Ejemplo n.º 5
0
        public void Post(int orderId, [FromBody] NewOrderItem newOrderItem)
        {
            Order order = getOrder(orderId);

            OrderItem orderItem = new OrderItem();

            orderItem.ProductId = newOrderItem.ProductId;
            orderItem.Count     = newOrderItem.Count;

            Product product = ProdContext.Products
                              .First(u => u.ProductId == newOrderItem.ProductId);

            product.UnitsInStock -= orderItem.Count;

            order.OrderItems.Add(orderItem);
            ProdContext.SaveChanges();
        }
Ejemplo n.º 6
0
        public IActionResult CreateOrderWithBundle([FromBody] NewBundleItem orderbundle, [FromRoute] long customerid)
        {
            //create a new order object
            NewOrderItem order = new NewOrderItem();

            //get all the products within the bundle
            var bundleprodlisting = from b in _context.newbundles
                                    join pb in _context.prodbundleassociations
                                    on b.Id equals pb.bundleId
                                    join p in _context.newproducts
                                    on pb.productId equals p.Id
                                    where b.Id == orderbundle.Id
                                    select new { p.Id, p.productPrice };

            //initialize the order price
            double orderprice = 0;

            //loop through each product and append it to the same order
            foreach (var item in bundleprodlisting)
            {
                order.productId = item.Id;
                //order.orderPrice = item.productPrice;
                orderprice += item.productPrice;
            }

            //calculate the order price by deducting 5% from the total cost
            orderprice = orderprice - (0.05 * orderprice);

            //set the order price
            order.orderPrice = orderprice;

            //set the customer id for the order from the URI
            order.customerId = customerid;

            _context.neworders.Add(order);
            _context.SaveChanges();

            return(CreatedAtRoute("BundleOrderDetails", new { id = order.Id }, order));
        }
Ejemplo n.º 7
0
 public async Task <long> AddOrderItem(NewOrderItem model, int corpClientId)
 {
     return(await repository.AddOrderItem(model, corpClientId));
 }
Ejemplo n.º 8
0
        public async Task <ActionResult <long> > AddItem(NewOrderItem model)
        {
            var id = await service.AddOrderItem(model, UserData.CorpClientId.Value);

            return(Ok(id));
        }