private async Task AddProcedureToStylistByCreatingStylistAsync(string id, string category)
        {
            var procedures = await this.proceduresRepository
                            .All()
                            .Where(p => p.CategoryId == category)
                            .Select(p => p.Id)
                            .ToListAsync();

            foreach (var procedure in procedures)
            {
                var procedureStylist = new ProcedureStylist()
                {
                    StylistId = id,
                    ProcedureId = procedure,
                };

                await this.procedureStylistsRepository.AddAsync(procedureStylist);
            }
        }
        public async Task<bool> AddProcedureToStylistAsync(string id, string procedureId)
        {
            var isAlreadyAdded = await this.procedureStylistsRepository
                .All()
                .AnyAsync(ps => ps.StylistId == id && ps.ProcedureId == procedureId);

            if (isAlreadyAdded)
            {
                return false;
            }

            var procedureStylist = new ProcedureStylist()
            {
                StylistId = id,
                ProcedureId = procedureId,
            };

            await this.procedureStylistsRepository.AddAsync(procedureStylist);
            await this.procedureStylistsRepository.SaveChangesAsync();

            return true;
        }
Пример #3
0
        public async Task CheckDeletingProcedureAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Procedure>(db);
            var skinProblemProceduresRepository = new EfRepository <SkinProblemProcedure>(db);
            var procedureStylistsRepository     = new EfRepository <ProcedureStylist>(db);
            var procedureProductsRepository     = new EfRepository <ProcedureProduct>(db);

            var service = new ProceduresService(
                repository,
                this.procedureReviewsRepository.Object,
                procedureProductsRepository,
                procedureStylistsRepository,
                skinProblemProceduresRepository,
                this.appointmentsRepository.Object,
                this.categoriesService.Object);

            var procedure = await PrepareProcedureAsync(db, service);

            var firstStylist = new ApplicationUser()
            {
                Id = "1"
            };
            var secondStylist = new ApplicationUser()
            {
                Id = "2"
            };

            var firstStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = procedure.Id,
                StylistId   = firstStylist.Id,
            };

            var secondStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = procedure.Id,
                StylistId   = secondStylist.Id,
            };

            var product = new Product()
            {
                Id = "1"
            };

            var procedureProduct = new ProcedureProduct()
            {
                ProcedureId = procedure.Id,
                ProductId   = product.Id,
            };

            await db.Users.AddAsync(firstStylist);

            await db.Users.AddAsync(secondStylist);

            await db.ProcedureStylists.AddAsync(firstStylistProcedure);

            await db.ProcedureStylists.AddAsync(secondStylistProcedure);

            await db.Products.AddAsync(product);

            await db.ProcedureProducts.AddAsync(procedureProduct);

            await db.SaveChangesAsync();

            await service.DeleteAsync(procedure.Id);

            Assert.True(procedure.IsDeleted);
            Assert.Empty(procedureProductsRepository.All());
            Assert.Empty(procedureStylistsRepository.All());
            Assert.Empty(procedureProductsRepository.All());
        }
Пример #4
0
        public async Task CheckSmartSearchPerfectProceduresAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Procedure>(db);
            var procedureStylistsRepository = new EfRepository <ProcedureStylist>(db);

            var service = new ProceduresService(
                repository,
                this.procedureReviewsRepository.Object,
                this.procedureProductsRepository.Object,
                procedureStylistsRepository,
                this.skinProblemProceduresRepository.Object,
                this.appointmentsRepository.Object,
                this.categoriesService.Object);

            var skinType = new SkinType()
            {
                Id = "1",
            };

            var firstProcedure = new Procedure()
            {
                Id          = "1",
                IsSensitive = true,
                SkinTypeId  = skinType.Id,
            };

            var secondProcedure = new Procedure()
            {
                Id          = "2",
                IsSensitive = true,
                SkinTypeId  = skinType.Id,
            };

            var thirdProcedure = new Procedure()
            {
                Id          = "3",
                IsSensitive = false,
                SkinTypeId  = skinType.Id,
            };

            var fourthProcedure = new Procedure()
            {
                Id          = "4",
                IsSensitive = true,
                SkinTypeId  = "2",
            };

            var stylist = new ApplicationUser()
            {
                Id = "1"
            };

            var firstStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = firstProcedure.Id,
                StylistId   = stylist.Id,
            };

            var secondStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = secondProcedure.Id,
                StylistId   = stylist.Id,
            };

            var thirdStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = thirdProcedure.Id,
                StylistId   = stylist.Id,
            };

            var fourthStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = fourthProcedure.Id,
                StylistId   = stylist.Id,
            };

            await db.Procedures.AddAsync(firstProcedure);

            await db.Procedures.AddAsync(secondProcedure);

            await db.Procedures.AddAsync(thirdProcedure);

            await db.Procedures.AddAsync(fourthProcedure);

            await db.Users.AddAsync(stylist);

            await db.SkinTypes.AddAsync(skinType);

            await db.ProcedureStylists.AddAsync(firstStylistProcedure);

            await db.ProcedureStylists.AddAsync(secondStylistProcedure);

            await db.ProcedureStylists.AddAsync(thirdStylistProcedure);

            await db.ProcedureStylists.AddAsync(fourthStylistProcedure);

            await db.SaveChangesAsync();

            var proceduresSmartSearch = await service.GetSmartSearchProceduresAsync <TestProcedureStylistModel>(skinType.Id, "yes", stylist.Id);

            var perfectProcedures = await service.GetPerfectProceduresForSkinTypeAsync <TestProcedureModel>(true, skinType.Id);

            Assert.Equal(2, proceduresSmartSearch.Count());
            Assert.Equal(2, perfectProcedures.Count());
        }
Пример #5
0
        public async Task CheckGettingProcedureStylistsAsync()
        {
            ApplicationDbContext db = GetDb();

            var repository = new EfDeletableEntityRepository <Procedure>(db);
            var procedureStylistsRepository = new EfRepository <ProcedureStylist>(db);

            var service = new ProceduresService(
                repository,
                this.procedureReviewsRepository.Object,
                this.procedureProductsRepository.Object,
                procedureStylistsRepository,
                this.skinProblemProceduresRepository.Object,
                this.appointmentsRepository.Object,
                this.categoriesService.Object);

            var procedure = new Procedure()
            {
                Id = "1"
            };

            var firstStylist = new ApplicationUser()
            {
                Id = "1"
            };
            var secondStylist = new ApplicationUser()
            {
                Id = "2"
            };
            var thirdStylist = new ApplicationUser()
            {
                Id = "3"
            };

            var firstStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = procedure.Id,
                StylistId   = firstStylist.Id,
            };

            var secondStylistProcedure = new ProcedureStylist()
            {
                ProcedureId = procedure.Id,
                StylistId   = secondStylist.Id,
            };

            await db.Procedures.AddAsync(procedure);

            await db.Users.AddAsync(firstStylist);

            await db.Users.AddAsync(secondStylist);

            await db.Users.AddAsync(thirdStylist);

            await db.ProcedureStylists.AddAsync(firstStylistProcedure);

            await db.ProcedureStylists.AddAsync(secondStylistProcedure);

            await db.SaveChangesAsync();

            var procedures = await service.GetProceduresByStylistAsync <TestProcedureStylistModel>(firstStylist.Id);

            Assert.Single(procedures);
        }
        public async Task SeedAsync(ApplicationDbContext dbContext, IServiceProvider serviceProvider)
        {
            var userManager = serviceProvider.GetRequiredService <UserManager <ApplicationUser> >();

            if (!dbContext.Users.Any())
            {
                var stylistsData = JsonConvert
                                   .DeserializeObject <List <StylistDto> >(File.ReadAllText(GlobalConstants.StylistSeederPath))
                                   .ToList();

                List <ApplicationUser>  stylists          = new List <ApplicationUser>();
                List <ProcedureStylist> procedureStylists = new List <ProcedureStylist>();

                foreach (var currentStylistData in stylistsData)
                {
                    var category = await dbContext.Categories
                                   .FirstOrDefaultAsync(c => c.Name == currentStylistData.Category);

                    var jobType = await dbContext.JobTypes
                                  .FirstOrDefaultAsync(jb => jb.Name == currentStylistData.JobType);

                    var stylist = new ApplicationUser()
                    {
                        FirstName      = currentStylistData.FirstName,
                        LastName       = currentStylistData.LastName,
                        Picture        = currentStylistData.Picture,
                        Gender         = Enum.Parse <Gender>(currentStylistData.Gender),
                        CategoryId     = category.Id,
                        JobTypeId      = jobType.Id,
                        UserName       = currentStylistData.UserName,
                        PasswordHash   = GlobalConstants.SystemPasswordHashed,
                        Email          = currentStylistData.Email,
                        EmailConfirmed = true,
                        Description    = currentStylistData.Description,
                    };

                    var procedures = dbContext.Procedures
                                     .Where(p => p.Category.Name == currentStylistData.Category)
                                     .ToList();

                    foreach (var procedure in procedures)
                    {
                        var procedureStylist = new ProcedureStylist()
                        {
                            ProcedureId = procedure.Id,
                            StylistId   = stylist.Id,
                        };

                        procedureStylists.Add(procedureStylist);
                    }

                    stylists.Add(stylist);
                }

                await dbContext.ProcedureStylists.AddRangeAsync(procedureStylists);

                await dbContext.Users.AddRangeAsync(stylists);

                await dbContext.SaveChangesAsync();
            }
        }