Ejemplo n.º 1
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }



            if (User.IsInRole("Client"))
            {
                var user = await _userManager.GetUserAsync(User);

                ReplacedPart = (from rp in _context.ReplacedPart.Include(r => r.OldPartImage).Include(rp => rp.NewPartBill)
                                join r in _context.Repair on rp.RepairID equals r.RepairID
                                where rp.ReplacedPartID == id.Value && r.ClientID == user.Id
                                select rp).AsNoTracking().FirstOrDefault();
            }
            else
            {
                ReplacedPart = await _context.ReplacedPart
                               .Include(rp => rp.OldPartImage)
                               .Include(rp => rp.NewPartBill)
                               .AsNoTracking()
                               .FirstOrDefaultAsync(m => m.ReplacedPartID == id);
            }


            if (ReplacedPart == null)
            {
                return(NotFound());
            }
            return(Page());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> OnGetAsync(int?id)
        {
            if (id == null)
            {
                return(NotFound());
            }

            ReplacedPart = await _context.ReplacedPart
                           .Include(rp => rp.OldPartImage)
                           .Include(rp => rp.NewPartBill)
                           .AsNoTracking()
                           .FirstOrDefaultAsync(m => m.ReplacedPartID == id);

            if (ReplacedPart == null)
            {
                return(NotFound());
            }

            if (!RepairNotClosed(ReplacedPart.RepairID))
            {
                return(NotFound());
            }

            return(Page());
        }
        public ActionResult DeleteConfirmed(int id)
        {
            ReplacedPart replacedpart = db.ReplacedParts.Find(id);

            db.ReplacedParts.Remove(replacedpart);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        //
        // GET: /ReplacedPart/Details/5

        public ActionResult Details(int id = 0)
        {
            ReplacedPart replacedpart = db.ReplacedParts.Find(id);

            if (replacedpart == null)
            {
                return(HttpNotFound());
            }
            return(View(replacedpart));
        }
        //
        // GET: /ReplacedPart/Edit/5

        public ActionResult Edit(int id = 0)
        {
            ReplacedPart replacedpart = db.ReplacedParts.Find(id);

            if (replacedpart == null)
            {
                return(HttpNotFound());
            }
            ViewBag.statusId      = new SelectList(db.Catalogs, "catalogId", "catalogValue", replacedpart.statusId);
            ViewBag.servicePartId = new SelectList(db.ServiceParts, "servicePartId", "servicePartDescription", replacedpart.servicePartId);
            ViewBag.supplierId    = new SelectList(db.SupplierParts, "supplierId", "supplierId", replacedpart.supplierId);
            ViewBag.serviceCarId  = new SelectList(db.ServiceCars, "serviceCarId", "serviceCarDescription", replacedpart.serviceCarId);
            return(View(replacedpart));
        }
 public ActionResult Edit(ReplacedPart replacedpart)
 {
     if (ModelState.IsValid)
     {
         db.Entry(replacedpart).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.statusId      = new SelectList(db.Catalogs, "catalogId", "catalogValue", replacedpart.statusId);
     ViewBag.servicePartId = new SelectList(db.ServiceParts, "servicePartId", "servicePartDescription", replacedpart.servicePartId);
     ViewBag.supplierId    = new SelectList(db.SupplierParts, "supplierId", "supplierId", replacedpart.supplierId);
     ViewBag.serviceCarId  = new SelectList(db.ServiceCars, "serviceCarId", "serviceCarDescription", replacedpart.serviceCarId);
     return(View(replacedpart));
 }
Ejemplo n.º 7
0
        //the part that is enabled and disabled
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (!editorChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Add(shipModified);
                    editorChangeRegistered = false;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Remove(vesselModified);
                    flightChangeRegistered = false;
                }
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (!flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Add(vesselModified);
                    flightChangeRegistered = true;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Remove(shipModified);
                    editorChangeRegistered = false;
                }
            }

            string[] nodenames           = nodeNames.Split(',');
            string[] transformGroupNames = transormNames.Split(',');

            List <string[]> transformnames = new List <string[]>();

            //when the lengths are not equal
            if (transformGroupNames.Length != nodenames.Length)
            {
                return;
            }

            //----------------------------------------------------------
            //create the list of transforms to be made visible on attach
            //----------------------------------------------------------

            //remove the whitespaces
            for (int i = 0; i < nodenames.Length; i++)
            {
                nodenames[i] = nodenames[i].Trim();

                //split up the names for the nodes
                string[] transformGroup = transformGroupNames[i].Split('|');

                for (int j = 0; j < transformGroup.Length; j++)
                {
                    transformGroup[j] = transformGroup[j].Trim();
                }
                transformnames.Add(transformGroup);
            }

            int num = 0;

            for (int i = 0; i < nodenames.Length; i++)
            {
                AttachNode       node       = part.FindAttachNode(nodenames[i]);
                List <Transform> transforms = new List <Transform>();
                for (int k = 0; k < transformnames[num].Length; k++)
                {
                    transforms.AddRange(part.FindModelTransforms(transformnames[num][k]));
                }

                //when nodes and transforms are valid and found
                if ((node != null) && (transforms.Count > 0))
                {
                    //create the new corridor data
                    CorridorPart corridor = new CorridorPart();
                    corridor.node       = node;
                    corridor.transforms = transforms;

                    if ((allowSurfaceAttach) && (surfaceAttachNode == nodenames[i]) && (part.srfAttachNode != null))
                    {
                        corridor.isSurfaceAttachPoint = true;
                    }
                    else
                    {
                        corridor.isSurfaceAttachPoint = false;
                    }

                    corridor.lastAttached = true;
                    corridors.Add(corridor);
                }
                num++;
            }

            //------------------------------------------------------------
            //create the list of transforms to be made invisible on attach
            //------------------------------------------------------------
            string[]        replaceTransformGroupNames = null;
            string[]        replaceNodeGroupNames      = null;
            List <string[]> replacetransformnames      = new List <string[]>();
            List <string[]> replacenodenames           = new List <string[]>();

            if ((replaceTransformNames != string.Empty) && (replaceNodeNames != string.Empty))
            {
                replaceTransformGroupNames = replaceTransformNames.Split(',');
                replaceNodeGroupNames      = replaceNodeNames.Split(',');

                if (replaceNodeGroupNames.Length == replaceTransformGroupNames.Length)
                {
                    //split up all the name for the groups
                    for (int i = 0; i < replaceNodeGroupNames.Length; i++)
                    {
                        //split up the names for the nodes
                        string[] transformGroup = replaceTransformGroupNames[i].Split('|');
                        for (int j = 0; j < transformGroup.Length; j++)
                        {
                            transformGroup[j] = transformGroup[j].Trim();
                        }
                        replacetransformnames.Add(transformGroup);

                        string[] nodeGroup = replaceNodeGroupNames[i].Split('|');
                        for (int j = 0; j < nodeGroup.Length; j++)
                        {
                            nodeGroup[j] = nodeGroup[j].Trim();
                        }
                        replacenodenames.Add(nodeGroup);
                    }


                    //for all transform groups
                    num = 0;
                    for (int i = 0; i < replacetransformnames.Count; i++)
                    {
                        List <Transform>  rTransforms  = new List <Transform>();
                        List <AttachNode> rAttachnodes = new List <AttachNode>();

                        for (int j = 0; j < replacetransformnames[i].Length; j++)
                        {
                            //Debug.Log("[KPBS] Replace Tranform Name: " + replacetransformnames[i][j]);
                            rTransforms.AddRange(part.FindModelTransforms(replacetransformnames[i][j]));
                        }

                        for (int j = 0; j < replacenodenames[num].Length; j++)
                        {
                            //Debug.Log("[KPBS] Replace Node Name: " + replacenodenames[num][j]);
                            rAttachnodes.Add(part.FindAttachNode(replacenodenames[num][j]));
                        }

                        if ((rTransforms.Count > 0) && (rAttachnodes.Count > 0))
                        {
                            ReplacedPart rp = new ReplacedPart();
                            rp.nodes      = rAttachnodes;
                            rp.transforms = rTransforms;
                            replaceParts.Add(rp);
                        }
                        num++;
                    }
                }
            }
            //check the visibility of all the parts
            updateAllCorridors();
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> OnPostAsync(int id)
        {
            if (!ModelState.IsValid)
            {
                return(Page());
            }

            var emptyPart = new ReplacedPart();

            if (await TryUpdateModelAsync <ReplacedPart>(emptyPart, "ReplacedPart",
                                                         p => p.Name, p => p.Manufacturer, p => p.ProductionDate, p => p.Quantity, p => p.Price))
            {
                var repair = await _context.Repair.FindAsync(id);

                if (repair == null || repair.InvoiceIssued)
                {
                    return(NotFound());
                }
                emptyPart.Repair = repair;

                string wwwRoot = _hostEnviroment.WebRootPath;


                if (ReplacedPart.NewPartBill != null)
                {
                    string extension = Path.GetExtension(ReplacedPart.NewPartBill.File.FileName);
                    ReplacedPart.NewPartBill.FileName = Path.GetRandomFileName() + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + extension;
                    string path = Path.Combine(wwwRoot + "/bills/", ReplacedPart.NewPartBill.FileName);

                    var billModel = new FileModel
                    {
                        Title    = ReplacedPart.NewPartBill.Title,
                        FileName = ReplacedPart.NewPartBill.FileName
                    };

                    using (var fileSteam = new FileStream(path, FileMode.Create))
                    {
                        await ReplacedPart.NewPartBill.File.CopyToAsync(fileSteam);
                    }

                    _context.Files.Add(billModel);
                    emptyPart.NewPartBill = billModel;
                }

                if (ReplacedPart.OldPartImage.File != null)
                {
                    string extension = Path.GetExtension(ReplacedPart.OldPartImage.File.FileName);
                    ReplacedPart.OldPartImage.FileName = Path.GetRandomFileName() + DateTime.Now.ToString("yyyyMMdd_HH_mm_ss") + extension;
                    string path = Path.Combine(wwwRoot + "/imgs/oldparts/", ReplacedPart.OldPartImage.FileName);

                    var image = new FileModel
                    {
                        Title    = ReplacedPart.OldPartImage.Title,
                        FileName = ReplacedPart.OldPartImage.FileName
                    };

                    using (var fileSteam = new FileStream(path, FileMode.Create))
                    {
                        await ReplacedPart.OldPartImage.File.CopyToAsync(fileSteam);
                    }

                    _context.Files.Add(image);
                    emptyPart.OldPartImage = image;
                }

                _context.ReplacedPart.Add(emptyPart);
                await _context.SaveChangesAsync();
            }



            //return RedirectToPage("/Repairs/Index");
            return(RedirectToPage("/Repairs/Index", "id", new { id = id }));
        }
Ejemplo n.º 9
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();
        }
        //the part that is enabled and disabled
        public override void OnStart(StartState state)
        {
            base.OnStart(state);

            if (HighLogic.LoadedSceneIsEditor)
            {
                if (!editorChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Add(shipModified);
                    editorChangeRegistered = false;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Remove(vesselModified);
                    flightChangeRegistered = false;
                }
            }
            if (HighLogic.LoadedSceneIsFlight)
            {
                if (!flightChangeRegistered)
                {
                    GameEvents.onVesselWasModified.Add(vesselModified);
                    flightChangeRegistered = true;
                }
                if (flightChangeRegistered)
                {
                    GameEvents.onEditorShipModified.Remove(shipModified);
                    editorChangeRegistered = false;
                }
            }

            string[] nodenames = nodeNames.Split(',');
            string[] transformGroupNames = transormNames.Split(',');

            List<string[]> transformnames = new List<string[]>();

            //when the lengths are not equal
            if (transformGroupNames.Length != nodenames.Length)
                return;

            //----------------------------------------------------------
            //create the list of transforms to be made visible on attach
            //----------------------------------------------------------

            //remove the whitespaces
            for (int i = 0; i < nodenames.Length; i++)
            {
                nodenames[i] = nodenames[i].Trim();

                //split up the names for the nodes
                string[] transformGroup = transformGroupNames[i].Split('|');

                for (int j = 0; j < transformGroup.Length; j++)
                {
                    transformGroup[j] = transformGroup[j].Trim();
                }
                transformnames.Add(transformGroup);
            }

            int num = 0;
            foreach (string nodeName in nodenames)
            {
                AttachNode node = part.findAttachNode(nodeName);

                List<Transform> transforms = new List<Transform>();
                for (int k = 0; k < transformnames[num].Length; k++) {
                    transforms.AddRange(part.FindModelTransforms(transformnames[num][k]));
                }

                //when nodes and transforms are valid and found
                if ((node != null) && (transforms.Count > 0))
                {
                    //create the new corridor data
                    CorridorPart corridor = new CorridorPart();
                    corridor.node = node;
                    corridor.transforms = transforms;

                    if ((allowSurfaceAttach) && (surfaceAttachNode == nodeName) && (part.srfAttachNode != null))
                    {
                        corridor.isSurfaceAttachPoint = true;
                    }
                    else
                    {
                        corridor.isSurfaceAttachPoint = false;
                    }

                    corridor.lastAttached = true;
                    corridors.Add(corridor);
                }
                num++;
            }

            //------------------------------------------------------------
            //create the list of transforms to be made invisible on attach
            //------------------------------------------------------------
            string[] replaceTransformGroupNames = null;
            string[] replaceNodeGroupNames = null;
            List<string[]> replacetransformnames = new List<string[]>();
            List<string[]> replacenodenames = new List<string[]>();

            if ((replaceTransformNames != string.Empty) && (replaceNodeNames != string.Empty))
            {
                replaceTransformGroupNames = replaceTransformNames.Split(',');
                replaceNodeGroupNames = replaceNodeNames.Split(',');

                if (replaceNodeGroupNames.Length == replaceTransformGroupNames.Length)
                {

                    //split up all the name for the groups
                    for (int i = 0; i < replaceNodeGroupNames.Length; i++)
                    {
                        //split up the names for the nodes
                        string[] transformGroup = replaceTransformGroupNames[i].Split('|');
                        for (int j = 0; j < transformGroup.Length; j++)
                        {
                            transformGroup[j] = transformGroup[j].Trim();
                        }
                        replacetransformnames.Add(transformGroup);

                        string[] nodeGroup = replaceNodeGroupNames[i].Split('|');
                        for (int j = 0; j < nodeGroup.Length; j++)
                        {
                            nodeGroup[j] = nodeGroup[j].Trim();
                        }
                        replacenodenames.Add(nodeGroup);
                    }

                    //for all transform groups
                    num = 0;
                    foreach (string[] tNames in replacetransformnames)
                    {

                        List<Transform> rTransforms = new List<Transform>();
                        List<AttachNode> rAttachnodes = new List<AttachNode>();

                        foreach (string tName in tNames)
                        {
                            Debug.Log("[KPBS] Replace Tranform Name: " + tName);
                            rTransforms.AddRange(part.FindModelTransforms(tName));
                        }
                        foreach (string nName in replacenodenames[num])
                        {
                            Debug.Log("[KPBS] Replace Node Name: " + nName);
                            rAttachnodes.Add(part.findAttachNode(nName));
                        }

                        if ((rTransforms.Count > 0) && (rAttachnodes.Count > 0))
                        {
                            ReplacedPart rp = new ReplacedPart();
                            rp.nodes = rAttachnodes;
                            rp.transforms = rTransforms;
                            replaceParts.Add(rp);
                        }
                        num++;
                    }
                }
            }
            //check the visibility of all the parts
            updateAllCorridors();
        }