Пример #1
0
        public async Task <IActionResult> Edit(int id, int id2, [Bind("Version,Comments,Status,HardwareId,SoftwareId")] HW_SW hW_SW)
        {
            if (id == hW_SW.HardwareId && id2 == hW_SW.SoftwareId)
            {
                if (hW_SW == null)
                {
                    return(NotFound());
                }
            }
            else
            {
                // here we will check if we already have HW_SW with same Id, if not we can proceed with an update
                var exist = _context.HW_SW.Any(m => m.HardwareId == hW_SW.HardwareId && m.SoftwareId == hW_SW.SoftwareId);
                if (exist)
                {
                    ModelState.AddModelError("HardwareId", "Already in database!");
                    ModelState.AddModelError("SoftwareId", "Already in database!");
                    //return View(hW_SW);
                    //return RedirectToAction(nameof(Index));
                }
                else
                {
                    var hW_SW_del = await _context.HW_SW.FindAsync(id, id2);

                    _context.HW_SW.Remove(hW_SW_del);
                    _context.Add(hW_SW);
                    await _context.SaveChangesAsync();

                    return(RedirectToAction(nameof(Index)));
                }
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(hW_SW);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!HW_SWExists(hW_SW.HardwareId, hW_SW.SoftwareId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HardwareId"] = new SelectList(_context.Hardwares, "HardwareId", "Name", hW_SW.HardwareId);
            ViewData["SoftwareId"] = new SelectList(_context.Softwares, "SoftwareId", "Name", hW_SW.SoftwareId);
            return(View(hW_SW));
        }
Пример #2
0
        public async Task <IActionResult> Create([Bind("Version,Comments,Status,HardwareId,SoftwareId")] HW_SW hW_SW)
        {
            if (ModelState.IsValid)
            {
                _context.Add(hW_SW);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["HardwareId"] = new SelectList(_context.Hardwares, "HardwareId", "Name", hW_SW.HardwareId);
            ViewData["SoftwareId"] = new SelectList(_context.Softwares, "SoftwareId", "Name", hW_SW.SoftwareId);
            return(View(hW_SW));
        }
Пример #3
0
        public static async void Initialize(ApplicationDbContext context, UserManager <IdentityUser> userManager, RoleManager <IdentityRole> roleManager)
        {
            context.Database.EnsureCreated();

            // Look for any data, abort seed if found
            if (context.Locations.Any() ||
                context.Rooms.Any() ||
                context.Hardwares.Any() ||
                context.Owners.Any() ||
                context.Softwares.Any() ||
                context.Brands.Any() ||
                context.HW_SW.Any())
            {
                return;
            }


            var locations = new Location[]
            {
                new Location {
                    Address = "Kopilica 7", Place = "Split", Country = "Croatia"
                },
                new Location {
                    Address = "Antuna Mihanovića 17", Place = "Zagreb", Country = "Croatia"
                },
                new Location {
                    Address = "Svetog leopolda Bogdana Madića 42", Place = "Osijek", Country = "Croatia"
                }
            };

            foreach (var location in locations)
            {
                context.Locations.Add(location);
            }
            context.SaveChanges();


            var rooms = new Room[]
            {
                new Room {
                    Name = "ST01", Purpose = "IT laboratorij", Floor = 0, Size = 50, LocationId = 1
                },
                new Room {
                    Name = "ST02", Purpose = "Laboratorij za elektroniku", Floor = 0, Size = 35, LocationId = 1
                },
                new Room {
                    Name = "ST03", Purpose = "Laboratorij za elektroniku", Floor = 0, Size = 35, LocationId = 1
                },
                new Room {
                    Name = "ST04", Floor = 0, Size = 70, LocationId = 1
                },
                new Room {
                    Name = "ST11", Floor = 1, Size = 70, LocationId = 1, Purpose = "Laboratorij za sve studije"
                },
                new Room {
                    Name = "ZG01", Purpose = "IT laboratorij", Floor = 0, Size = 50, LocationId = 1
                },
                new Room {
                    Name = "ZG02", Purpose = "Laboratorij za elektroniku", Floor = 0, Size = 35, LocationId = 1
                },
                new Room {
                    Name = "ZG03", Purpose = "Laboratorij za elektroniku", Floor = 0, Size = 35, LocationId = 1
                },
                new Room {
                    Name = "ZG04", Floor = 0, Size = 70, LocationId = 1
                },
                new Room {
                    Name = "ZG11", Floor = 1, Size = 70, LocationId = 1, Purpose = "Laboratorij za sve studije"
                }
            };

            foreach (var room in rooms)
            {
                context.Rooms.Add(room);
            }
            context.SaveChanges();

            var brands = new Brand[]
            {
                new Brand {
                    Name = "Microsoft", ContactFullName = "Adam Spencer", Email = "[email protected],", WebPage = "https://www.microsoft.com"
                },
                new Brand {
                    Name = "Adobe", ContactFullName = "Katerina Sandler", Email = "[email protected],", WebPage = "https://www.adobe.com"
                },
                new Brand {
                    Name = "Google", ContactFullName = "Phill Collins", Phone = "+235 18 523 1234", WebPage = "https://www.google.com"
                },
                new Brand {
                    Name = "Apple", ContactFullName = "Herkulies Lu", Phone = "+305 22 523 1234", WebPage = "https://www.apple.com"
                },
                new Brand {
                    Name = "Nvidia", WebPage = "https://www.nvidia.com"
                },
                new Brand {
                    Name = "ADM"
                },
                new Brand {
                    Name = "Gigabyte", Email = "[email protected],", WebPage = "https://www.gigabyte.com"
                },
                new Brand {
                    Name = "IBM", Email = "[email protected],", WebPage = "https://www.ibm.com"
                },
                new Brand {
                    Name = "Logitech", Email = "[email protected],", WebPage = "https://www.ibm.com"
                },
                new Brand {
                    Name = "Dell"
                },
                new Brand {
                    Name = "HP"
                },
                new Brand {
                    Name = "LG"
                },
            };

            foreach (var brand in brands)
            {
                context.Brands.Add(brand);
            }
            context.SaveChanges();

            var owners = new Owner[]
            {
                new Owner {
                    FullName = "Sveučilišni centar za stručne studije", Email = "*****@*****.**", Phone = "+38521346886"
                },
                new Owner {
                    FullName = "Sveučilište u Splitu",
                },
            };

            foreach (var owner in owners)
            {
                context.Owners.Add(owner);
            }
            context.SaveChanges();

            var softwares = new Software[]
            {
                new Software {
                    BrandId = 1, LicenceType = LicenceType.Proprietary, Name = "Visual Studio", Purpose = "Za progamiranje u C#, web development, C/C++"
                },
                new Software {
                    BrandId = 3, LicenceType = LicenceType.Protective, Name = "Google drive"
                },
                new Software {
                    LicenceType = LicenceType.Protective, Name = "Statictica"
                },
                new Software {
                    BrandId = 1, LicenceType = LicenceType.Proprietary, Name = "Windows"
                },
                new Software {
                    BrandId = 1, LicenceType = LicenceType.Proprietary, Name = "Office"
                },
                new Software {
                    BrandId = 1, LicenceType = LicenceType.Proprietary, Name = "Azure"
                },
                new Software {
                    LicenceType = LicenceType.PublicDomain, Name = "Linux Ubuntu"
                },
                new Software {
                    LicenceType = LicenceType.PublicDomain, Name = "Notepad++"
                },
            };

            foreach (var software in softwares)
            {
                context.Softwares.Add(software);
            }
            context.SaveChanges();

            var hardwares = new Hardware[]
            {
                new Hardware {
                    RoomId = 1, Name = "Monitor-17-01", Specs = "17\"", Condition = Condition.Poor, BrandId = 12, AcquiredDate = DateTime.Parse("2015-09-01"), Serial = "SDUIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 1, Name = "Monitor-24-01", Specs = "24\"", Condition = Condition.Excelent, BrandId = 12, AcquiredDate = DateTime.Parse("2018-09-01"), Serial = "S123DUADSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 1, Name = "Monitor-18-01", Specs = "18\"", Condition = Condition.Excelent, BrandId = 12, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 1, Name = "PC01", Specs = "Intel i7, Nvidia 1060", Condition = Condition.Excelent, BrandId = 10, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 1, Name = "PC02", Specs = "Intel i7, Nvidia 1060", Condition = Condition.Excelent, BrandId = 10, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 1, Name = "PC03", Specs = "Intel i7, Nvidia 1060", Condition = Condition.Excelent, BrandId = 10, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },

                new Hardware {
                    RoomId = 2, Name = "Monitor-17-02", Specs = "17\"", Condition = Condition.Poor, BrandId = 12, AcquiredDate = DateTime.Parse("2015-09-01"), Serial = "SDUIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 2, Name = "Monitor-24-02", Specs = "24\"", Condition = Condition.Excelent, BrandId = 12, AcquiredDate = DateTime.Parse("2018-09-01"), Serial = "S123DUADSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 2, Name = "Monitor-18-02", Specs = "18\"", Condition = Condition.Excelent, BrandId = 12, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 2, Name = "PC04", Specs = "Intel i7, Nvidia 1060", Condition = Condition.Excelent, BrandId = 10, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 2, Name = "PC05", Specs = "Intel i7, Nvidia 1060", Condition = Condition.Excelent, BrandId = 10, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
                new Hardware {
                    RoomId = 2, Name = "PC06", Specs = "Intel i7, Nvidia 1060", Condition = Condition.Excelent, BrandId = 10, AcquiredDate = DateTime.Parse("2017-10-01"), Serial = "S123DSFIH3289D", OwnerId = 1
                },
            };

            foreach (var hardware in hardwares)
            {
                context.Hardwares.Add(hardware);
            }
            context.SaveChanges();

            var hw_sws = new HW_SW[]
            {
                new HW_SW {
                    HardwareId = 4, SoftwareId = 4, Version = "10.0.1234", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 4, SoftwareId = 5, Version = "19.0.123", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 4, SoftwareId = 1, Version = "19.0.3", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 5, SoftwareId = 4, Version = "10.0.1234", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 5, SoftwareId = 5, Version = "19.0.123", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 5, SoftwareId = 1, Version = "19.0.3", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 5, SoftwareId = 8, Version = "10.0.1234", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 6, SoftwareId = 4, Version = "12.0.1234", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 6, SoftwareId = 5, Version = "44.0.123", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 6, SoftwareId = 1, Version = "23.0.3", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 10, SoftwareId = 8, Version = "3.0.123", Status = Status.Active
                },
                new HW_SW {
                    HardwareId = 11, SoftwareId = 8, Version = "3.0.3", Status = Status.Active
                },
            };

            foreach (var hw_sw in hw_sws)
            {
                context.HW_SW.Add(hw_sw);
            }
            context.SaveChanges();

            var roles = new IdentityRole[]
            {
                new IdentityRole {
                    Name = "Admin", NormalizedName = "ADMIN"
                },
                new IdentityRole {
                    Name = "PowerUser", NormalizedName = "POWERUSER"
                },
                new IdentityRole {
                    Name = "User", NormalizedName = "USER"
                },
            };

            foreach (var role in roles)
            {
                roleManager.CreateAsync(role).Wait();
            }

            var user = new IdentityUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true
            };

            userManager.CreateAsync(user, "Opatija-1").Wait();
            userManager.AddToRoleAsync(user, "Admin").Wait();

            user = new IdentityUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true
            };
            userManager.CreateAsync(user, "Opatija-1").Wait();
            userManager.AddToRoleAsync(user, "PowerUser").Wait();

            user = new IdentityUser
            {
                UserName       = "******",
                Email          = "*****@*****.**",
                EmailConfirmed = true
            };

            userManager.CreateAsync(user, "Opatija-1").Wait();
            userManager.AddToRoleAsync(user, "User").Wait();

            // /*DEAD CODE BELOW*/
            // var users = new IdentityUser[]
            // {
            //     new IdentityUser{ Id="1", Email="*****@*****.**", UserName="******", NormalizedUserName="******", PhoneNumber="+3852345123", NormalizedEmail="*****@*****.**".ToUpper()},
            //     new IdentityUser{ Id="2", Email="*****@*****.**", UserName="******", NormalizedUserName="******", PhoneNumber="+3852345123", NormalizedEmail="*****@*****.**".ToUpper()},
            //     new IdentityUser{ Id="3", Email="*****@*****.**", UserName="******", NormalizedUserName="******", PhoneNumber="+3852345123", NormalizedEmail="*****@*****.**".ToUpper()},
            // };

            // //var user = new IdentityUser();
            // //user.UserName = "******";
            // //user.Email = "*****@*****.**";

            // //string userPWD = "somepassword";

            // //IdentityResult chkUser = await userManager.CreateAsync(user, userPWD).;

            // foreach (var user in users)
            // {
            //     userManager.CreateAsync(user, "Opatija 1").Wait();
            //     //userManager.AddToRoleAsync(user, "Admin").Wait();
            //     context.Users.Add(user);
            // }
            // context.SaveChanges();
        }