public IHttpActionResult GetProductById(int Id)
        {
            GenericImplement <Product> _GenericMethod = new GenericImplement <Product>();
            Product _product = _GenericMethod.GetSingleById(Id);

            return(Ok(_product));
        }
Example #2
0
        public IHttpActionResult GetCreate_orderLine(string _IdO)
        {
            int      _ido  = int.Parse(_IdO);
            OrderSet order = db.OrderSet.Find(_ido);

            GenericImplement <OrderLineSet> _GenericMethod = new GenericImplement <OrderLineSet>();

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

            OrderLineSet _OrderLine = new OrderLineSet();

            _GenericMethod.Insert(_OrderLine);

            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_OrderLine.GetType());
            var       _StringWriter = new StringWriter();
            XmlWriter _Writer       = XmlWriter.Create(_StringWriter);

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

            return(Ok(_Xml));
        }
        //GET:api/Product
        public IEnumerable <Product> GetAll()
        {
            GenericImplement <Product> _GenericMethod = new GenericImplement <Product>();
            IEnumerable <Product>      products       = _GenericMethod.GetAll();

            return(products);
        }
        public IHttpActionResult Post(Product P)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }
            GenericImplement <Product> _products = new GenericImplement <Product>();

            _products.Insert(P);
            return(CreatedAtRoute("DefaultApi", new { id = P.IdProduct }, _products));
        }
        public IHttpActionResult GetOrder(int id)
        {
            GenericImplement <OrderSet> _GenericMethod = new GenericImplement <OrderSet>();
            OrderSet _orderSet = _GenericMethod.Find(id);

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

            return(Ok(_orderSet));
        }
        public IHttpActionResult GetCreateOrder(string IdC)
        {
            int      id       = int.Parse(IdC);
            Customer custumer = db.Customer.Find(id);
            GenericImplement <OrderSet> _GenericMethod = new GenericImplement <OrderSet>();

            if (custumer == null)
            {
                return(NotFound());
            }
            OrderSet order = new OrderSet();


            _GenericMethod.Insert(order);
            return(Ok(order));
        }
        public IHttpActionResult GetProductOfOrder(string _IdOL)
        {
            int _idol = int.Parse(_IdOL);

            OrderLineSet   _orderL   = db.OrderLineSet.Find(_idol);
            List <Product> _products = new List <Product>();

            GenericImplement <OrderLineSet> _GenericMethod = new GenericImplement <OrderLineSet>();

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

            _products = db.Product.Where(u => u.OrderLine_Id == _idol).ToList();
            return(Ok(_products));
        }
        public IHttpActionResult GetOrderLinesOfOrder(string _IdO)
        {
            int      _ido  = int.Parse(_IdO);
            OrderSet order = db.OrderSet.Find(_ido);

            GenericImplement <OrderLineSet> _GenericMethod = new GenericImplement <OrderLineSet>();

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

            List <OrderLineSet> _orderLine = new List <OrderLineSet>();

            _orderLine = db.OrderLineSet.Where(u => u.Order_Id == _ido).ToList();
            return(Ok(_orderLine));
        }
Example #9
0
        public IHttpActionResult GetAddProduct(string _IdOL, string _IdP)
        {
            int          _idol   = int.Parse(_IdOL);
            int          _idp    = int.Parse(_IdP);
            OrderLineSet orderL  = db.OrderLineSet.Find(_idol);
            Product      product = db.Product.Find(_idp);

            GenericImplement <OrderLineSet> _GenericMethod = new GenericImplement <OrderLineSet>();

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

            if (orderL.Product == product)
            {
                orderL.Quantity = orderL.Quantity + 1;
                _GenericMethod.Update(orderL);
                _GenericMethod.SaveAll();
            }
            else
            {
                OrderLineSet _orderLine = (OrderLineSet)GetCreate_orderLine("" + orderL.Order_Id);
                _orderLine.Quantity = 1;
                _orderLine.Product  = product;
                _GenericMethod.SaveAll();
                System.Xml.Serialization.XmlSerializer x1 = new System.Xml.Serialization.XmlSerializer(_orderLine.GetType());
                var       _StringWriter1 = new StringWriter();
                XmlWriter _Writer1       = XmlWriter.Create(_StringWriter1);
                x1.Serialize(_Writer1, _orderLine);
                string _Xml1 = _StringWriter1.ToString();
                return(Ok(_Xml1));
            }
            System.Xml.Serialization.XmlSerializer x2 = new System.Xml.Serialization.XmlSerializer(orderL.GetType());
            var       _StringWriter2 = new StringWriter();
            XmlWriter _Writer2       = XmlWriter.Create(_StringWriter2);

            x2.Serialize(_Writer2, orderL);
            string _Xml2 = _StringWriter2.ToString();

            return(Ok(_Xml2));
        }
 public bool Invoice(OrderSet order)
 {
     try
     {
         InvoiceSet _invoice = new InvoiceSet();
         GenericImplement <InvoiceSet> _GenericImplement = new GenericImplement <InvoiceSet>();
         _invoice.OrderSet      = db.OrderSet.Find(order.IdOrder);
         _invoice.InvoiceNumber = db.InvoiceSet.Count() + 1;
         _invoice.InvoiceDate   = DateTime.Now;
         _invoice.HTAmount      = order.HTAmount;
         _invoice.TTCAmount     = order.TTCAmount;
         _invoice.TotalOfLines  = (short)_invoice.InvoiceLineSet.Count();
         _invoice.Order_Id      = order.IdOrder;
         _GenericImplement.Insert(_invoice);
         return(true);
     }
     catch (Exception)
     {
         return(false);
     }
 }
Example #11
0
        public IHttpActionResult GetCreateOrder(string _IdC)
        {
            int      _id      = int.Parse(_IdC);
            Customer custumer = db.Customer.Find(_id);
            GenericImplement <OrderSet> _GenericMethod = new GenericImplement <OrderSet>();

            if (custumer == null)
            {
                return(NotFound());
            }
            OrderSet _Order = new OrderSet();

            _GenericMethod.Insert(_Order);

            System.Xml.Serialization.XmlSerializer x = new System.Xml.Serialization.XmlSerializer(_Order.GetType());
            var       _StringWriter = new StringWriter();
            XmlWriter _Writer       = XmlWriter.Create(_StringWriter);

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

            return(Ok(_Xml));
        }
        // GET: api/OrderJson
        public List <OrderSet> GetOrder()
        {
            GenericImplement <OrderSet> _GenericMethod = new GenericImplement <OrderSet>();

            return(_GenericMethod.GetAll().ToList());
        }