Пример #1
0
        // POST api/student
        //public HttpResponseMessage Post()
        public HttpResponseMessage Post(order ord)
        {
            DetailsRepository.save(ord);

            //If the orderEvent is not null the f****r fails !! serveral
            // hours wasted.
            ord.orderEvent = null;

            var response = Request.CreateResponse(HttpStatusCode.Created, ord);
            string url = Url.Link("DefaultApi", new { ord.id });
            response.Headers.Location = new Uri(url);
            //response.Content.Dispose();
            return response;
        }
Пример #2
0
        /*
        static public IList<order> GetDetails()
        {

            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {

                    return InventoryAvailability.Set();

                        //return ord.ToList();

                }
            }

        }
         */
        //static public void save (int EventId, order newOrder)
        public static void save(order newOrder)
        {
            // create our NHibernate session factory
            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {

                        events evt = session.Load<events>(newOrder.orderEvent.id);

                       // newOrder.orderEvent = null;

                         evt.addOrder(newOrder);

                         session.SaveOrUpdate(evt);

                         //InventoryAvailability.checkInventoryAndSave(newOrder, session);

                         /* Should get saved during the checkAvialbility */

                         //session.SaveOrUpdate(evt);

                   //session.Save(newOrder.orderEvent);

                         session.Transaction.Commit();

                         //newOrder.orderEvent = null;

                }

                // closing session causes problem of Lazy Loading?!

                //session.Close();

            }
        }
Пример #3
0
 virtual public void removeOrder(order Order)
 {
     this.orderList.Remove(Order);
 }
Пример #4
0
 virtual public void addOrder(order newOrder)
 {
     newOrder.orderEvent = this;
     this.orderList.Add(newOrder);
 }
Пример #5
0
        /* updates the inventory availability on the new Order */
        public static void checkInventoryAndSave(ref order newOrder, ISession session )
        {
            IList<order> ord = session.CreateCriteria(typeof(order)).List<order>();

                    ord.Add(newOrder);

                    IList<inventory> inv = session.CreateCriteria(typeof(inventory)).List<inventory>();

                    IList<bom> bom = session.CreateCriteria(typeof(bom)).List<bom>();

                    IList<loadlist> tmp = session.CreateCriteria(typeof(loadlist)).List<loadlist>();

                    var MaxDate = ord.Max(x => x.checkin);

                    var MinDate = ord.Min(x => x.checkout);

                    DateTime dMax = Convert.ToDateTime(MaxDate);

                    DateTime dMin = Convert.ToDateTime(MinDate);

                    TimeSpan DaysDiff = dMax - dMin;

                    DateTime[] myDate = new DateTime[DaysDiff.Days];

                    myDate[0] = dMin;

                    for (int i = 1; i < DaysDiff.Days; i++)
                    {
                        myDate[i] = dMin.AddDays(i);
                    }

                    IList<compOrdInv> CompQty = (from o in ord
                                                 join b in bom on o.item equals b.item
                                                 join i in inv on b.component equals i.item
                                                 from d in myDate
                                                 where d >= o.checkout && d <= o.checkin
                                                 select new compOrdInv
                                                 {
                                                     myDate = d
                                                     ,
                                                     item = b.component
                                                     ,
                                                     InvQty = i.qty
                                                     ,
                                                     ordQty = o.orderQty
                                                     ,
                                                     extQty = b.qty * o.orderQty
                                                 })
                                        .ToList();

                    IList<compOrdInv> Short = (from s in CompQty
                                               group s by new { s.myDate, s.item, s.InvQty }
                                                   into g
                                                   where g.Key.InvQty - g.Sum(x => x.extQty) < 0
                                                   select new compOrdInv
                                                   {
                                                       myDate = g.Key.myDate
                                                       ,
                                                       item = g.Key.item
                                                       ,
                                                       InvQty = g.Key.InvQty
                                                       ,
                                                       extQty = g.Sum(x => x.extQty)
                                                       ,
                                                       avl = g.Key.InvQty - g.Sum(x => x.extQty)
                                                   }).ToList();

                    IList<order> ordsEffected = (from o in ord
                                                 join b in bom on o.item equals b.item
                                                 join s in Short on b.component equals s.item
                                                 where s.myDate >= o.checkout
                                                 && s.myDate <= o.checkin
                                                 && o.available == (int)Available.Red
                                                 select o
                                                ).ToList();

                    IList<order> ordsAvl = (ord.Except(ordsEffected)).ToList();

                    foreach (order o in ordsAvl)
                    {
                        o.available = (int)Available.Green;
                        o.orderEvent.available = (int)Available.Green;
                        session.SaveOrUpdate(o.orderEvent);
                    }

                    foreach (order o in ordsEffected)
                    {
                        o.available = (int)Available.Red;
                        o.orderEvent.available = (int)Available.Red;
                        //session.SaveOrUpdate(o);
                        session.SaveOrUpdate(o.orderEvent);
                    }

                //    session.Transaction.Commit();

                 //   session.Close();
        }
Пример #6
0
 public virtual void removeOrder(order Order)
 {
     this.orderList.Remove(Order);
 }
Пример #7
0
 public virtual void addOrder(order newOrder)
 {
     newOrder.orderEvent = this;
     this.orderList.Add(newOrder);
 }