示例#1
0
        private static List <DAL.Ship> ConvertShips(DAL.Player player, List <Ship> domainShips)
        {
            var dalShips = new List <DAL.Ship>();

            // Convert all Domain ships to DAL ship objects
            foreach (var domainShip in domainShips)
            {
                var dalShip = new DAL.Ship {
                    Player       = player,
                    Title        = domainShip.Title,
                    Symbol       = domainShip.Symbol,
                    Size         = domainShip.Size,
                    Direction    = (int)domainShip.Direction,
                    ShipStatuses = null,
                    X            = domainShip.ShipPos.X,
                    Y            = domainShip.ShipPos.Y
                };

                dalShip.ShipStatuses = ConvertShipStatus(dalShip, domainShip.ShipStatuses);

                dalShips.Add(dalShip);
            }

            return(dalShips);
        }
示例#2
0
        public DAL.Ship saveInDB()
        {
            DAL.Ship entity = null;

            // Create, if not existant
            if (this.id == 0)
            {
                entity = MainClass.Instance.db.Ship.Add(new DAL.Ship()
                {
                    capacity = this.capacity,
                    name     = this.name
                });
                MainClass.Instance.db.SaveChanges();
                this.id = entity.id;
            }
            else
            {
                entity = MainClass.Instance.db.Ship.Where(v => v.id == this.id).FirstOrDefault();

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

                entity.capacity = this.capacity;
                entity.name     = this.name;
                MainClass.Instance.db.SaveChanges();
            }
            return(entity);
        }
        public bool removeShip(Ship ship)
        {
            DAL.Ship entity = db.Ship.Where(v => v.id == ship.id).FirstOrDefault();

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

            //entity.boatToursManagerId = null;
            db.SaveChanges();
            return(this.ships.Remove(ship));
        }
示例#4
0
        private static List <DAL.ShipStatus> ConvertShipStatus(DAL.Ship dalShip,
                                                               ShipStatus[] domainShipStatuses)
        {
            var dalStatuses = new List <DAL.ShipStatus>();

            // Convert all Domain Ship status blocks to DAL ship status blocks
            for (int i = 0; i < domainShipStatuses.Length; i++)
            {
                var dalStatus = new DAL.ShipStatus {
                    Ship   = dalShip,
                    Status = (int)domainShipStatuses[i],
                    Offset = i
                };

                dalStatuses.Add(dalStatus);
            }

            return(dalStatuses);
        }
        public bool addShip(Ship ship)
        {
            if (this.ships.Contains(ship))
            {
                return(false);
            }

            DAL.Ship entity = db.Ship.Where(v => v.id == ship.id).FirstOrDefault();

            if (entity == null && (entity = ship.saveInDB()) == null)
            {
                return(false);
            }

            //entity.boatToursManagerId = this.id;
            db.SaveChanges();

            this.ships.Add(ship);
            return(true);
        }
示例#6
0
 public Ship(DAL.Ship ship)
 {
     this.id       = ship.id;
     this.capacity = ship.capacity;
     this.name     = ship.name;
 }