Exemplo n.º 1
0
        public int NumOfOrdersPerReq(GuestRequest req)
        {
            //List<Order> lst = (List<Order>)dal.GetAllOrders();
            //int numOfOrders = 0;
            //foreach (var item in lst)
            //{
            //    if (item.GuestRequestKey == req.GuestRequestKey)
            //        numOfOrders++;
            //}
            //return numOfOrders;
            int numOfOrders         = 0;
            IEnumerable <Order> lst = from item in dal.GetAllOrders()
                                      where item.GuestRequestKey == req.GuestRequestKey
                                      select item;

            foreach (var item in lst)
            {
                numOfOrders++;
            }
            return(numOfOrders);
        }
Exemplo n.º 2
0
        public void UpdateOrder(Order order, string text, string pic)//Updates Order
        {
            Order orig = GetAllOrders().FirstOrDefault(t => t.OrderKey == order.OrderKey);

            if ((orig.Status == Status.Closed_ClientRequest || orig.Status == Status.Closed_NoReply))
            {
                throw new TaskCanceledException("Status cannot be changed");
            }

            if (orig.Status == Status.Active && order.Status == Status.Active)
            {
                return;
            }
            if (orig.Status != Status.Active && order.Status == Status.Active)
            {
                return;
            }
            if (orig.Status == Status.Mail_Sent && order.Status == Status.Mail_Sent)
            {
                try
                {
                    //dal.UpdateOrder(order.Clone());
                }
                catch (KeyNotFoundException e)
                {
                    throw e;
                }
            }
            if (order.Status == Status.Closed_NoReply)
            {
                if (order.OrderDate == default(DateTime))
                {
                    throw new TaskCanceledException("Cannot Update order to closed before an email was sent");
                }
                try
                {
                    dal.UpdateOrder(order.Clone());
                }
                catch (KeyNotFoundException e)
                {
                    throw e;
                }
            }
            if (order.Status == Status.Closed_ClientRequest)
            {
                if (order.OrderDate == default(DateTime))
                {
                    throw new TaskCanceledException("Cannot Update order to closed before an email was sent");
                }
                Guest guest = dal.GetGuest(order.GuestRequestKey);
                guest.GuestStatus = Status.Closed_ClientRequest;
                UpdateGuestReq(guest);

                HostingUnit tmp = dal.GetHostingUnit(order.HostingUnitKey);
                if (!CheckOffDates(tmp, guest.EntryDate, guest.ReleaseDate))
                {
                    throw new TaskCanceledException("could not book dates");
                }
                Charge(FindHost(order.HostingUnitKey), DaysBetween(guest.EntryDate, guest.ReleaseDate)); //charges the host 10 nis
                // Charge(tmp, DaysBetween(guest.EntryDate, guest.ReleaseDate));
                UpdateHostUnit(tmp.Clone());                                                             //need if we figure out how to clone diary
                foreach (Order order1 in dal.GetAllOrders())                                             //closes all orders that are open for this guest
                {
                    if (order1.GuestRequestKey == guest.GuestRequestKey)
                    {
                        order1.Status = Status.Closed_ClientRequest;
                        dal.UpdateOrder(order1);
                    }
                }
                return;
            }
            if (order.Status == Status.Mail_Sent)
            {
                HostingUnit hosting = dal.GetHostingUnit(order.HostingUnitKey);
                if (!CheckIsBankAllowed(hosting.Owner, order))
                {
                    throw new TaskCanceledException("Cannot send mail. No debit authorization\n please update Automatic billing.");
                }
                SendMail(order, text, pic);
                order.OrderDate = DateTime.Now;
            }
            try
            {
                dal.UpdateOrder(order.Clone());
            }
            catch (KeyNotFoundException e)
            {
                throw e;
            }
        }