Esempio n. 1
0
        public static Vehicle CreateEntry(ulong CID, int carSort, int color = 0, int grade = 1)
        {
            using (var rc = Database.GetContext())
            {
                try
                {
                    VehicleTable.GetVehicleUpgrade(carSort, grade);
                }
                catch (Exception ex)
                {
                    Log.WriteError($"Failed to get vehicle {carSort} grade {grade} for Vehicle.CreateEntry: {ex.Message}");
                    return(null);
                }

                var lastVehicle = rc.Vehicles.Where(i => i.CID == (long)CID).OrderByDescending(i => i.CarID).FirstOrDefault();

                var newVehicle = new Models.Vehicle
                {
                    CID          = (long)CID,
                    CarID        = (lastVehicle?.CarID ?? 0) + 1,
                    CarType      = carSort,
                    Grade        = grade,
                    AuctionCount = 0,
                    Color        = color
                };

                rc.Vehicles.Add(newVehicle);
                rc.SaveChanges();

                return(new Vehicle(newVehicle.CarType, newVehicle));
            }
        }
Esempio n. 2
0
        private Vehicle(int id, Models.Vehicle dbVehicle = null, int grade = 1)
        {
            int lookupId    = id;
            int lookupGrade = grade;

            if (dbVehicle != null)
            {
                AuctionCount = (uint)dbVehicle.AuctionCount;
                Color        = (uint)dbVehicle.Color;
                CarID        = dbVehicle.CarID;
                CarType      = (uint)dbVehicle.CarType;
                Grade        = (uint)dbVehicle.Grade;
                Mitron       = dbVehicle.Mitron;
                Kms          = dbVehicle.Kms;
                SlotType     = 0;

                lookupId    = dbVehicle.CarType;
                lookupGrade = dbVehicle.Grade;
            }

            VehicleUpgradeEntry = VehicleTable.GetVehicleUpgrade(lookupId, lookupGrade);
            VehicleListEntry    = VehicleTable.Vehicles[lookupId];
        }
Esempio n. 3
0
 public static Vehicle FromDB(Models.Vehicle dbVehicle) => new Vehicle(dbVehicle.CarID, dbVehicle, dbVehicle.Grade);