public BoatRental(DAL.BoatRental boatRental)
 {
     this.id         = boatRental.id;
     this.startTime  = boatRental.startTime ?? DateTime.Now;
     this.endTime    = boatRental.endTime ?? DateTime.Now;
     this.boat       = new Boat(boatRental.Boat);
     this.numPersons = boatRental.numPersons ?? 0;
 }
        public DAL.Order saveInDB()
        {
            DAL.Order      entity     = null;
            DAL.BoatRental boatRental = MainClass.Instance.db.BoatRental.Where(v => v.id == this.boatRental.id).FirstOrDefault();

            if (boatRental == 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,
                    BoatRental  = boatRental
                });
                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);
        }
        public DAL.BoatRental saveInDB()
        {
            DAL.BoatRental entity = null;

            if (this.boat.id == 0)
            {
                return(null);
            }

            // Create, if not existant
            if (this.id == 0)
            {
                entity = MainClass.Instance.db.BoatRental.Add(new DAL.BoatRental()
                {
                    boatId     = this.boat.id,
                    numPersons = this.numPersons,
                    startTime  = this.startTime,
                    endTime    = this.endTime
                });
                MainClass.Instance.db.SaveChanges();
                this.id = entity.id;
            }
            else
            {
                entity = MainClass.Instance.db.BoatRental.Where(v => v.id == this.id).FirstOrDefault();

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

                entity.boatId     = this.boat.id;
                entity.numPersons = this.numPersons;
                entity.startTime  = this.startTime;
                entity.endTime    = this.endTime;
                MainClass.Instance.db.SaveChanges();
            }
            return(entity);
        }