public DAL.GroupTrip saveInDB()
        {
            DAL.GroupTrip entity = null;

            if (this.route.id == 0 || this.ship.id == 0 || this.tripType.id == 0)
            {
                return(null);
            }

            // Create, if not existant
            if (this.id == 0)
            {
                entity = MainClass.Instance.db.GroupTrip.Add(new DAL.GroupTrip()
                {
                    startTime  = this.depatureTime,
                    endTime    = this.returnTime,
                    routeId    = this.route.id,
                    shipId     = this.ship.id,
                    tripTypeId = this.tripType.id
                });

                foreach (KeyValuePair <PriceCategory, int> entry in this.personsOnBoard)
                {
                    entity.GroupTripPriceCategory.Add(new DAL.GroupTripPriceCategory()
                    {
                        group_trip_id     = this.id,
                        price_category_id = entry.Key.id,
                        quantity          = entry.Value
                    });
                }
                MainClass.Instance.db.SaveChanges();
                this.id = entity.id;
            }
            else
            {
                entity = MainClass.Instance.db.GroupTrip.Where(v => v.id == this.id).FirstOrDefault();

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

                entity.startTime  = this.depatureTime;
                entity.endTime    = this.returnTime;
                entity.routeId    = this.route.id;
                entity.shipId     = this.ship.id;
                entity.tripTypeId = this.tripType.id;
                MainClass.Instance.db.SaveChanges();
            }
            return(entity);
        }
        public GroupTrip(DAL.GroupTrip groupTrip)
        {
            this.id = groupTrip.id;

            this.route          = new Route(groupTrip.Route);
            this.depatureTime   = depatureTime;
            this.returnTime     = returnTime;
            this.personsOnBoard = personsOnBoard ?? throw new ArgumentNullException(nameof(personsOnBoard));
            this.tripType       = new TripType(groupTrip.TripType);
            this.ship           = new Ship(groupTrip.Ship);

            foreach (DAL.GroupTripPriceCategory gtpc in groupTrip.GroupTripPriceCategory)
            {
                this.personsOnBoard.Add(new PriceCategory(gtpc.PriceCategory), gtpc.quantity);
            }
        }
        public DAL.Order saveInDB()
        {
            DAL.Order     entity    = null;
            DAL.GroupTrip groupTrip = MainClass.Instance.db.GroupTrip.Where(v => v.id == this.groupTrip.id).FirstOrDefault();

            if (groupTrip == null || this.orderAddress.id == 0 || this.user.id == 0)
            {
                return(null);
            }

            // Create, if not existant
            if (this.id == 0)
            {
                entity = MainClass.Instance.db.Order.Add(new DAL.Order()
                {
                    addressId   = this.orderAddress.id,
                    billed      = this.billed,
                    orderDate   = this.orderDate,
                    orderNumber = this.orderNumber,
                    paymentType = (int)this.paymentType,
                    price       = Convert.ToDouble(this.price),
                    userId      = this.user.id,
                    GroupTrip   = groupTrip
                });
                MainClass.Instance.db.SaveChanges();
                this.id = entity.id;
            }
            else
            {
                entity = MainClass.Instance.db.Order.Where(v => v.id == this.id).FirstOrDefault();

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

                entity.addressId   = this.orderAddress.id;
                entity.billed      = this.billed;
                entity.orderDate   = this.orderDate;
                entity.orderNumber = this.orderNumber;
                entity.paymentType = (int)this.paymentType;
                entity.price       = Convert.ToDouble(this.price);
                entity.userId      = this.user.id;
                MainClass.Instance.db.SaveChanges();
            }
            return(entity);
        }