Esempio n. 1
0
        public static async Task InitializeAsync(ApplicationDbContext context, IServiceProvider serviceProvider)
        {
            context.Database.EnsureCreated();
            RoleManager <IdentityRole>    _roleManager = serviceProvider.GetRequiredService <RoleManager <IdentityRole> >();
            UserManager <ApplicationUser> _userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();

            string[]       roleNames = { "Admin", "User" };
            IdentityResult roleResult;

            foreach (string role in roleNames)
            {
                bool roleExist = await _roleManager.RoleExistsAsync(role);

                if (!roleExist)
                {
                    roleResult = await _roleManager.CreateAsync(new IdentityRole(role));
                }
            }

            ApplicationUser admin = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**"
            };
            var resultAdmin = await _userManager.CreateAsync(admin, "1234Qw_");

            if (resultAdmin.Succeeded)
            {
                await _userManager.AddToRoleAsync(admin, roleNames[0]);
            }
            ApplicationUser user = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**"
            };
            var resultUser = await _userManager.CreateAsync(user, "4321Wq_");

            if (resultUser.Succeeded)
            {
                await _userManager.AddToRoleAsync(user, roleNames[1]);
            }

            PartyModel party = new PartyModel
            {
                Name          = "Mega Party",
                Performer     = "DJ BlaBla",
                TicketsAmount = 10,
                TicketsLeft   = 10,
                Date          = new DateTime(2018, 08, 10),
                Place         = "Minsk",
                Price         = 10
            };

            ConcertModel concert = await context.Concerts.FirstOrDefaultAsync(c => c.Name == party.Name);

            if (concert == null)
            {
                context.Parties.Add(party);
                context.SaveChanges();
            }
        }
Esempio n. 2
0
 public ConcertModel(ConcertModel c)
 {
     Name          = c.Name;
     Performer     = c.Performer;
     TicketsAmount = c.TicketsAmount;
     TicketsLeft   = c.TicketsLeft;
     Date          = c.Date;
     Place         = c.Place;
     Price         = c.Price;
 }
Esempio n. 3
0
 public ConcertViewModel(ConcertModel concert)
 {
     Id            = concert.Id;
     Name          = concert.Name;
     Performer     = concert.Performer;
     TicketsAmount = concert.TicketsAmount;
     TicketsLeft   = concert.TicketsLeft;
     ConcertDate   = concert.Date;
     Place         = concert.Place;
     Price         = concert.Price;
     Type          = concert.Type;
 }
 public OpenAirModel(ConcertModel c) : base(c)
 {
     Type = nameof(OpenAirModel);
 }
 public PartyModel(ConcertModel c) : base(c)
 {
     Type = nameof(PartyModel);
 }
 public ClassicalConcertModel(ConcertModel c) : base(c)
 {
     Type = nameof(ClassicalConcertModel);
 }