Пример #1
0
        public async Task <ActionResult <GetOrderDTO> > PostAsync([FromBody] PostOrderDTO orderDTO)
        {
            OrderEntity entity = _mapper.Map <PostOrderDTO, OrderEntity>(orderDTO);

            entity.UserId = HttpContext.User.FindFirstValue(ClaimTypes.NameIdentifier);
            if (entity.UserId == null)
            {
                throw new InvalidPermissionException(ErrorCode.InvalidUserId);
            }

            var result = await _manager.InsertAsync(entity);

            var dto = _mapper.Map <GetOrderDTO>(result);

            return(Ok(dto));
        }
Пример #2
0
        public static async Task <Order> PostOrder(Order order)
        {
            PostOrderDTO orderDTO = PostOrderDTO.FromOrder(order);
            string       content  = JsonConvert.SerializeObject(orderDTO);

            UserService serv   = UserService.GetInstance();
            HttpClient  client = new HttpClient();

            client.DefaultRequestHeaders.Add("Authorization", string.Format("Bearer {0}", serv.Token));
            HttpResponseMessage res = await client.PostAsync(new Uri($"https://flightappapi.azurewebsites.net/api/Shop/create_order/{serv.User.FlightId}"),
                                                             new HttpStringContent(content, Windows.Storage.Streams.UnicodeEncoding.Utf8, "application/json"));

            if (res.IsSuccessStatusCode)
            {
                OrderDTO response = JsonConvert.DeserializeObject <OrderDTO>(res.Content.ToString());
                return(response.ToOrder());
            }
            return(null);
        }
Пример #3
0
        public async Task <ActionResult <Order> > PostOrder([FromBody] PostOrderDTO order)
        {
            var orderToAdd = new Order
            {
                SellDate     = DateTime.Now,
                ShallDisplay = true,
                OrderState   = OrderState.New,
                InvoiceId    = null,
                OrderValue   = 0.0M,
                Username     = order.Invoice.Username
            };

            List <Product> products = new List <Product>();

            foreach (var item in order.PostOrders)
            {
                var product = await productService.GetByIdAsync(item.ProductId);

                products.Add(product);
                orderToAdd.OrderValue += (product.NettoPrice + decimal.Divide(product.VAT, 100) * product.NettoPrice) * item.QuantityOfProducts;
            }

            var placedOrder = await orderService.CreateOrder(orderToAdd);

            var orderItems = new List <OrderItem>();

            foreach (var product in products)
            {
                var orderItem = new OrderItem
                {
                    OrderId   = placedOrder.OrderId,
                    ProductId = product.ProductId
                };
                foreach (var item in order.PostOrders)
                {
                    if (item.ProductId == product.ProductId)
                    {
                        orderItem.Amount       = item.QuantityOfProducts;
                        orderItem.NettoPrice   = product.NettoPrice * item.QuantityOfProducts;
                        orderItem.BruttoPrice += (product.NettoPrice + decimal.Divide(product.VAT, 100) * product.NettoPrice) * item.QuantityOfProducts;
                    }
                }
                await orderItemService.CreateOrderItem(orderItem);

                orderItems.Add(orderItem);
            }

            EdiParser ediParser        = new EdiParser();
            var       mappedOrderItems = mapper.Map <List <OrderItem>, List <GetOrderItemForXml> >(orderItems);
            var       invoice          = await CreateInvoice(placedOrder.OrderId, order.Invoice);

            var invoiceXml = new XmlInvoice(invoice.InvoiceId, invoice.IssueDate, invoice.DeliveryDate,
                                            SynthPolInfo.supplierName, SynthPolInfo.supplierStreet, SynthPolInfo.supplierCity, SynthPolInfo.supplierZipCode, SynthPolInfo.supplierNIP,
                                            invoice.Name, invoice.Street, invoice.ZipCode, invoice.City, invoice.NIP, mappedOrderItems);
            YAXSerializer serializer      = new YAXSerializer(typeof(XmlInvoice));
            string        xmlString       = serializer.Serialize(invoiceXml);
            var           invoiceEdiToAdd = new InvoiceEdi
            {
                Username  = invoice.Username,
                InvoiceId = invoice.InvoiceId,
                EdiString = ediParser.Save(invoice.InvoiceId.ToString(), invoice.IssueDate.ToString(), invoice.DeliveryDate.ToString(),
                                           SynthPolInfo.supplierName, SynthPolInfo.supplierStreet, SynthPolInfo.supplierZipCode, SynthPolInfo.supplierCity,
                                           SynthPolInfo.supplierNIP, invoice.Name, invoice.Street, invoice.ZipCode, invoice.City, invoice.NIP, orderItems),
                XmlString = xmlString
            };

            var invoiceEdi = await invoiceEdiService.CreateInvoiceEdi(invoiceEdiToAdd);

            var newOrder = placedOrder;

            newOrder.InvoiceId = invoice.InvoiceId;
            await orderService.UpdateOrder(placedOrder, newOrder);

            var newInvoice = invoice;

            newInvoice.InvoiceEdiId = invoiceEdi.InvoiceEdiId;
            await invoiceService.UpdateInvoice(invoice, newInvoice);

            return(Ok());
        }