Exemplo n.º 1
0
        // POST api/inventory
        //public HttpResponseMessage Post(List<order> ords)
        public events Post(events evt)
        {
            //DetailsRepository.saveAll(ords);
            DetailsRepository.saveAll(evt);

            var sessionFactory = FluentNHibernate.CreateSessionFactory();

            using (var session = sessionFactory.OpenSession())
            {
                // retreive all stores and display them
                using (session.BeginTransaction())
                {
                    evt = session.Load <events>(evt.id);

                    IList <order> ord = evt.orderList.ToList();

                    foreach (order o in ord)
                    {
                        o.orderEvent = null;
                    }
                }
            }

            return(evt);
            //string msg = "Items updated";
            //var response = Request.CreateResponse(HttpStatusCode.Created, evt);
            //string url = Url.Link("DefaultApi", new { evt.id });
            //response.Headers.Location = new Uri(url);
            //return response;
        }
Exemplo n.º 2
0
        static private void SetInvAvailability(int EventId, Available avlType)
        {
            // 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>(EventId);

                    IList <order> ordList = evt.orderList.ToList();

                    if (ordList.Count == 0)
                    {
                        session.Close();
                        return;
                    }

                    var MaxDate = evt.checkIn;  // ordList.Max(x => x.checkin);

                    var MinDate = evt.checkOut; // ordList.Min(x => x.checkout);

                    if (avlType == Available.Red)
                    {
                        MaxDate = evt.eventDate; MinDate = evt.eventDate;
                    }

                    DateTime dMax = Convert.ToDateTime(MaxDate);

                    DateTime dMin = Convert.ToDateTime(MinDate);

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

                    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>();

                    TimeSpan DaysDiff = dMin - dMax;

                    int Days = 1;

                    if (DaysDiff.Days > 0)
                    {
                        Days = DaysDiff.Days;
                    }

                    DateTime[] myDate = new DateTime[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.orderEvent.checkOut &&
                                                  d <= o.orderEvent.checkIn &&
                                                  avlType == Available.Yellow ||
                                                  d.ToShortDateString() == o.orderEvent.eventDate.ToShortDateString() &&
                                                  avlType == Available.Red
                                                  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> ordAffected = (from o in ord
                                                 join b in bom on o.item equals b.item
                                                 join s in Short on b.component equals s.item
                                                 join ol in ordList on o.id equals ol.id
                                                 where s.myDate >= o.checkout &&
                                                 s.myDate <= o.checkin
                                                 select o
                                                 ).ToList();

                    if (avlType == Available.Yellow)
                    {
                        foreach (order o in ordList)
                        {
                            o.available            = (int)Available.Green;
                            o.orderEvent.available = (int)Available.Green;
                            session.SaveOrUpdate(o.orderEvent);
                        }
                    }

                    foreach (order o in ordAffected)
                    {
                        o.available            = (int)avlType;
                        o.orderEvent.available = (int)avlType;
                        session.SaveOrUpdate(o);
                        session.SaveOrUpdate(o.orderEvent);
                    }


                    session.Transaction.Commit();

                    session.Close();
                }
            }
        }