public CurrencyServiceTests() { this.dbContext = base.DatabaseInstance; this.currencyService = new CurrencyService(this.dbContext); }
public CostEntryServiceTests() { this.dbContext = base.DatabaseInstance; this.costEntryService = new CostEntryService(this.dbContext); }
private static void SeedDefaultRoles(UserManager <User> userManager, RoleManager <IdentityRole> roleManager, JustMonitorDbContext dbContext) { Task .Run(async() => { var adminRoleName = WebConstants.AdministratorRole; var roles = new[] { adminRoleName }; foreach (var role in roles) { var roleExist = await roleManager.RoleExistsAsync(role); if (!roleExist) { await roleManager.CreateAsync(new IdentityRole(role)); } } await RegisterAdminUser(userManager, adminRoleName, dbContext); }) .Wait(); }
private static async Task RegisterAdminUser(UserManager <User> userManager, string adminRoleName, JustMonitorDbContext dbContext) { var adminEmail = WebConstants.AdminEmail; var adminUserName = WebConstants.AdminUserName; var adminUser = await userManager.FindByEmailAsync(adminEmail); if (adminUser == null) { var defaultDisplayCurrencyId = dbContext .Currencies .FirstOrDefault(c => c.Code == GlobalConstants.DefaultCurrencyCode) ?.Id; adminUser = new User { Email = adminEmail, UserName = adminUserName, CurrencyId = defaultDisplayCurrencyId, EmailConfirmed = true, }; await userManager.CreateAsync(adminUser, WebConstants.AdminPassword); await userManager.AddToRoleAsync(adminUser, adminRoleName); } }
public FuelEntryServiceTests() { this.dbContext = base.DatabaseInstance; this.fuelEntryService = new FuelEntryService(this.dbContext); }
private static void SeedFuelEntries(JustMonitorDbContext dbContext) { if (!dbContext.FuelEntries.Any()) { var allVehicles = dbContext.Vehicles.ToList(); var defaultCurrencyId = dbContext .Currencies .First(c => c.Code == GlobalConstants.DefaultCurrencyCode) .Id; var random = new Random(); var currentDate = DateTime.UtcNow; var minDay = 1; var maxDay = 29; var odometerMinStep = 250; var odometerMaxStep = 750; var fuelQuantityMinValue = 20; var fuelQuantityMaxValue = 80; var note = "Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua."; var firstFuelingTypeId = dbContext.FuelEntryTypes.First(fet => fet.Name == "First fueling").Id; var fullFuelingTypeId = dbContext.FuelEntryTypes.First(fet => fet.Name == "Full").Id; var routesIds = dbContext.RouteTypes.Select(r => r.Id).ToArray(); var extrasIds = dbContext.ExtraFuelConsumers.Select(ex => ex.Id).ToArray(); var fuelEntriesToBeCreated = new List <FuelEntry>(); foreach (var vehicle in allVehicles) { var odometer = 100000; var startDate = new DateTime(currentDate.Year - 2, 1, 1); var hasAnyEntries = false; while (startDate < currentDate) { var day = random.Next(minDay, maxDay); var fuelingDate = new DateTime(startDate.Year, startDate.Month, day); var quantity = random.Next(fuelQuantityMinValue, fuelQuantityMaxValue); var tripOdometer = random.Next(odometerMinStep, odometerMaxStep); if (hasAnyEntries) { odometer += tripOdometer; } var model = new FuelEntryCreateServiceModel { DateCreated = fuelingDate, Odometer = odometer, TripOdometer = hasAnyEntries ? tripOdometer : 0, Average = hasAnyEntries ? ((double)quantity / tripOdometer) * 100 : 0, FuelQuantity = quantity, Price = (decimal)(quantity * (random.NextDouble() + 0.7)), CurrencyId = defaultCurrencyId, Note = note, FuelEntryTypeId = hasAnyEntries ? fullFuelingTypeId : firstFuelingTypeId, Routes = new List <FuelEntryRouteType> { new FuelEntryRouteType { RouteTypeId = routesIds[random.Next(0, routesIds.Length)] } }, ExtraFuelConsumers = new List <FuelEntryExtraFuelConsumer> { new FuelEntryExtraFuelConsumer { ExtraFuelConsumerId = extrasIds[random.Next(0, extrasIds.Length)] } }, VehicleId = vehicle.Id, FuelTypeId = vehicle.FuelTypeId }; var newFuelEntry = Mapper.Map <FuelEntry>(model); fuelEntriesToBeCreated.Add(newFuelEntry); startDate = startDate.AddMonths(1); hasAnyEntries = true; } } dbContext.FuelEntries.AddRange(fuelEntriesToBeCreated); dbContext.SaveChanges(); UpdateVehiclesStats(dbContext); } }
public VehicleModelService(JustMonitorDbContext db) : base(db) { }
public VehicleServiceTests() { this.dbContext = base.DatabaseInstance; this.vehicleService = new VehicleService(this.dbContext); }
public LogService(JustMonitorDbContext db) : base(db) { }
public BaseService(JustMonitorDbContext db) { this.db = db; }
public UserServiceTests() { this.dbContext = base.DatabaseInstance; this.userService = new UserService(this.dbContext); }
public PictureServiceTests() { this.dbContext = base.DatabaseInstance; this.pictureService = new PictureService(this.dbContext); }
public PictureService(JustMonitorDbContext db) : base(db) { }
public ManufacturerService(JustMonitorDbContext db) : base(db) { }
public CostEntryService(JustMonitorDbContext db) : base(db) { }