public void AddOrder(Order order)//adds a new order
        {
            HostingUnit hosting = dal.GetHostingUnit(order.HostingUnitKey);

            if (hosting == null)
            {
                throw new KeyNotFoundException("Invalid Hosting Unit");
            }
            Guest guest = dal.GetGuest(order.GuestRequestKey);

            if (guest == null)
            {
                throw new KeyNotFoundException("Invalid Guest");
            }
            order.Status     = Status.Active;
            order.CreateDate = DateTime.Now;

            try
            {
                dal.AddOrder(order.Clone());
            }
            catch (DuplicateWaitObjectException e)
            {
                throw e;
            }
        }
Exemple #2
0
        public void AddOrder(Order o)
        {
            List <Branch> branchH = (dal.GetListBranch().Where(i => i.BranchCode == o.Branch)).ToList <Branch>();

            if (branchH.Count() != 0)
            {
                if (branchH[0].HechsherBranch > o.OrderHechsher)
                {
                    throw new Exception("the order hechsher is not appropriate to the branch");
                }
            }
            if (o.CreditCard.Length != 8 && o.CreditCard.Length != 16)
            {
                throw new Exception("the digits number is wrong! ");
            }

            dal.AddOrder(o);
        }
Exemple #3
0
        public void AddOrder(long guestReqKey, long UnitKey)
        {
            if (!dal.GetAllUnits().Any(x => x.HostingUnitKey == UnitKey))
            {
                throw new KeyNotFoundException("The hosting unit key doesn't exist");
            }
            if (!dal.GetAllRequests().Any(x => x.GuestRequestKey == guestReqKey))
            {
                throw new KeyNotFoundException("The guest request key doesn't exist");
            }
            Order order = new Order
            {
                GuestRequestKey = guestReqKey,
                HostingUnitKey  = UnitKey,
                CreateDate      = DateTime.Now,
                OrderDate       = DateTime.MinValue,
                Status          = OrderStatus.NotYetHandle
            };

            GuestRequest certianRequest = FindReqByKey(guestReqKey);

            if (certianRequest.Status != GuestRequestStatus.Active)
            {
                throw new DataException("the request is not active");
            }
            DateTime entryDate   = certianRequest.EntryDate;
            DateTime releaseDate = certianRequest.ReleaseDate;

            bool[,] diary = null;
            try
            {
                foreach (var item in dal.GetAllUnits())
                {
                    if (item.HostingUnitKey == order.HostingUnitKey)
                    {
                        diary = item.Diary;
                    }
                }
            }
            catch (Exception exc)
            {
                if (exc is ArgumentNullException)
                {
                    throw new ArgumentNullException("Unable to copy content to array or list");
                }
                if (exc is ArgumentException)
                {
                    throw new ArgumentException("Unable to copy content to array or list");
                }
                else
                {
                    throw exc;
                }
            }

            for (DateTime i = entryDate; i < releaseDate; i = i.AddDays(1))
            {
                if (diary[i.Month - 1, i.Day - 1] == true)
                {
                    throw new DataException("the dates immpossible");
                }
            }
            try
            {
                dal.AddOrder(order);
            }
            catch (DuplicateWaitObjectException exc)
            {
                throw exc;
            }
            catch (Exception ex)
            {
                throw ex;
            }
        }