コード例 #1
0
 public CategoriesController(IUserService service, IRepository <ServiceCategory> sc, IMapper mapper, AmsApiDbContext cntx)
 {
     _cntx    = cntx;
     _mapper  = mapper;
     _service = service;
     _sc      = sc;
 }
コード例 #2
0
        public async void GetLocation()
        {
            #region Arrange
            // todo: define the required assets
            var storeOptions = Options.Create(new OperationalStoreOptions());
            var options      = new DbContextOptionsBuilder <AmsApiDbContext>()
                               .UseInMemoryDatabase(databaseName: "AmsContext")
                               .Options;
            using (var context = new AmsApiDbContext(options, storeOptions))
            {
                context.Add(new Location()
                {
                    Id           = 1,
                    Active       = true,
                    Address      = "Ab",
                    Address1     = "Ab",
                    Cancelation  = true,
                    City         = "Test city",
                    Confirmation = true,
                    ContactEmail = "*****@*****.**",
                    ContactName  = "Contact NAme",
                    Country      = "CountryName",
                    Description  = "Locatin Description",
                    NoShowUp     = true,
                    Phone        = "12345678901",
                    Reminder     = true,
                    Rescheduling = true,
                    State        = "State testing",
                    ThankYou     = true,
                    ZipCode      = "12345"
                });

                await context.SaveChangesAsync();
            }
            Location location_existing    = null;
            Location location_notExisting = null;

            #endregion


            #region Act
            // todo: invoke the test

            using (var context = new AmsApiDbContext(options, storeOptions))
            {
                var controller = new LocationsForTestController(context);
                location_existing    = (await controller.GetLocation(1)).Value;
                location_notExisting = (await controller.GetLocation(2)).Value;
            }

            #endregion
            #region Assert
            // todo: verify that conditions are met.

            Assert.True(location_existing != null && location_notExisting == null);

            #endregion
        }
コード例 #3
0
 public SeedController(
     AmsApiDbContext context,
     RoleManager <IdentityRole> roleManager,
     UserManager <ApplicationUser> userManager,
     IWebHostEnvironment env)
 {
     _context     = context;
     _env         = env;
     _roleManager = roleManager;
     _userManager = userManager;
 }
コード例 #4
0
 public UsersController(IUserService userService, AmsApiDbContext context, IRepository <Staff> s, IRepository <Client> c,
                        IMapper mapper, SignInManager <ApplicationUser> signInManager,
                        UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, ILogger <DbInitializer> logger)
 {
     _c             = c;
     _signInManager = signInManager;
     _userManager   = userManager;
     _roleManager   = roleManager;
     _logger        = logger;
     _mapper        = mapper;
     _s             = s;
     _context       = context;
     _userService   = userService;
 }
コード例 #5
0
        public UserService(AmsApiDbContext context, IConfiguration configuration, IMapper mapper, IRepository <Staff> s,
                           UserManager <ApplicationUser> userManager,
                           SignInManager <ApplicationUser> signInManager,
                           ILogger <UserService> logger)
        {
            _userManager   = userManager;
            _signInManager = signInManager;

            _logger       = logger;
            _s            = s;
            _mapper       = mapper;
            Configuration = configuration;
            _context      = context;
        }
 public LocationsForTestController(AmsApiDbContext context)
 {
     _context = context;
 }
コード例 #7
0
 public StaffWorkingHoursController(AmsApiDbContext context)
 {
     _context = context;
 }
コード例 #8
0
 public Repository(AmsApiDbContext dbContext)
 {
     _dbContext = dbContext;
     entities   = dbContext.Set <T>();
 }
コード例 #9
0
 public ServiceCategoryRepository(AmsApiDbContext context) : base(context)
 {
 }
コード例 #10
0
 public MessagesController(AmsApiDbContext context)
 {
     _context = context;
 }
コード例 #11
0
        public async void CreateDefaultUsers()
        {
            #region Arrange
            // create the option instances required by the
            // AmsApiDbContext
            var options = new DbContextOptionsBuilder <AmsApiDbContext>()
                          .UseInMemoryDatabase(databaseName: "AmsContext")
                          .Options;
            var storeOptions = Options.Create(new
                                              OperationalStoreOptions());
            // create a IWebHost environment mock instance
            var mockEnv = new Mock <IWebHostEnvironment>().Object;
            // define the variables for the users we want to test
            ApplicationUser user_Admin       = null;
            ApplicationUser user_User        = null;
            ApplicationUser user_Employee    = null;
            ApplicationUser user_NotExisting = null;
            #endregion
            #region Act
            // create a AmsApiDbContext instance using the
            // in-memory DB
            using (var context = new AmsApiDbContext(options,
                                                     storeOptions))
            {
                // create a RoleManager instance
                var roleManager = IdentityHelper.GetRoleManager(
                    new RoleStore <IdentityRole>(context));
                // create a UserManager instance
                var userManager = IdentityHelper.GetUserManager(
                    new UserStore <ApplicationUser>(context));

                // create a SeedController instance
                var controller = new SeedController(
                    context,
                    roleManager,
                    userManager,
                    mockEnv
                    );
                // execute the SeedController's CreateDefaultUsers()
                // method to create the default users (and roles)
                await controller.CreateDefaultUsers();

                // retrieve the users
                user_Admin = await userManager.FindByEmailAsync("*****@*****.**");

                user_User = await userManager.FindByEmailAsync("*****@*****.**");

                user_Employee = await userManager.FindByEmailAsync("*****@*****.**");

                user_NotExisting = await userManager.FindByEmailAsync("*****@*****.**");
            }
            #endregion
            #region Assert
            Assert.True(
                user_Admin != null &&
                user_User != null &&
                user_Employee != null &&
                user_NotExisting == null
                );
            #endregion
        }
コード例 #12
0
 public ClosedDatesController(AmsApiDbContext context)
 {
     _context = context;
 }
コード例 #13
0
 public CitiesController(AmsApiDbContext context)
 {
     _context = context;
 }
コード例 #14
0
        public static void Initialize(AmsApiDbContext context, UserManager <ApplicationUser> userManager, RoleManager <IdentityRole> roleManager, ILogger <DbInitializer> logger)
        {
            context.Database.EnsureCreated();



            var locations = new Location[] {
                new Location {
                    Active = true, Address = "7696 NW Greensprint St", Address1 = "Suit 123", ContactEmail = "*****@*****.**", ContactName = "Contact PersonNAme", Description = "Este es un salo de belleza", State = "FL", ZipCode = "34987", Country = "US", Phone = "1234567890", City = "Port Saint Lucie"
                },
                new Location {
                    Active = true, Address = "123 NW Greensprint St", Address1 = "Suit 434", ContactEmail = "*****@*****.**", ContactName = "PersonNAme", Description = "Este es una barberia", State = "GA", ZipCode = "3093", Country = "US", Phone = "1234567811", City = "Port Saint Lucie"
                },
            };

            if (!context.Locations.Any())
            {
                //return;   // DB has been seeded

                context.Locations.AddRange(locations);

                context.SaveChanges();
            }
            var cds = new ClosedDate[] {
                new ClosedDate {
                    Location = locations.FirstOrDefault(), Description = "Holyday 2", From = DateTime.Now.AddDays(55), To = DateTime.Now.AddDays(55)
                },
                new ClosedDate {
                    Location = locations.FirstOrDefault(), Description = "Holyday 1", From = DateTime.Now.AddDays(5), To = DateTime.Now.AddDays(5)
                },
            };

            if (!context.ClosedDates.Any())
            {
                //return;   // DB has been seeded


                context.ClosedDates.AddRange(cds);

                context.SaveChanges();
            }



            var scs = new ServiceCategory[] {
                new ServiceCategory {
                    Description = "Haircuts and Hairdressing"
                },
                new ServiceCategory {
                    Description = "Color"
                }
            };

            if (!context.ServiceCategories.Any())
            {
                context.ServiceCategories.AddRange(scs);

                context.SaveChanges();
            }

            var ss = new Service[] {
                new Service {
                    ServiceCategory = scs.Single(s => s.Description == "Haircuts and Hairdressing"), ActiveStatus = true, DurationHour = 1, DurationMinute = 30, Price = 50.00m, ServiceDescription = "Modern Hair cuts", ServiceName = "Hair Cuts"
                },
                new Service {
                    ServiceCategory = scs.Single(s => s.Description == "Haircuts and Hairdressing"), ActiveStatus = true, DurationHour = 1, DurationMinute = 15, Price = 45.00m, ServiceDescription = "Modern Hair cuts", ServiceName = "Wash"
                },
                new Service {
                    ServiceCategory = scs.Single(s => s.Description == "Haircuts and Hairdressing"), ActiveStatus = true, DurationHour = 1, DurationMinute = 30, Price = 50.00m, ServiceDescription = "Hoof cuts", ServiceName = "Manicure and Pedicure"
                },
            };

            if (!context.Services.Any())
            {
                context.Services.AddRange(ss);
                context.SaveChanges();
            }


            var clients = new Client[] {
                new Client {
                    AcceptsMarketingNotifications = true, Active = true, Email = "*****@*****.**", FirstName = "Client1", LastName = "last 1", Mobile = "1234567890", SendNotificationBy = "phone", Photo = "234234"
                },
                new Client {
                    AcceptsMarketingNotifications = true, Active = true, Email = "*****@*****.**", FirstName = "Client 2", LastName = "last 2", Mobile = "1234567890", SendNotificationBy = "email", Photo = "234234"
                },
                new Client {
                    AcceptsMarketingNotifications = true, Active = true, Email = "*****@*****.**", FirstName = "Client 3", LastName = "last 3", Mobile = "1234567890", SendNotificationBy = "email", Photo = "234234"
                },
            };

            if (!context.Clients.Any())
            {
                context.Clients.AddRange(clients);

                context.SaveChanges();
            }

            var uRoles = new IdentityRole {
                Name = "admin", ConcurrencyStamp = "adminrole"
            };
            IdentityResult resultR = roleManager.CreateAsync(uRoles).Result;

            uRoles = new IdentityRole {
                Name = "staff", ConcurrencyStamp = "staffrole"
            };
            resultR = roleManager.CreateAsync(uRoles).Result;
            uRoles  = new IdentityRole {
                Name = "customer", ConcurrencyStamp = "customerrole"
            };
            resultR = roleManager.CreateAsync(uRoles).Result;


            var aUser = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
            };
            var result = userManager.CreateAsync(aUser, "Password1$").Result;


            var resultRole = userManager.AddToRoleAsync(aUser, "customer").Result;


            if (result.Succeeded)
            {
                logger.LogInformation("User created a new account with password.");

                var token   = userManager.GenerateEmailConfirmationTokenAsync(aUser).Result;
                var results = userManager.ConfirmEmailAsync(aUser, token).Result;

                aUser = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
                };
                results    = userManager.CreateAsync(aUser, "Password1$").Result;
                resultRole = userManager.AddToRoleAsync(aUser, "customer").Result;

                token   = userManager.GenerateEmailConfirmationTokenAsync(aUser).Result;
                results = userManager.ConfirmEmailAsync(aUser, token).Result;


                aUser = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
                };
                userManager.CreateAsync(aUser, "Password1$").Wait();
                resultRole = userManager.AddToRoleAsync(aUser, "customer").Result;
            }
            var sts = new Staff[] {
                new Staff {
                    Active = true, BriefCv = "Nice cuts", CanBook = true, Email = "*****@*****.**", FirstName = "Staly 1", LastName = "st", Mobile = "1234567890", Title = "Cutter"
                },
                new Staff {
                    Active = true, BriefCv = "Nice cuts same", CanBook = true, Email = "*****@*****.**", FirstName = "St3", LastName = "tr", Mobile = "1234563333", Title = "Very good"
                },
                new Staff {
                    Active = true, BriefCv = "D' Penco Nice cuts same", CanBook = true, Email = "*****@*****.**", FirstName = "the", LastName = "penco", Mobile = "1234562233", Title = "The Penco"
                },
            };

            if (!context.Staffs.Any())
            {
                context.Staffs.AddRange(sts);
                context.SaveChanges();
            }

            aUser = new ApplicationUser {
                UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
            };
            result     = userManager.CreateAsync(aUser, "Password1$").Result;
            resultRole = userManager.AddToRoleAsync(aUser, "staff").Result;

            if (result.Succeeded)
            {
                var token   = userManager.GenerateEmailConfirmationTokenAsync(aUser).Result;
                var results = userManager.ConfirmEmailAsync(aUser, token).Result;

                aUser = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
                };
                userManager.CreateAsync(aUser, "Password1$").Wait();
                resultRole = userManager.AddToRoleAsync(aUser, "admin").Result;

                token   = userManager.GenerateEmailConfirmationTokenAsync(aUser).Result;
                results = userManager.ConfirmEmailAsync(aUser, token).Result;

                aUser = new ApplicationUser {
                    UserName = "******", Email = "*****@*****.**", EmailConfirmed = true
                };
                userManager.CreateAsync(aUser, "Password1$").Wait();
                resultRole = userManager.AddToRoleAsync(aUser, "staff").Result;
            }

            var whs = new StaffWorkingHour[] {
                new StaffWorkingHour {
                    EndRepeat = EndRepeat.Ongoing, From = DateTime.Now, To = DateTime.Now.AddHours(5), Location = locations.FirstOrDefault(), Staff = sts.FirstOrDefault()
                },
                new StaffWorkingHour {
                    EndRepeat = EndRepeat.Ongoing, From = DateTime.Now, To = DateTime.Now.AddHours(3), Location = locations.LastOrDefault(), Staff = sts.LastOrDefault()
                },
            };

            if (!context.StaffWorkingHours.Any())
            {
                context.StaffWorkingHours.AddRange(whs);

                context.SaveChanges();
            }
        }