Esempio n. 1
0
 public async Task Seed()
 {
     if (await _context.VehicleTypes.CountAsync() == 0)
     {
         _context.VehicleTypes.Add(new VehicleType()
         {
             Name = "Truck"
         });
         _context.VehicleTypes.Add(new VehicleType()
         {
             Name = "Loader"
         });
         _context.VehicleTypes.Add(new VehicleType()
         {
             Name = "Lift"
         });
         _context.VehicleTypes.Add(new VehicleType()
         {
             Name = "Trailer"
         });
         _context.VehicleTypes.Add(new VehicleType()
         {
             Name = "Car"
         });
         await _context.SaveChangesAsync();
     }
 }
Esempio n. 2
0
        public async Task <bool> Create(PartServiceModel partServiceModel)
        {
            if (_context.Parts.Any(v => v.Name == partServiceModel.Name))
            {
                return(false);
            }

            Part part = AutoMapper.Mapper.Map <Part>(partServiceModel);

            part.AcquiredFrom = await GetPartProviderByName(partServiceModel.AcquiredFrom.Name);

            _context.Parts.Add(part);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 3
0
        public async Task <bool> Create(VehicleServiceModel vehicleServiceModel)
        {
            if (_context.Vehicles.Any(v => v.VSN == vehicleServiceModel.VSN))
            {
                return(false);
            }

            Vehicle vehicle = AutoMapper.Mapper.Map <Vehicle>(vehicleServiceModel);

            vehicle.VehicleProvider = await GetVehicleProviderByName(vehicleServiceModel.VehicleProvider.Name);

            vehicle.VehicleType = await GetVehicleTypeByName(vehicleServiceModel.VehicleType.Name);

            _context.Vehicles.Add(vehicle);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 4
0
        public async Task <bool> CreateCustomReport(ReportServiceModel reportServiceModel)
        {
            ReportType reportType = await _context.ReportTypes.SingleOrDefaultAsync(x => x.Name == "Custom");

            reportServiceModel.Name =
                $"Custom_{reportServiceModel.StartYear}_{reportServiceModel.StartMonth}_{reportServiceModel.EndYear}_{reportServiceModel.EndMonth}";

            if (await _context.Reports.AnyAsync(x => x.Name == reportServiceModel.Name && x.IsDeleted == false))
            {
                return(false);
            }

            var report = reportServiceModel.To <Report>();

            if (report.StartYear > report.EndYear)
            {
                return(false);
            }
            else if (report.StartMonth > report.EndMonth)
            {
                return(false);
            }

            report.ReportType = reportType;

            report.VehiclesInReport = GetVehiclesInReport(reportServiceModel.StartMonth, reportServiceModel.StartYear,
                                                          reportServiceModel.EndMonth, reportServiceModel.EndYear);

            report.MonthlySalariesInReport = GetSalariesInReport(reportServiceModel.StartMonth,
                                                                 reportServiceModel.StartYear,
                                                                 reportServiceModel.EndMonth, reportServiceModel.EndYear);

            report.MechanicsBaseCosts  = report.MonthlySalariesInReport.Sum(x => x.BaseSalary);
            report.VehicleBaseCost     = report.VehiclesInReport.Sum(x => x.Depreciation);
            report.ExternalRepairCosts = report.VehiclesInReport.Sum(x => x.ExternalRepairs.Sum(y => y.LaborCost + y.PartsCost));
            report.InternalRepairCosts = report.VehiclesInReport.Sum(x => x.InternalRepairs.Sum(y => (decimal)y.HoursWorked * y.MdmsUser.AdditionalOnHourPayment) +
                                                                     x.InternalRepairs.Sum(y => y.InternalRepairParts.Sum(z => z.Quantity * z.Part.Price)));

            await _context.AddAsync(report);

            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
        public async Task <bool> CreateExternalRepairProvider(ExternalRepairProviderServiceModel externalRepairProviderServiceModel)
        {
            if (_context.ExternalRepairProviders.Any(v => v.Name == externalRepairProviderServiceModel.Name))
            {
                return(false);
            }

            _context.ExternalRepairProviders.Add(externalRepairProviderServiceModel.To <ExternalRepairProvider>());
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
        public async Task <bool> DeleteUser(string id)
        {
            var user = _context.Users.Find(id);

            user.IsDeleted = true;
            _context.Update(user);
            var result = await _context.SaveChangesAsync();

            return(result > 0);
        }
Esempio n. 7
0
 public async Task Seed()
 {
     if (await _context.Roles.CountAsync() <= 1)
     {
         _context.Roles.Add(new IdentityRole()
         {
             Name = "Admin", NormalizedName = "ADMIN"
         });
         _context.Roles.Add(new IdentityRole()
         {
             Name = "User", NormalizedName = "USER"
         });
         _context.Roles.Add(new IdentityRole()
         {
             Name = "Guest", NormalizedName = "GUEST"
         });
         await _context.SaveChangesAsync();
     }
 }
 public async Task Seed()
 {
     if (await _context.RepairedSystems.CountAsync() == 0)
     {
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "Engine"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "GearBox"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "Electrical"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "Hydraulic"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "Fuel"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "Chassis"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "Breaking"
         });
         _context.RepairedSystems.Add(new RepairedSystem()
         {
             Name = "BodyWork"
         });
         await _context.SaveChangesAsync();
     }
 }
Esempio n. 9
0
 public async Task Seed()
 {
     if (await _context.ReportTypes.CountAsync() == 0)
     {
         _context.ReportTypes.Add(new ReportType()
         {
             Name = "Month"
         });
         _context.ReportTypes.Add(new ReportType()
         {
             Name = "Quarter"
         });
         _context.ReportTypes.Add(new ReportType()
         {
             Name = "Year"
         });
         _context.ReportTypes.Add(new ReportType()
         {
             Name = "Custom"
         });
         await _context.SaveChangesAsync();
     }
 }
 private async Task SeedData(MdmsDbContext context)
 {
     context.AddRange(GetPartGetDummyData());
     await context.SaveChangesAsync();
 }
        private async Task SeedReportData(MdmsDbContext context)
        {
            context.AddRange(SeedReports());

            await context.SaveChangesAsync();
        }
 private async Task SeedVehicleAndMonthlySalarytData(MdmsDbContext context)
 {
     context.AddRange(GetVehicleDummyData());
     context.AddRange(SeedMonthlySalaries());
     await context.SaveChangesAsync();
 }
Esempio n. 13
0
 private async Task SeedDataSalary(MdmsDbContext context)
 {
     context.AddRange(AddSalaries());
     await context.SaveChangesAsync();
 }