public async Task ShouldBlockUpdateUserCareerInfo() { var career = UserCareer.Create( ObjectId.GenerateNewId() ).Data; await ContainerFixture.ExecuteDbContextAsync(async dbContext => { var value = await dbContext.UserCareerCollection.EstimatedDocumentCountAsync(); Assert.True(value > 0); }); }
public async Task <Result> Handle(Contract request, CancellationToken cancellationToken) { if (request.CurrentUserRole != "Secretary" && request.CurrentUserRole != "Admin" && request.CurrentUserRole != "Student") { return(Result.Fail <Result>("Acesso Negado")); } if (request.CurrentUserRole == "Student" && request.CurrentUserId != request.UserId) { return(Result.Fail <Result>("Acesso Negado")); } var userId = ObjectId.Parse(request.UserId); var userCareer = await _db.UserCareerCollection.AsQueryable() .Where(x => x.CreatedBy == userId) .FirstOrDefaultAsync(cancellationToken: cancellationToken); if (userCareer == null) { userCareer = UserCareer.Create(userId).Data; await _db.UserCareerCollection.InsertOneAsync( userCareer, cancellationToken : cancellationToken ); } userCareer = TransformToUserCareer(userCareer, request.Career); await _db.UserCareerCollection.ReplaceOneAsync( t => t.CreatedBy == userCareer.CreatedBy, userCareer, cancellationToken : cancellationToken ); return(Result.Ok()); }
private async Task SetUserCareerInfo(User user, UserInfoDB userInfo, CancellationToken token) { bool createNew = false; var userCareer = await _db.UserCareerCollection.AsQueryable() .Where(uc => uc.CreatedBy == user.Id) .FirstOrDefaultAsync(); if (userCareer == null) { userCareer = UserCareer.Create(user.Id).Data; createNew = true; } if ( !CellIsEmpty(userInfo.GrauCurso1) || !CellIsEmpty(userInfo.NomeCurso1) || !CellIsEmpty(userInfo.Instituicao1) || !CellIsEmpty(userInfo.AnoInicio1) || !CellIsEmpty(userInfo.AnoConclusao1) || !CellIsEmpty(userInfo.PeriodoAnoConclusao1) || !CellIsEmpty(userInfo.CRAcumulado1) || !CellIsEmpty(userInfo.SituacaoCurso1) || !CellIsEmpty(userInfo.Campus1) ) { var college = new College() { AcademicDegree = userInfo.GrauCurso1, Name = userInfo.NomeCurso1, Title = userInfo.Instituicao1, Campus = userInfo.Campus1, CR = userInfo.CRAcumulado1, Status = userInfo.SituacaoCurso1 }; if (!CellIsEmpty(userInfo.PeriodoAnoConclusao1)) { college.CompletePeriod = Int32.Parse(userInfo.PeriodoAnoConclusao1); } if (!CellIsEmpty(userInfo.AnoInicio1)) { int year = Int32.Parse(userInfo.AnoInicio1); college.StartDate = new DateTime(year, 1, 1); } if (!CellIsEmpty(userInfo.AnoConclusao1)) { int year = Int32.Parse(userInfo.AnoConclusao1); college.EndDate = new DateTime(year, 1, 1); } if (userCareer.Colleges == null) { userCareer.Colleges = new List <College>(); } userCareer.Colleges.Add(college); } if (!CellIsEmpty(userInfo.Ingles)) { var language = new PerkLanguage() { Names = "Inglês", Level = userInfo.Ingles }; if (userCareer.Languages == null) { userCareer.Languages = new List <PerkLanguage>(); } userCareer.Languages.Add(language); } if (!CellIsEmpty(userInfo.Excel)) { var excel = new Perk() { Name = "Excel", Level = userInfo.Excel }; if (userCareer.Abilities == null) { userCareer.Abilities = new List <Perk>(); } userCareer.Abilities.Add(excel); } if (!CellIsEmpty(userInfo.VBA)) { var vba = new Perk() { Name = "VBA", Level = userInfo.VBA }; if (userCareer.Abilities == null) { userCareer.Abilities = new List <Perk>(); } userCareer.Abilities.Add(vba); } if ( !CellIsEmpty(userInfo.Empresa1) || !CellIsEmpty(userInfo.CargoEmpresa1) || !CellIsEmpty(userInfo.DescricaoEmpresa1) ) { var experience = new ProfessionalExperience() { Title = userInfo.Empresa1, Role = userInfo.CargoEmpresa1, Description = userInfo.DescricaoEmpresa1 }; if (userCareer.ProfessionalExperiences == null) { userCareer.ProfessionalExperiences = new List <ProfessionalExperience>(); } userCareer.ProfessionalExperiences.Add(experience); } if (!CellIsEmpty(userInfo.ObjetivoProfissionalCurto) && String.IsNullOrEmpty(userCareer.ShortDateObjectives)) { userCareer.ShortDateObjectives = userInfo.ObjetivoProfissionalCurto; } if (!CellIsEmpty(userInfo.ObjetivoProfissionalLongo) && String.IsNullOrEmpty(userCareer.LongDateObjectives)) { userCareer.LongDateObjectives = userInfo.ObjetivoProfissionalLongo; } if (createNew) { await _db.UserCareerCollection.InsertOneAsync( userCareer, cancellationToken : token ); } else { await _db.UserCareerCollection.ReplaceOneAsync( u => u.CreatedBy == user.Id, userCareer, cancellationToken : token ); } }