public async Task <ResourceSkill> DeleteResourceSkill(ResourceSkill skill) { var sql = @" DELETE FROM ResourceSkill WHERE ResourceId = @ResourceId AND SkillDisciplineId IN ( SELECT Id FROM Disciplines WHERE Name = @ResourceDisciplineName ) AND ResourceDisciplineID = SkillDisciplineID AND SkillId IN ( SELECT Id FROM Skills WHERE Name = @Name ) ;"; using var connection = new SqlConnection(connectionString); connection.Open(); await connection.QueryAsync <ResourceDiscipline>(sql, new { ResourceId = skill.ResourceId, ResourceDisciplineName = skill.ResourceDisciplineName, Name = skill.Name }); return(skill); }
public bool Equals(ResourceSkill other) { if (other is null) { return(false); } else { return(this.ResourceDisciplineName == other.ResourceDisciplineName && this.Name == other.Name); } }
public async Task <int> GetSkillByDisciplineAndName(ResourceSkill skill) { var sql = @"select s.id from Disciplines as d, Skills as s where d.[Name] = @DisciplineName and d.id = s.DisciplineId and s.[Name] = @SkillName;" ; using var connection = new SqlConnection(connectionString); connection.Open(); var result = await connection.QuerySingleAsync(sql, new { DisciplineName = skill.ResourceDisciplineName, SkillName = skill.Name }); return(result); }
private IEnumerable <ResourceSkill> createResourceSkillsFromProfile(IEnumerable <ResourceDisciplineResource> disciplines, string userId) { var result = Enumerable.Empty <ResourceSkill>(); foreach (var disc in disciplines) { foreach (var skill in disc.Skills) { var sk = new ResourceSkill(); sk.ResourceId = userId; sk.ResourceDisciplineName = disc.Discipline; sk.Name = skill; result = result.Append(sk); } } // Log.Logger.Information("complete loop in skill creation"); return(result); }
public int SaveResource(Resource resourceData, List <ResourceSkill> resourceSkills) { int entriesSaved = 0; var resource = new Resource() { Name = resourceData.Name, Title = resourceData.Title, PayRate = resourceData.PayRate, AvailabilityCalendar = resourceData.AvailabilityCalendar }; ResourceSkill resourceSkill = new ResourceSkill(); foreach (var rs in resourceSkills) { resourceSkill = new ResourceSkill() { SkillLevel = rs.SkillLevel, SkillId = rs.SkillId, ResourceId = resource.Id.ToString() }; } try { this.db.Add(resource); if (resourceSkills.Count > 0) { this.db.Add(resourceSkill); } entriesSaved = this.db.SaveChanges(); } catch (SqlException ex) { Console.Write(ex.Message); } return(entriesSaved); }
public async Task <ResourceSkill> InsertResourceSkill(ResourceSkill skill) { var sql = @" INSERT INTO ResourceSkill VALUES ( @ResourceId, (SELECT Id FROM Disciplines WHERE Name = @ResourceDisciplineName), (SELECT Id FROM Disciplines WHERE Name = @ResourceDisciplineName), (SELECT Id FROM Skills WHERE Name = @Name AND DisciplineId = (SELECT Id FROM Disciplines WHERE Name = @ResourceDisciplineName)) ) ;"; using var connection = new SqlConnection(connectionString); connection.Open(); await connection.QueryFirstOrDefaultAsync(sql, new { ResourceId = skill.ResourceId, ResourceDisciplineName = skill.ResourceDisciplineName, Name = skill.Name }); return(skill); }
private void Setup_AllRepo_UpdateUser(ResourceDiscipline discipline, IEnumerable <ResourceDiscipline> dbDisciplines, OutOfOffice availability, IEnumerable <OutOfOffice> dbAvailability, ResourceSkill skill, IEnumerable <ResourceSkill> dbSkills) { // Disciplines Repo Setup_DisciplinesRepo_GetUserDisciplines_Default(dbDisciplines); Setup_DisciplinesRepo_DeleteResourceDiscipline_Default(discipline); Setup_DisciplinesRepo_InsertResourceDiscipline_Default(discipline); // OutOfOffice repo Setup_OutOfOfficeRepo_GetAllOutOfOfficeForUser_Default(dbAvailability); Setup_OutOfOffice_InsertOutOfOffice_Default(availability); Setup_OutOfOfficeRepo_DeleteOutOfOffice_Default(availability); // Skills repo Setup_SkillsRepo_GetUserSkills_Default(dbSkills); Setup_SkillsRepo_DeleteResourceSkill_Default(skill); Setup_SkillsRepo_InsertResourceSkill_Default(skill); }
private void Setup_SkillsRepo_DeleteResourceSkill_Default(ResourceSkill returnVal) { _mockSkillsRepo.Setup( repo => repo.DeleteResourceSkill(It.IsAny <ResourceSkill>()) ).ReturnsAsync(returnVal); }