Пример #1
0
        public GroupTripOrder orderGroupTrip(GroupTrip groupTrip, PaymentType paymentType, Address orderAddress, User user)
        {
            if (!this.users.Contains(user))
            {
                return(null);
            }

            if (groupTrip == null || orderAddress == null || user == null || !this.canOrderGroupTrip(groupTrip))
            {
                return(null);
            }

            if (groupTrip.saveInDB() == null)
            {
                return(null);
            }

            GroupTripOrder groupTripOrder = new GroupTripOrder(paymentType, DateTime.Now, user, orderAddress, ++numOrders, groupTrip);

            DAL.Order value = groupTripOrder.saveInDB();

            if (value == null)
            {
                return(null);
            }

            // value.boatToursManagerId = 1;
            entity.numOrders = this.numOrders;
            db.SaveChanges();

            this.orders.Add(groupTripOrder.orderNumber, groupTripOrder);
            return(groupTripOrder);
        }
 public GroupTripOrder(DAL.Order order) : base(order)
 {
     this.groupTrip = new GroupTrip(order.GroupTrip);
 }
Пример #3
0
        public bool canOrderGroupTrip(GroupTrip groupTrip)
        {
            if (groupTrip == null)
            {
                return(false);
            }

            if (DateTime.Compare(groupTrip.depatureTime, DateTime.Today) < 0)
            {
                return(false);
            }

            if (groupTrip.getNumPersonsOnBoard() <= 0)
            {
                return(false);
            }

            List <PriceCategory> priceCategories = groupTrip.getPriceCategories();
            int priceCategoriesFound             = 0;

            foreach (PriceCategory value in priceCategories)
            {
                if (this.priceCategories.Contains(value))
                {
                    priceCategoriesFound++;
                }
            }

            if (priceCategoriesFound != priceCategories.Count)
            {
                return(false);
            }

            if (!this.routes.Contains(groupTrip.route) || !this.ships.Contains(groupTrip.ship) ||
                !this.tripTypes.Contains(groupTrip.tripType))
            {
                return(false);
            }

            foreach (KeyValuePair <int, Order> entry in this.orders)
            {
                GroupTripOrder order = entry.Value as GroupTripOrder;

                if (order != null && groupTrip.ship == order.groupTrip.ship)
                {
                    /*
                     * Check, whether the time span of the new group trip overlaps with the available group trips
                     * if it's the same ship
                     */
                    if (DateTime.Compare(groupTrip.depatureTime, DateTime.Today) < 0 &&
                        DateTime.Compare(groupTrip.depatureTime, order.groupTrip.depatureTime) >= 0 &&
                        DateTime.Compare(groupTrip.depatureTime, order.groupTrip.returnTime) <= 0 ||
                        DateTime.Compare(groupTrip.returnTime, order.groupTrip.depatureTime) >= 0 &&
                        DateTime.Compare(groupTrip.returnTime, order.groupTrip.returnTime) <= 0)
                    {
                        return(false);
                    }
                }
            }
            return(true);
        }
 public GroupTripOrder(PaymentType paymentType, DateTime orderDate, User user, Address orderAddress, int orderNumber, GroupTrip groupTrip)
     : base(paymentType, orderDate, user, orderAddress, groupTrip.getTotalPrice(), orderNumber)
 {
     this.groupTrip = groupTrip ?? throw new ArgumentNullException(nameof(groupTrip));
 }