Esempio n. 1
0
        public void UpdateUser(Assignment8.Models.ApplicationDbContext context, string email, List <string> roles)
        {
            foreach (var role in roles)
            {
                if (!context.Roles.Any(r => r.Name == role))
                {
                    var store   = new RoleStore <IdentityRole>(context);
                    var manager = new RoleManager <IdentityRole>(store);
                    manager.Create(new IdentityRole {
                        Name = role
                    });
                }
            }

            if (!context.Users.Any(u => u.UserName == email))
            {
                var store   = new UserStore <ApplicationUser>(context);
                var manager = new UserManager <ApplicationUser>(store);
                var user    = new ApplicationUser {
                    UserName = email
                };

                manager.Create(user, "Password123!");

                foreach (var role in roles)
                {
                    manager.AddToRole(user.Id, role);
                }
            }
        }
Esempio n. 2
0
        public void AssocAlbumTracks(Assignment8.Models.ApplicationDbContext context, string albumName, string trackName)
        {
            var album = context.Albums.SingleOrDefault(a => a.Name == albumName);
            var track = album.Tracks.SingleOrDefault(t => t.Name == trackName);

            if (track == null)
            {
                album.Tracks.Add(context.Tracks.Single(t => t.Name == trackName));
            }
        }
Esempio n. 3
0
        //data association methods
        public void AssocArtistAlbums(Assignment8.Models.ApplicationDbContext context, string artistName, string albumName)
        {
            var artist = context.Artists.SingleOrDefault(a => a.Name == artistName);
            var album  = artist.Albums.SingleOrDefault(a => a.Name == albumName);

            if (album == null)
            {
                artist.Albums.Add(context.Albums.Single(a => a.Name == albumName));
            }
        }