Exemplo n.º 1
0
        public ActionResult Edit(TraineeUser traineeUser)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var traineeInDb = _context.TraineeUsers.SingleOrDefault(te => te.ID == traineeUser.ID);

            if (traineeInDb == null)
            {
                return(HttpNotFound());
            }
            traineeInDb.Email                = traineeUser.Email;
            traineeInDb.Full_Name            = traineeUser.Full_Name;
            traineeInDb.Education            = traineeUser.Education;
            traineeInDb.Programming_Language = traineeUser.Programming_Language;
            traineeInDb.Experience_Details   = traineeUser.Experience_Details;
            traineeInDb.Department           = traineeUser.Department;
            //traineeInDb.Phone = traineeUser.Phone;
            _context.SaveChanges();
            return(RedirectToAction("Index"));
        }
Exemplo n.º 2
0
 public static TraineeUserDetailModel Create(TraineeUser traineeUser)
 {
     return(Projection.Compile().Invoke(traineeUser));
 }
        //Arrange
        private HonoplayDbContext InitAndGetDbContext(out int workingStatusId, out int departmentId, out int adminUserId, out int traineeUserId, out Guid tenantId)
        {
            var context = GetDbContext();

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name     = "TestTenant#01",
                HostName = "localhost"
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var department = new Department
            {
                CreatedBy = adminUser.Id,
                Name      = "testDepartment",
                TenantId  = tenant.Id
            };

            context.Departments.Add(department);

            var workingStatus = new WorkingStatus
            {
                Name      = "testWorkingStatus",
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id
            };

            context.WorkingStatuses.Add(workingStatus);

            var traineeUser = new TraineeUser
            {
                Name                   = "testName",
                DepartmentId           = department.Id,
                Surname                = "testSurname",
                PhoneNumber            = "testNumber11111",
                Password               = "******".GetSHA512(salt),
                PasswordSalt           = salt,
                CreatedBy              = adminUser.Id,
                Email                  = "*****@*****.**",
                Gender                 = 1,
                NationalIdentityNumber = "testNumber22222",
                WorkingStatusId        = workingStatus.Id
            };

            context.TraineeUsers.Add(traineeUser);

            context.SaveChanges();

            workingStatusId = workingStatus.Id;
            departmentId    = department.Id;
            adminUserId     = adminUser.Id;
            traineeUserId   = traineeUser.Id;
            tenantId        = tenant.Id;
            return(context);
        }
Exemplo n.º 4
0
        private HonoplayDbContext InitAndGetDbContext(out Guid tenantId, out int adminUserId, out int trainingId, out int trainerUserId, out int traineeUserId)
        {
            var context = GetDbContext();

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Id           = 1,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            context.AdminUsers.Add(adminUser);

            var tenant = new Tenant
            {
                Name     = "TestTenant#01",
                HostName = "localhost"
            };

            context.Tenants.Add(tenant);

            context.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenant.Id,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var trainingSeries = new TrainingSeries
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "testSeries"
            };

            context.TrainingSerieses.Add(trainingSeries);

            var trainingCategory = new TrainingCategory
            {
                CreatedBy   = adminUser.Id,
                Description = "test",
                Name        = "sample",
            };

            context.TrainingCategories.Add(trainingCategory);

            var training = new Training
            {
                CreatedBy          = adminUser.Id,
                BeginDateTime      = DateTimeOffset.Now,
                Description        = "test",
                EndDateTime        = DateTimeOffset.Now.AddDays(5),
                TrainingCategoryId = trainingCategory.Id,
                TrainingSeriesId   = trainingSeries.Id,
                Name = "sample"
            };

            context.Trainings.Add(training);

            var department = new Department
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "sampleDepartment"
            };

            context.Departments.Add(department);

            var profession = new Profession
            {
                TenantId  = tenant.Id,
                CreatedBy = adminUser.Id,
                Name      = "testProfession"
            };

            context.Professions.Add(profession);

            var workingStatus = new WorkingStatus
            {
                CreatedBy = adminUser.Id,
                TenantId  = tenant.Id,
                Name      = "test"
            };

            context.WorkingStatuses.Add(workingStatus);

            var traineeUser = new TraineeUser
            {
                CreatedBy              = adminUser.Id,
                DepartmentId           = department.Id,
                Gender                 = 1,
                Name                   = "asdasd",
                NationalIdentityNumber = "12321421311",
                PhoneNumber            = "912489213123",
                Surname                = "test",
                WorkingStatusId        = 1
            };

            context.TraineeUsers.Add(traineeUser);

            var trainerUser = new TrainerUser
            {
                CreatedBy    = adminUser.Id,
                Name         = "sample",
                DepartmentId = department.Id,
                Email        = "*****@*****.**",
                PhoneNumber  = "16846546544545",
                ProfessionId = profession.Id,
                Surname      = "test"
            };

            context.TrainerUsers.Add(trainerUser);
            context.SaveChanges();

            adminUserId   = adminUser.Id;
            traineeUserId = traineeUser.Id;
            tenantId      = tenant.Id;
            trainingId    = training.Id;
            trainerUserId = trainerUser.Id;

            return(context);
        }
Exemplo n.º 5
0
        public static void PopulateTestData(HonoplayDbContext dbContext)
        {
            var tenantId       = Guid.Parse("b0dfcb00-6195-46a7-834e-c58276c3242a");
            var secondTenantId = Guid.Parse("f3878709-3cba-4ed3-4c03-08d70375909d");

            dbContext.Tenants.Add(new Tenant
            {
                Id          = tenantId,
                Name        = "api-test",
                Description = "test",
                HostName    = "localhost",
            });

            var salt      = ByteArrayExtensions.GetRandomSalt();
            var adminUser = new AdminUser
            {
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                LastPasswordChangeDateTime = DateTime.Today.AddDays(-5),
            };

            dbContext.AdminUsers.Add(adminUser);

            dbContext.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = tenantId,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            dbContext.Tenants.Add(new Tenant
            {
                Id          = secondTenantId,
                Name        = "api-tesasdt",
                Description = "test",
                HostName    = "localhosttt",
            });

            dbContext.TenantAdminUsers.Add(new TenantAdminUser
            {
                TenantId    = secondTenantId,
                AdminUserId = adminUser.Id,
                CreatedBy   = adminUser.Id
            });

            var questionTypes = new List <QuestionType>
            {
                new QuestionType
                {
                    Id   = 1,
                    Name = "questionType1"
                },
                new QuestionType
                {
                    Id   = 2,
                    Name = "questionType2"
                }
            };

            dbContext.QuestionTypes.AddRange(questionTypes);

            var questionDifficulties = new List <QuestionDifficulty>
            {
                new QuestionDifficulty
                {
                    Id   = 1,
                    Name = "questionDifficulty1"
                },
                new QuestionDifficulty
                {
                    Id   = 2,
                    Name = "questionDifficulty2"
                }
            };

            dbContext.QuestionDifficulties.AddRange(questionDifficulties);

            var questionCategories = new List <QuestionCategory>
            {
                new QuestionCategory
                {
                    Name     = "questionDifficulty1",
                    TenantId = tenantId
                },
                new QuestionCategory
                {
                    Name     = "questionDifficulty2",
                    TenantId = tenantId
                }
            };

            dbContext.QuestionCategories.AddRange(questionCategories);

            var department = new Department
            {
                CreatedBy = adminUser.Id,
                Name      = "yazilim",
                TenantId  = tenantId
            };

            dbContext.Departments.Add(department);

            var workingStatus = new WorkingStatus
            {
                Name      = "Full-Time",
                CreatedBy = adminUser.Id,
                TenantId  = tenantId
            };

            dbContext.WorkingStatuses.Add(workingStatus);

            var profession = new Profession
            {
                Name      = "Web",
                CreatedBy = adminUser.Id,
                TenantId  = tenantId
            };

            dbContext.Professions.Add(profession);

            var trainingSeries = new TrainingSeries
            {
                Name      = "series1",
                CreatedBy = adminUser.Id,
                TenantId  = tenantId
            };

            dbContext.TrainingSerieses.Add(trainingSeries);


            var trainingCategory = new TrainingCategory
            {
                CreatedBy   = adminUser.Id,
                Description = "sample",
                Name        = "test"
            };

            dbContext.TrainingCategories.Add(trainingCategory);

            var training = new Training
            {
                TrainingCategoryId = trainingCategory.Id,
                BeginDateTime      = DateTimeOffset.Now,
                EndDateTime        = DateTimeOffset.Now.AddDays(5),
                CreatedBy          = adminUser.Id,
                Description        = "description",
                Name             = "test",
                TrainingSeriesId = trainingSeries.Id
            };

            dbContext.Trainings.Add(training);

            var trainerUser = new TrainerUser
            {
                Name         = "Emre",
                PhoneNumber  = "1234567890",
                Surname      = "KAS",
                DepartmentId = department.Id,
                CreatedBy    = adminUser.Id,
                Email        = "*****@*****.**",
                Password     = "******".GetSHA512(salt),
                PasswordSalt = salt,
                ProfessionId = profession.Id
            };

            dbContext.TrainerUsers.Add(trainerUser);

            var traineeUser = new TraineeUser
            {
                DepartmentId           = department.Id,
                Name                   = "Yunus Emre",
                CreatedBy              = adminUser.Id,
                Gender                 = 1,
                Email                  = "*****@*****.**",
                Password               = "******".GetSHA512(salt),
                PasswordSalt           = salt,
                NationalIdentityNumber = "654654654444",
                PhoneNumber            = "053546835411",
                Surname                = "KAS",
                WorkingStatusId        = workingStatus.Id
            };

            dbContext.TraineeUsers.Add(traineeUser);

            var question = new Question
            {
                TenantId  = tenantId,
                CreatedBy = adminUser.Id,
                Duration  = 123,
                Text      = "Yukaridaki yukarida midir?",
            };

            dbContext.Questions.Add(question);

            var option = new Option
            {
                VisibilityOrder = 1,
                CreatedBy       = adminUser.Id,
                Text            = "yukaridadir",
                QuestionId      = question.Id
            };

            dbContext.Options.Add(option);

            var classroom = new Classroom
            {
                CreatedBy     = adminUser.Id,
                Name          = "test",
                TrainerUserId = trainerUser.Id,
                TrainingId    = training.Id,
            };

            dbContext.Classrooms.Add(classroom);

            var game = new Game
            {
                Name = "game1"
            };

            dbContext.Games.Add(game);

            var session = new Session
            {
                UpdatedBy   = adminUser.Id,
                Name        = "test",
                ClassroomId = classroom.Id,
                GameId      = game.Id,
            };

            dbContext.Sessions.Add(session);

            dbContext.TraineeGroups.Add(new TraineeGroup
            {
                CreatedBy = adminUser.Id,
                Name      = "traineeGroup",
                TenantId  = tenantId
            });
            dbContext.ContentFiles.Add(new ContentFile
            {
                Id          = Guid.Parse("4f2b88e3-704c-41d8-a679-f608a159d055"),
                Name        = "contentFile1",
                ContentType = "contentFile1",
                Data        = new byte[] { 0x20, 0x20, 0x20, 0x20, 0x20, 0x20, 0x20 },
                TenantId    = tenantId,
                CreatedBy   = adminUser.Id
            });

            dbContext.Avatars.Add(new Avatar
            {
                Name       = "avatar1",
                ImageBytes = new byte[] { 0x20 }
            });

            var tag = new Tag
            {
                Name       = "tag1",
                CreatedBy  = adminUser.Id,
                ToQuestion = true
            };

            dbContext.Tags.Add(tag);
            var questionTag = new QuestionTag
            {
                QuestionId = question.Id,
                TagId      = tag.Id
            };

            dbContext.QuestionTags.Add(questionTag);
            dbContext.SaveChanges();
        }
Exemplo n.º 6
0
        public async Task <ResponseModel <CreateTraineeUserModel> > Handle(CreateTraineeUserCommand request, CancellationToken cancellationToken)
        {
            var redisKey    = $"TraineeUsersWithDepartmentsByTenantId{request.TenantId}";
            var salt        = ByteArrayExtensions.GetRandomSalt();
            var traineeUser = new TraineeUser
            {
                Name                       = request.Name,
                DepartmentId               = request.DepartmentId,
                Gender                     = request.Gender,
                NationalIdentityNumber     = request.NationalIdentityNumber,
                PhoneNumber                = request.PhoneNumber,
                Surname                    = request.Surname,
                WorkingStatusId            = request.WorkingStatusId,
                CreatedBy                  = request.CreatedBy,
                Email                      = request.Email,
                LastPasswordChangeDateTime = DateTimeOffset.Now,
                PasswordSalt               = salt,
                Password                   = request.Password.GetSHA512(salt),
                AvatarId                   = request.AvatarId
            };

            using (var transaction = await _context.Database.BeginTransactionAsync(cancellationToken))
            {
                try
                {
                    var isExistAnyDepartment = await _context.Departments.AnyAsync(x =>
                                                                                   x.TenantId == request.TenantId &&
                                                                                   x.Id == request.DepartmentId,
                                                                                   cancellationToken);

                    if (!isExistAnyDepartment)
                    {
                        throw new NotFoundException(nameof(Department), request.DepartmentId);
                    }

                    await _context.TraineeUsers.AddAsync(traineeUser, cancellationToken);

                    await _context.SaveChangesAsync(cancellationToken);

                    transaction.Commit();

                    await _cacheService.RedisCacheUpdateAsync(redisKey,
                                                              _ => _context.TraineeUsers
                                                              .Include(x => x.Department)
                                                              .Where(x => x.Department.TenantId == request.TenantId)
                                                              .ToList()
                                                              , cancellationToken);
                }
                catch (DbUpdateException ex) when((ex.InnerException is SqlException sqlException && (sqlException.Number == 2627 || sqlException.Number == 2601)) ||
                                                  (ex.InnerException is SqliteException sqliteException && sqliteException.SqliteErrorCode == 19))
                {
                    transaction.Rollback();
                    throw new ObjectAlreadyExistsException(nameof(TraineeUser), request.Name);
                }
                catch (NotFoundException)
                {
                    transaction.Rollback();
                    throw;
                }
                catch (Exception)
                {
                    transaction.Rollback();
                    throw new TransactionException();
                }
            }

            var traineeUserModel = new CreateTraineeUserModel(traineeUser.Id,
                                                              traineeUser.CreatedAt,
                                                              traineeUser.Name,
                                                              traineeUser.Email,
                                                              traineeUser.Surname,
                                                              traineeUser.NationalIdentityNumber,
                                                              traineeUser.PhoneNumber,
                                                              traineeUser.Gender,
                                                              traineeUser.AvatarId);

            return(new ResponseModel <CreateTraineeUserModel>(traineeUserModel));
        }
Exemplo n.º 7
0
 public static GetTraineeUsersListByClassroomIdModel Create(TraineeUser traineeUser) => Projection.Compile().Invoke(traineeUser);