コード例 #1
0
        public ActionResult <ProcessingOrderDetailsDto> GetProcessingOrderDetails(int idOrder)
        {
            var order = orderService.GetOrderById(idOrder);

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

            var orderProducts = productOrderService.GetOrderProducts(order);
            var products      = new List <ProductForProcessingOrderDetailsDto>();

            foreach (var prod in orderProducts)
            {
                var product = productService.GetProductById(prod.IdProduct);

                products.Add(new ProductForProcessingOrderDetailsDto
                {
                    Id          = product.Id,
                    Amount      = prod.Amount,
                    ImageBase64 = product.ProductImages.FirstOrDefault().ImageBase64,
                    Name        = product.Name,
                    NotBought   = prod.NotBought
                });
            }

            string statusString;

            if (order.Status == EnumOrderStatus.Processing)
            {
                statusString = "En cours de traitement";
            }
            else
            {
                statusString = "En cours de livraison";
            }

            var orderDetails = new ProcessingOrderDetailsDto
            {
                Id           = idOrder,
                StatusString = statusString,
                Status       = order.Status,
                OrderPrice   = order.OrderPrice,
                Products     = products,
                Client       = _mapper.Map <ClientForPendingOrdersDto>(clientService.GetClientById(order.IdClient))
            };

            return(Ok(orderDetails));
        }
コード例 #2
0
        public ActionResult <ProcessingOrderDetailsDto> AbortBuyingProduct([FromBody] ProductToAbortBuyingDto boughtProduct)
        {
            var orderProduct = productOrderService.GetOrderProduct(boughtProduct.IdOrder, boughtProduct.IdProduct);

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

            orderProduct.NotBought = true;
            productOrderService.EditOrderProduct(orderProduct);


            var order    = orderService.GetOrderById(boughtProduct.IdOrder);
            var products = productOrderService.GetOrderProducts(order);

            var productsToReturn = new List <ProductForProcessingOrderDetailsDto>();


            double totalPrice = 0;

            foreach (var prod in products)
            {
                var product   = productService.GetProductById(prod.IdProduct);
                var notBought = true;

                if (!prod.NotBought)
                {
                    //The following code line wont work if the amount can't be converted to int
                    totalPrice += Math.Floor(1000 * (product.Price * Convert.ToInt32(prod.Amount))) / 1000;
                    notBought   = false;
                }

                productsToReturn.Add(new ProductForProcessingOrderDetailsDto
                {
                    Id          = product.Id,
                    Amount      = prod.Amount,
                    ImageBase64 = product.ProductImages.FirstOrDefault().ImageBase64,
                    Name        = product.Name,
                    NotBought   = notBought
                });
            }

            order.OrderPrice = totalPrice;
            orderService.EditOrder(order);

            var statusString = "En cours de livraison";


            var client = clientService.GetClientById(order.IdClient);

            var orderToReturn = new ProcessingOrderDetailsDto
            {
                Id           = order.Id,
                OrderPrice   = totalPrice,
                Products     = productsToReturn,
                Status       = EnumOrderStatus.InDelivery,
                StatusString = statusString,
                Client       = _mapper.Map <ClientForPendingOrdersDto>(client)
            };

            return(Ok(orderToReturn));
        }
コード例 #3
0
        public ActionResult <ProcessingOrderDetailsDto> DeliverOrder([FromBody] OrderToUpdateStatusDto orderToUpdate)
        {
            var order = orderService.GetOrderById(orderToUpdate.IdOrder);

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

            double totalPrice = 0;

            /*
             * If there are missing products we have to delete them from orderProducts table
             * and update the orderPrice
             */
            if (orderToUpdate.MissingProducts.Length != 0)
            {
                foreach (int id in orderToUpdate.MissingProducts)
                {
                    var orderProduct = productOrderService.GetOrderProduct(orderToUpdate.IdOrder, id);
                    orderProduct.NotBought = true;
                    productOrderService.EditOrderProduct(orderProduct);
                }
            }

            var products = productOrderService.GetOrderProducts(orderService.GetOrderById(orderToUpdate.IdOrder));

            var productsToReturn = new List <ProductForProcessingOrderDetailsDto>();


            foreach (var prod in products)
            {
                var product   = productService.GetProductById(prod.IdProduct);
                var notBought = true;

                if (!prod.NotBought)
                {
                    //The following code line wont work if the amount can't be converted to int
                    totalPrice += Math.Floor(1000 * (product.Price * Convert.ToInt32(prod.Amount))) / 1000;
                    notBought   = false;
                }

                productsToReturn.Add(new ProductForProcessingOrderDetailsDto
                {
                    Id          = product.Id,
                    Amount      = prod.Amount,
                    ImageBase64 = product.ProductImages.FirstOrDefault().ImageBase64,
                    Name        = product.Name,
                    NotBought   = notBought
                });
            }

            //var deliveryInfos = deliveryInfoService.GetOrderDeliveryInfo(orderToUpdate.IdOrder);

            order.Status     = EnumOrderStatus.InDelivery;
            order.OrderPrice = totalPrice;

            orderService.EditOrder(order);

            var statusString = "En cours de livraison";


            var client = clientService.GetClientById(order.IdClient);

            var orderToReturn = new ProcessingOrderDetailsDto
            {
                Id           = order.Id,
                OrderPrice   = totalPrice,
                Products     = productsToReturn,
                Status       = EnumOrderStatus.InDelivery,
                StatusString = statusString,
                Client       = _mapper.Map <ClientForPendingOrdersDto>(client)
            };

            return(Ok(orderToReturn));
        }