Esempio n. 1
0
 public CurrencyServiceTests()
 {
     this.dbContext       = base.DatabaseInstance;
     this.currencyService = new CurrencyService(this.dbContext);
 }
Esempio n. 2
0
 public CostEntryServiceTests()
 {
     this.dbContext        = base.DatabaseInstance;
     this.costEntryService = new CostEntryService(this.dbContext);
 }
Esempio n. 3
0
        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();
        }
Esempio n. 4
0
        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);
            }
        }
Esempio n. 5
0
 public FuelEntryServiceTests()
 {
     this.dbContext        = base.DatabaseInstance;
     this.fuelEntryService = new FuelEntryService(this.dbContext);
 }
Esempio n. 6
0
        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);
            }
        }
Esempio n. 7
0
 public VehicleModelService(JustMonitorDbContext db)
     : base(db)
 {
 }
Esempio n. 8
0
 public VehicleServiceTests()
 {
     this.dbContext      = base.DatabaseInstance;
     this.vehicleService = new VehicleService(this.dbContext);
 }
Esempio n. 9
0
 public LogService(JustMonitorDbContext db)
     : base(db)
 {
 }
Esempio n. 10
0
 public BaseService(JustMonitorDbContext db)
 {
     this.db = db;
 }
Esempio n. 11
0
 public UserServiceTests()
 {
     this.dbContext   = base.DatabaseInstance;
     this.userService = new UserService(this.dbContext);
 }
Esempio n. 12
0
 public PictureServiceTests()
 {
     this.dbContext      = base.DatabaseInstance;
     this.pictureService = new PictureService(this.dbContext);
 }
Esempio n. 13
0
 public PictureService(JustMonitorDbContext db)
     : base(db)
 {
 }
Esempio n. 14
0
 public ManufacturerService(JustMonitorDbContext db)
     : base(db)
 {
 }
Esempio n. 15
0
 public CostEntryService(JustMonitorDbContext db)
     : base(db)
 {
 }