Esempio n. 1
0
 public Boat(DAL.Boat boat)
 {
     this.id           = boat.id;
     this.name         = boat.name ?? throw new ArgumentNullException(nameof(boat.name));
     this.capacity     = boat.capacity;
     this.pricePerHour = boat.pricePerHour;
     // this.likeCount = (int)boat;
     //this.disLikeCount = (int)boat.disLikeCount;
     //this.imagePath = boat.imagePath;
 }
Esempio n. 2
0
        public bool removeBoat(Boat boat)
        {
            DAL.Boat b = MainClass.Instance.db.Boat.Where(v => v.id == boat.id).FirstOrDefault();

            if (b == null)
            {
                return(false);
            }

            b.location_id = 0;
            MainClass.Instance.db.SaveChanges();
            return(this.boats.Remove(boat));
        }
Esempio n. 3
0
        public bool addBoat(Boat boat)
        {
            if (this.boats.Contains(boat))
            {
                return(false);
            }

            DAL.Boat b = MainClass.Instance.db.Boat.Where(v => v.id == boat.id).FirstOrDefault();

            if (b == null && (b = boat.saveInDB()) == null)
            {
                return(false);
            }

            b.location_id = this.id;
            MainClass.Instance.db.SaveChanges();

            this.boats.Add(boat);
            return(true);
        }
Esempio n. 4
0
        public DAL.Boat saveInDB()
        {
            DAL.Boat entity = null;
            // Create, if not existant
            if (this.id == 0)
            {
                entity = MainClass.Instance.db.Boat.Add(new DAL.Boat()
                {
                    capacity     = this.capacity,
                    name         = this.name,
                    pricePerHour = this.pricePerHour,
                    location_id  = 0,
                    //seasonId = this.seasonId,
                    // likeCount = 0,
                    //disLikeCount = 0,
                    //imagePath = this.imagePath
                });
                MainClass.Instance.db.SaveChanges();
                this.id = entity.id;
            }
            else
            {
                entity = MainClass.Instance.db.Boat.Where(v => v.id == this.id).FirstOrDefault();

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

                entity.capacity     = this.capacity;
                entity.name         = this.name;
                entity.pricePerHour = this.pricePerHour;
                //entity.seasonId = this.seasonId;
                //entity.likeCount = this.likeCount;
                //entity.disLikeCount = this.disLikeCount;
                //entity.imagePath = this.imagePath;
                MainClass.Instance.db.SaveChanges();
            }
            return(entity);
        }