Пример #1
0
        public static void AddNewFurnitureToMarket(int count)
        {
            var furnRepo = new EFFurnitureRepository();

            var rand = new Random();

            for (var i = 0; i < count; i++)
            {
                var furnitureTypes = furnRepo.DbStaticFurniture.ToList();
                var max            = furnitureTypes.Count();
                var num            = rand.NextDouble();

                var index         = Convert.ToInt32(Math.Floor(num * max));
                var furnitureType = furnitureTypes[index];

                var contractTurnRandomOffset = (int)(furnitureType.BaseContractTurnLength * ((rand.NextDouble() - .5) * 2) * FurnitureContractVariation);
                var basePriceRandomOffset    = furnitureType.BaseCost * (decimal)((rand.NextDouble() - .5) * 2) * (decimal)FurnitureContractVariation;

                var newfurn = new Furniture
                {
                    dbType = furnitureType.dbType,
                    ContractTurnDuration = furnitureType.BaseContractTurnLength + contractTurnRandomOffset,
                    CovenantId           = -1,
                    HumanName            = $"{NameService.GetRandomFirstName()} {NameService.GetRandomLastName()} the {furnitureType.FriendlyName}",
                    Price             = Math.Floor(furnitureType.BaseCost + basePriceRandomOffset),
                    LastUseTimestamp  = DateTime.UtcNow,
                    ContractStartTurn = 0,
                    ContractEndTurn   = 0,
                    LastUsersIds      = ";",
                };

                furnRepo.SaveFurniture(newfurn);
            }
        }