示例#1
0
        public ActionResult DeleteOrganization(int OrganizationID)
        {
            IOrgRepo orgrepo = OrgRepoFactory.Create();

            orgrepo.DeleteOrganization(OrganizationID);
            return(RedirectToAction("OrganizationList"));
        }
示例#2
0
        public ActionResult AddOrganization(OrgVM o)
        {
            IHeroRepo herorepo = HeroRepoFactory.Create();
            IOrgRepo  orgrepo  = OrgRepoFactory.Create();

            if (ModelState.IsValid)
            {
                o.OrganizationHeroes = new List <Hero>();

                var org = new Organization
                {
                    SelectedHeroesID     = o.SelectedHeroesID,
                    OrganizationID       = o.OrganizationID,
                    OrganizationName     = o.OrganizationName,
                    OganizationAddress   = o.OganizationAddress,
                    OrganizationLocation = o.OrganizationLocation,
                    Phone = o.Phone,
                };
                foreach (var HeroID in o.SelectedHeroesID)
                {
                    org.OrganizationHeroes.Add(herorepo.GetHereosByID(HeroID));
                }
                orgrepo.AddOrganization(org);
            }
            else
            {
                return(View(o));
            }
            return(RedirectToAction("OrganizationList"));
        }
示例#3
0
        public ActionResult EditHero(HeroVM h)
        {
            IHeroRepo herorepo = HeroRepoFactory.Create();
            IOrgRepo  orgrepo  = OrgRepoFactory.Create();

            if (ModelState.IsValid)
            {
                h.Organizations = new List <Organization>();

                var hero = new Hero
                {
                    HeroID      = h.HeroID,
                    HeroName    = h.HeroName,
                    Description = h.Description,
                    Sightings   = h.Sightings,
                    Superpower  = h.Superpower,
                };
                foreach (var OrganizationID in h.SelectedOrganizationsID)
                {
                    hero.Organizations.Add(orgrepo.GetOrganizationById(OrganizationID));
                }
                herorepo.EditHero(hero);
            }
            return(RedirectToAction("HeroList"));
        }
示例#4
0
        public ActionResult EditOrganization(OrgVM o)
        {
            ILocationRepo locorepo = LocationRepoFactory.Create();
            IHeroRepo     herorepo = HeroRepoFactory.Create();
            IOrgRepo      orgrepo  = OrgRepoFactory.Create();

            if (ModelState.IsValid)
            {
                o.OrganizationHeroes = new List <Hero>();

                var orgToEdit = new Organization
                {
                    OrganizationID       = o.OrganizationID,
                    OganizationAddress   = o.OganizationAddress,
                    OrganizationLocation = locorepo.GetLocationById(o.OrganizationLocation.LocationID),
                    OrganizationName     = o.OrganizationName,
                    Phone = o.Phone,
                };
                foreach (var HeroID in o.SelectedHeroesID)
                {
                    orgToEdit.OrganizationHeroes.Add(herorepo.GetHereosByID(HeroID));
                }
                orgrepo.EditOrg(orgToEdit);
            }
            return(RedirectToAction("OrganizationList"));
        }
示例#5
0
        public ActionResult OrganizationList()
        {
            IOrgRepo orgrepo = OrgRepoFactory.Create();
            var      model   = orgrepo.GetAllOrganizations();

            return(View(model.ToList()));
        }
示例#6
0
        public ActionResult EditOrganization(int id)
        {
            IOrgRepo orgrepo = OrgRepoFactory.Create();
            var      org     = orgrepo.GetOrganizationById(id);
            var      model   = new OrgVM
            {
                OrganizationID     = org.OrganizationID,
                OrganizationName   = org.OrganizationName,
                OganizationAddress = org.OganizationAddress,
                Phone = org.Phone,
                OrganizationLocation = org.OrganizationLocation,
            };

            foreach (var Hero in org.OrganizationHeroes)
            {
                model.SelectedHeroesID.Add(Hero.HeroID);
            }
            return(View(model));
        }
示例#7
0
        protected override void Seed(Superhero.Data.SuperheroDBContext context)
        {
            IOrgRepo      orgrepo      = OrgRepoFactory.Create();
            IHeroRepo     herorepo     = HeroRepoFactory.Create();
            ILocationRepo locorepo     = LocationRepoFactory.Create();
            ISightingRepo sightingrepo = SightingRepoFactory.Create();
            var           userMgr      = new UserManager <IdentityUser>(new UserStore <IdentityUser>(context));
            var           roleMgr      = new RoleManager <IdentityRole>(new RoleStore <IdentityRole>(context));

            if (!roleMgr.RoleExists("User"))
            {
                var role = new Microsoft.AspNet.Identity.EntityFramework.IdentityRole();
                role.Name = "User";
                roleMgr.Create(role);
            }

            if (!userMgr.Users.Any(u => u.UserName == "user"))
            {
                var user = new IdentityUser()
                {
                    UserName = "******"
                };
                userMgr.Create(user, "testing");
            }
            var findmanager = userMgr.FindByName("user");

            // create the user with the manager class
            if (!userMgr.IsInRole(findmanager.Id, "user"))
            {
                userMgr.AddToRole(findmanager.Id, "user");
            }


            if (!roleMgr.RoleExists("admin"))
            {
                roleMgr.Create(new IdentityRole()
                {
                    Name = "admin"
                });
            }

            if (!userMgr.Users.Any(u => u.UserName == "admin"))
            {
                var user = new IdentityUser()
                {
                    UserName = "******"
                };
                userMgr.Create(user, "testing");
            }
            var finduser = userMgr.FindByName("admin");

            // create the user with the manager class
            if (!userMgr.IsInRole(finduser.Id, "admin"))
            {
                userMgr.AddToRole(finduser.Id, "admin");
            }

            if (!context.Locations.Any(l => l.LocationName == "Minneapolis"))
            {
                var firstlocation = new Location
                {
                    LocationName        = "Minneapolis",
                    LocationAddress     = "The Twin Cities",
                    LocationDescription = "A lovely city",
                    LatitudeCoordinate  = 100,
                    LongitudeCoordinate = 100,
                };
                context.Locations.Add(firstlocation);
                context.SaveChanges();
            }
            var location = context.Locations.First(l => l.LocationName == "Minneapolis");

            if (!context.Organizations.Any(o => o.OrganizationName == "Minneapolis Hero Squad"))
            {
                var firstorg = new Organization
                {
                    OrganizationName     = "Minneapolis Hero Squad",
                    OganizationAddress   = "S 5th street Minneapolis",
                    OrganizationLocation = location,
                    Phone = "123-456-7899",
                };
                context.Organizations.Add(firstorg);
                context.SaveChanges();
            }

            var org = context.Organizations.First(l => l.OrganizationName == "Minneapolis Hero Squad");

            if (!context.Heroes.Any(h => h.HeroName == "The Flash"))
            {
                var firsthero = new Hero
                {
                    HeroName      = "The Flash",
                    Organizations = new Collection <Organization>()
                    {
                        org
                    },
                    Description = "Wears a red/yellow suit",
                    Superpower  = "Runs really fast",
                };
                context.Heroes.Add(firsthero);
                context.SaveChanges();
            }

            var hero = context.Heroes.First(l => l.HeroName == "The Flash");

            if (!context.Sightings.Any(s => s.SightingDescription == "We saw the Flash in Minneapolis"))
            {
                var firstsighting = new Sighting
                {
                    SightingLocation = location,
                    SightingHeroes   = new Collection <Hero>()
                    {
                        hero
                    },
                    Date = DateTime.Today,
                    SightingDescription = "We saw the Flash in Minneapolis",
                    IsDeleted           = false,
                    Ispublished         = true,
                };
                context.Sightings.Add(firstsighting);
            }
            context.SaveChanges();
        }