//public SelectList repairState { get; set; }
        //public SelectList engineFuels { get; set; }

        //public SelectList bodyTypes { get; set; }


        public void initializeSelectList(RepairShopContext _context, object selectedClient = null, object selectedMechanic = null)
        {
            //var clientQuery = await _userManager.GetUsersInRoleAsync("Client");


            var clientQuery = from c in _context.Users
                              join ur in _context.UserRoles on c.Id equals ur.UserId
                              join r in _context.Roles on ur.RoleId equals r.Id
                              where r.Name == "Client"
                              orderby c.FirstName, c.LastName
            select c;

            var mechanicQuery = from c in _context.Users
                                join ur in _context.UserRoles on c.Id equals ur.UserId
                                join r in _context.Roles on ur.RoleId equals r.Id
                                where r.Name == "Mechanic"
                                orderby c.FirstName, c.LastName
            select c;

            clientSL   = new SelectList(clientQuery, "Id", "FullName", selectedClient);
            mechanicSL = new SelectList(mechanicQuery, "Id", "FullName", selectedMechanic);

            //repairState = new SelectList(Enum.GetValues(typeof(RepairState)));
            //engineFuels = new SelectList(Enum.GetValues(typeof(EngineFuel)), selectedEF);
            //bodyTypes = new SelectList(Enum.GetValues(typeof(BodyType)), selectedBT);
        }
Esempio n. 2
0
 public SessionDataViewComponent(RepairShopContext context)
 {
     _context = context;
 }
Esempio n. 3
0
 internal static void Initialize(RepairShopContext context)
 {
     throw new NotImplementedException();
 }
Esempio n. 4
0
        public async static Task Initialize(RepairShopContext context, UserManager <RepairShopUser> userManager, RoleManager <ApplicationRole> roleManager)
        {
            context.Database.EnsureCreated();

            string[] roleNames = { "Admin", "Client", "Mechanic" };
            Task <IdentityResult> roleResult;

            foreach (var roleName in roleNames)
            {
                var roleExist = roleManager.RoleExistsAsync(roleName);
                roleExist.Wait();
                if (!roleExist.Result)
                {
                    ApplicationRole ap = new ApplicationRole();
                    ap.Name = roleName;
                    //create the roles and seed them to the database: Question 1
                    roleResult = roleManager.CreateAsync(ap);
                    roleResult.Wait();
                }
            }
            // Look for any students.
            if (context.Users.Any())
            {
                return;       // DB has been seeded
            }

            var client = new RepairShopUser {
                UserName = "******", Email = "*****@*****.**", FirstName = "John", LastName = "Kowalsky"
            };
            await userManager.CreateAsync(client, "Test!@#123");

            client.EmailConfirmed = true;
            await userManager.AddToRoleAsync(client, "Client");



            var mechanic = new RepairShopUser {
                UserName = "******", Email = "*****@*****.**", FirstName = "Mark", LastName = "Stafford"
            };
            await userManager.CreateAsync(mechanic, "Test!@#123");

            mechanic.EmailConfirmed = true;
            await userManager.AddToRoleAsync(mechanic, "Mechanic");


            var admin = new RepairShopUser {
                UserName = "******", Email = "*****@*****.**", FirstName = "Admin", LastName = "Admin"
            };
            await userManager.CreateAsync(admin, "Test!@#123");

            admin.EmailConfirmed = true;
            await userManager.AddToRoleAsync(admin, "Admin");



            var car = new Car
            {
                Brand          = "Audi",
                Model          = "A4",
                BodyType       = BodyType.Sedan,
                EngineFuel     = EngineFuel.Diesel,
                EngineCapacity = 1900,
                productionYear = 1999
            };

            context.Car.Add(car);


            var repair = new Repair
            {
                Description        = "This a example repair description created for testing purposes. Real description will be much longer and more interesting",
                ProblemDescription = "This a example of problem description created for testing purposes. Real description will be much longer and more interesting",
                RepairState        = RepairState.Reported,
                startTime          = DateTime.Now,
                WorkPrice          = 1,
                Client             = client,
                AssignedMechanic   = mechanic,
                Car = car,
            };


            context.Repair.Add(repair);

            var image = new FileModel
            {
                FileName = "lamp.jpg",
                Title    = "Old lamp"
            };

            context.Files.Add(image);

            var replacedPart = new ReplacedPart
            {
                Manufacturer   = "Audi",
                Name           = "Front lamp",
                Price          = 100,
                ProductionDate = DateTime.Now,
                Quantity       = 1,
                Repair         = repair,
                OldPartImage   = image
            };

            context.ReplacedPart.Add(replacedPart);



            var visit = new Visit
            {
                VisitClient      = client,
                VisitMechanic    = mechanic,
                VisitPurpose     = "This a example visit description created for testing purposes. Real description will be much longer and more interesting",
                AcceptedClient   = true,
                AcceptedMechanic = false,
                PlannedVisitDate = DateTime.Now
            };

            context.Visit.Add(visit);
            context.SaveChanges();
        }
Esempio n. 5
0
 public DeviceServicesController(RepairShopContext context)
 {
     _context = context;
 }
 public HomeController(RepairShopContext context)
 {
     _context = context;
 }
        // This method gets called by the runtime. Use this method to configure the HTTP request pipeline.
        public void Configure(IApplicationBuilder app, IHostingEnvironment env, ILoggerFactory loggerFactory, RepairShopContext context)
        {
            loggerFactory.AddConsole(Configuration.GetSection("Logging"));
            loggerFactory.AddDebug();

            if (env.IsDevelopment())
            {
                app.UseDeveloperExceptionPage();
                app.UseBrowserLink();
            }
            else
            {
                app.UseExceptionHandler("/Home/Error");
            }

            app.UseStaticFiles();
            app.UseSession();

            app.UseMvc(routes =>
            {
                routes.MapRoute(
                    name: "default",
                    template: "{controller=Home}/{action=Index}/{id?}");
            });

            DbInitializer.Initialize(context);
        }
 public UsersController(RepairShopContext context)
 {
     _context = context;
 }