Exemple #1
0
        public IHttpActionResult PostOrder([FromBody] OrderSet orderSet)
        {
            // OrderSet orderSet = new OrderSet();
            OrderTreatment _treatment = new OrderTreatment();
            List <Product> Products   = new List <Product>();

            //orderSet =request;
            foreach (var _item in db.OrderLineSet)
            {
                orderSet.OrderLineSet.Add(_item);
            }
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            if (_treatment.Validation(ref orderSet, ref Products))
            {
                _treatment.Insert(orderSet);
            }
            else
            {
            }
            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(orderSet.GetType());
            var       _StringWriter = new StringWriter();
            XmlWriter _Writer       = XmlWriter.Create(_StringWriter);

            x.Serialize(_Writer, orderSet);
            string _Xml = _StringWriter.ToString();



            return(CreatedAtRoute("DefaultApi", new { id = orderSet.IdOrder }, _Xml));
        }
        // POST: api/OrderJson
        public IHttpActionResult PostOrder([FromBody] JObject Response)
        {
            OrderTreatment _treatment = new OrderTreatment();
            OrderSet       orderSet   = new OrderSet();

            orderSet = Response.ToObject <OrderSet>();
            List <Product> Products = new List <Product>();

            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (_treatment.Validation(ref orderSet, ref Products))
            {
                orderSet.Note = "Commande enregistrée";
                //_treatment.Insert(orderSet);
                //Products.Add(db.Product.FirstOrDefault());
            }
            else
            {
                orderSet.Note = "Certains élements de la commande ne sont pas identifiables";
            }



            if (Products.Count() == 0 || Products == null)
            {
                _treatment.Invoice(orderSet);

                return(Ok(Products));
            }
            else
            {
                orderSet.Note = "Ces produits n'ont pas été trouvés";
                return(CreatedAtRoute("DefaultApi", new { id = orderSet.IdOrder }, order));
            }
        }