Esempio n. 1
0
        public async Task <IActionResult> PutOrder([FromBody] XmlOrders xmlOrders)
        {
            try
            {
                foreach (XmlOrder xmlOrder in xmlOrders.Orders)
                {
                    Order order = await _context.Orders.FirstOrDefaultAsync(o => o.Oxid == xmlOrder.Oxid);

                    if (order == null)
                    {
                        return(BadRequest("Order with Oxid: " + xmlOrder.Oxid + " doesent exist!"));
                    }
                    else
                    {
                        order.Status = xmlOrder.Status;
                    }
                }
            }
            catch (Exception e)
            {
                return(BadRequest(e.StackTrace + '\n' + e.Message));
            }

            await _context.SaveChangesAsync();

            return(NoContent());
        }
Esempio n. 2
0
        public async Task <IActionResult> PostOrder([FromBody] XmlOrders xmlOrders)
        {
            string error = String.Empty;

            foreach (XmlOrder xmlOrder in xmlOrders.Orders)
            {
                Order order = await _context.Orders.FirstOrDefaultAsync(o => o.Oxid == xmlOrder.Oxid);

                if (order != null)
                {
                    return(BadRequest("Order with Oxid: " + xmlOrder.Oxid + " already exist!"));
                }
                else
                {
                    try
                    {
                        order = mapper.MapToObject(xmlOrder) as Order;
                        if (order == null)
                        {
                            return(BadRequest("Wrong xml file"));
                        }
                        order.Status = "Unprocessed";
                        _context.Orders.Add(order);
                        await _context.SaveChangesAsync();
                    }
                    catch (Exception e)
                    {
                        error = e.StackTrace + '\n' + e.Message;
                    }
                }
            }
            return(Ok(xmlOrders));
        }
Esempio n. 3
0
        public object MapToXml(IEnumerable <object> valueToMap)
        {
            List <Order> orders         = valueToMap as List <Order>;
            XmlOrders    outerOrdersXml = new XmlOrders();

            foreach (Order order in orders)
            {
                XmlOrders innerOrdersXml = MapToXml(order) as XmlOrders;
                outerOrdersXml.Orders.Add(innerOrdersXml.Orders[0]);
            }
            return(outerOrdersXml);
        }
Esempio n. 4
0
        public async Task <IActionResult> GetOrders()
        {
            IEnumerable <Order> orders = await _context.Orders.Include(p => p.Payments)
                                         .Include(p => p.Orderarticles)
                                         .Include("Orderarticles.Article")
                                         .Include(p => p.Billingaddress)
                                         .ThenInclude(p => p.Country).ToListAsync();

            XmlOrders xmlOrders = mapper.MapToXml(orders) as XmlOrders;

            return(Ok(xmlOrders));
        }
Esempio n. 5
0
        public object MapToXml(object _orders)
        {
            XmlOrders xmlOrders = new XmlOrders();
            Order     order     = _orders as Order;
            XmlOrder  xmlOrder  = new XmlOrder();

            xmlOrder.Oxid      = order.Oxid;
            xmlOrder.Oxid      = order.Oxid;
            xmlOrder.Orderdate = order.Orderdate;
            xmlOrder.Status    = order.Status;

            XmlBillingaddress xmlAdress = new XmlBillingaddress();

            xmlAdress.Billemail     = order.Billingaddress.Billemail;
            xmlAdress.Billfname     = order.Billingaddress.Billfname;
            xmlAdress.Billstreet    = order.Billingaddress.Billstreet;
            xmlAdress.Billstreetnr  = order.Billingaddress.Billstreetnr;
            xmlAdress.Billcity      = order.Billingaddress.Billcity;
            xmlAdress.Billzip       = order.Billingaddress.Billzip;
            xmlAdress.Country.Geo   = order.Billingaddress.Country.Geo;
            xmlOrder.Billingaddress = xmlAdress;

            foreach (Payment payment in order.Payments)
            {
                XmlPayment xmlPayment = new XmlPayment();
                xmlPayment.Methodname = payment.Methodname;
                xmlPayment.Amount     = payment.Amount;
                xmlOrder.Payments.Payment.Add(xmlPayment);
            }

            foreach (Orderarticles orderArcticle in order.Orderarticles)
            {
                XmlOrderarticle xmlOrderArticle = new XmlOrderarticle();
                xmlOrderArticle.Artnum    = orderArcticle.Article.Artnum;
                xmlOrderArticle.Title     = orderArcticle.Article.Title;
                xmlOrderArticle.Amount    = orderArcticle.Article.Amount;
                xmlOrderArticle.Brutprice = orderArcticle.Article.Brutprice;
                xmlOrder.Articles.Orderarticle.Add(xmlOrderArticle);
            }
            xmlOrders.Orders.Add(xmlOrder);
            return(xmlOrders);
        }
Esempio n. 6
0
        public async Task <IActionResult> GetOrder([FromRoute] int oxid)
        {
            var order = new Order();

            try
            {
                order = await _context.Orders.Include(p => p.Payments)
                        .Include(p => p.Orderarticles)
                        .Include("Orderarticles.Article")
                        .Include(p => p.Billingaddress)
                        .ThenInclude(p => p.Country).FirstOrDefaultAsync(p => p.Oxid == oxid.ToString());

                if (order == null)
                {
                    return(NotFound());
                }
                XmlOrders xmlOrders = mapper.MapToXml(order) as XmlOrders;
                return(Ok(xmlOrders));
            }
            catch (Exception e)
            {
                return(BadRequest(e.StackTrace + '\n' + e.Message));
            }
        }