public async Task <BaseDtoResponse <CompanyRoleDto> > Update(Guid id, CreateCompanyRoleRequest request) { try { CompanyRole role = await _companyRoleRepository.GetById(id); if (role != null) { role.RoleName = request.RoleName; role.Description = request.Description; role.Salary = request.Salary; await _companyRoleRepository.Update(role); CompanyRole updatedResult = await _companyRoleRepository.GetById(id); CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(updatedResult); return(new BaseDtoResponse <CompanyRoleDto>(result)); } else { return(new BaseDtoResponse <CompanyRoleDto>("Role Not found")); } } catch (Exception ex) { return(new BaseDtoResponse <CompanyRoleDto>($"An error occurred when updating the Role: {ex.Message}")); } }
public async Task <IActionResult> CreateCompanyRole(int id, CompanyRoleToCreateDto companyRole) { CompanyRoleDto createdRole = await _service.CreateCompanyRole(id, companyRole); if (createdRole == null) { return(StatusCode(400)); } return(StatusCode(200, createdRole)); }
public async Task <IActionResult> GetCompanyRoleById(int roleId) { CompanyRoleDto companyRole = await _service.GetCompanyRole(roleId); if (companyRole == null) { return(StatusCode(404)); } return(StatusCode(200, companyRole)); }
public async Task <CompanyRoleDto> CreateCompanyRoleAsync(CompanyRoleToCreateDto companyRole, int id) { GetClient(); CompanyRoleDto createdCompanyRole = null; HttpResponseMessage response = await client.PostAsJsonAsync($"api/Companies/{id}/Roles", companyRole); if (response.IsSuccessStatusCode) { createdCompanyRole = await response.Content.ReadAsAsync <CompanyRoleDto>(); } return(createdCompanyRole); }
public async Task <CompanyRoleDto> UpdateCompanyRoleByIdAsync(CompanyRoleToUpdateDto companyRole, int id, int roleId) { GetClient(); CompanyRoleDto updatedCompanyRole = null; HttpResponseMessage response = await client.PutAsJsonAsync($"api/Companies/{id}/Roles/{roleId}", companyRole); if (response.IsSuccessStatusCode) { updatedCompanyRole = await response.Content.ReadAsAsync <CompanyRoleDto>(); } return(updatedCompanyRole); }
public async Task <BaseDtoResponse <CompanyRoleDto> > GetById(Guid id) { CompanyRole role = await _companyRoleRepository.GetById(id); if (role == null) { return(new BaseDtoResponse <CompanyRoleDto>("Role Not Found")); } CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(role); return(new BaseDtoResponse <CompanyRoleDto>(result)); }
public async Task <CompanyRoleDto> GetCompanyRoleByIdAsync(int id, int roleId) { GetClient(); CompanyRoleDto getCompanyRole = null; HttpResponseMessage response = await client.GetAsync($"api/Companies/{id}/Roles/{roleId}"); if (response.IsSuccessStatusCode) { getCompanyRole = await response.Content.ReadAsAsync <CompanyRoleDto>(); } return(getCompanyRole); }
public async Task <bool> DeleteCompanyRoleByIdAsync(int id, int roleId) { GetClient(); CompanyRoleDto deletedCompanyRole = null; HttpResponseMessage response = await client.DeleteAsync($"api/Companies/{id}/Roles/{roleId}"); if (response.IsSuccessStatusCode) { deletedCompanyRole = await response.Content.ReadAsAsync <CompanyRoleDto>(); return(true); } return(false); }
public async Task <bool> CreateUserCompanyRolesAsync(int id, int userId, int roleId) { GetClient(); CompanyRoleDto createdCompanyRole = null; HttpResponseMessage response = await client.PostAsJsonAsync($"api/Companies/{id}/Users/{userId}/Roles?roleId={roleId}", roleId); if (response.IsSuccessStatusCode) { createdCompanyRole = await response.Content.ReadAsAsync <CompanyRoleDto>(); return(true); } return(false); }
public async Task <IActionResult> DeleteCompanyRole(int id, int roleId) { CompanyRoleDto defaultCompanyRole = await _service.GetDefaultCompanyRole(id); if (defaultCompanyRole.Id == roleId) { return(StatusCode(400, "You can not delete the default role!")); } if (!await _service.DeleteCompanyRole(roleId)) { return(StatusCode(404)); } return(StatusCode(200)); }
private CompanyRoleDto ConvertToCompanyRoleDto(CompanyRole companyRole) { CompanyRoleDto companyRoleDto = new CompanyRoleDto { Id = companyRole.Id, CompanyId = companyRole.CompanyId, Name = companyRole.Name, Description = companyRole.Description, ManageCompany = companyRole.ManageCompany, ManageUsers = companyRole.ManageUsers, ManageProjects = companyRole.ManageProjects, ManageRoles = companyRole.ManageRoles, }; return(companyRoleDto); }
//Alle Role gegevens ophalen en tonen op het scherm protected async override void OnAppearing() { companyRoles = await companyRoleServices.GetAllCompanyRolesAsync(int.Parse(idCompany)); companyRole = await companyRoleServices.GetCompanyRoleByIdAsync(int.Parse(idCompany), roleId); CheckBoxIsDefault.IsChecked = companyRole.IsDefault; CheckBoxManageCompanies.IsChecked = companyRole.ManageCompany; CheckBoxManageRoles.IsChecked = companyRole.ManageRoles; CheckBoxManageUsers.IsChecked = companyRole.ManageUsers; CheckBoxManageProjects.IsChecked = companyRole.ManageProjects; EntryName.Text = companyRole.Name; RoleName = EntryName.Text; EntryDescription.Text = companyRole.Description; }
public async Task <IActionResult> UpdateCompanyRole(int id, int roleId, CompanyRoleToUpdateDto companyRole) { CompanyRoleDto defaultCompanyRole = await _service.GetDefaultCompanyRole(id); if (defaultCompanyRole.Id == roleId) { return(StatusCode(400, "You can not update the default role!")); } CompanyRoleDto updatedRole = await _service.UpdateCompanyRole(roleId, companyRole); if (updatedRole == null) { return(StatusCode(400)); } return(StatusCode(200, updatedRole)); }
//Role toevoegen private async void AddRoleButton_Clicked(object sender, EventArgs e) { if (CheckDescriptionAndName() == true) { CompanyRoleToCreateDto companyRole = new CompanyRoleToCreateDto { Name = EntryName.Text, Description = EntryDescription.Text, IsDefault = isDefault, ManageCompany = manageCompanies, ManageUsers = manageUsers, ManageProjects = manageProjects, ManageRoles = manageRoles }; AddRoleButton.IsEnabled = false; CompanyRoleDto companyRole1 = await companyRoleServices.CreateCompanyRoleAsync(companyRole, int.Parse(idCompany)); Application.Current.MainPage = new Roles(); } }
public async Task <BaseDtoResponse <CompanyRoleDto> > Add(CreateCompanyRoleRequest request) { try { CompanyRole model = _mapper.Map <CreateCompanyRoleRequest, CompanyRole>(request); CompanyRole role = await _companyRoleRepository.Add(model); if (role != null) { CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(role); return(new BaseDtoResponse <CompanyRoleDto>(result)); } else { return(new BaseDtoResponse <CompanyRoleDto>("Unable to create a new role, try again")); } } catch (Exception ex) { return(new BaseDtoResponse <CompanyRoleDto>($"An error occurred when saving the role: {ex.Message}")); } }
public async Task <BaseDtoResponse <CompanyRoleDto> > Delete(Guid id) { try { CompanyRole role = await _companyRoleRepository.GetById(id); if (role != null) { await _companyRoleRepository.Delete(role); CompanyRoleDto result = _mapper.Map <CompanyRole, CompanyRoleDto>(role); return(new BaseDtoResponse <CompanyRoleDto>(result)); } else { return(new BaseDtoResponse <CompanyRoleDto>("Unable to delete: Role Not found")); } } catch (Exception ex) { return(new BaseDtoResponse <CompanyRoleDto>($"An error occurred when deleting the role: {ex.Message}")); } }
static void Main() { //Create address AddressToCreateDto createdAddress = new AddressToCreateDto { Country = "Belgium", City = "Brussel", PostalCode = "1000", Street = "testStraat", HouseNumber = "20" }; //Create user UserToCreateDto createdUser = new UserToCreateDto { FirstName = "Mich", LastName = "dg", Email = "*****@*****.**", PhoneNumber = "+3256798487", Psw = "hallo", Address = createdAddress }; //Update address AddressToUpdateDto updatedAddress = new AddressToUpdateDto { Country = "Belgium", City = "Brussel", PostalCode = "1000", Street = "testStraat1", HouseNumber = "35" }; //Update user UserToUpdateDto updatedUser = new UserToUpdateDto { FirstName = "Michael", LastName = "DG", Email = "*****@*****.**", PhoneNumber = "+3256798489", Address = updatedAddress }; //Login UserToLoginDto login = new UserToLoginDto { Email = "*****@*****.**", Password = "******" }; //Create company CompanyToCreateDto createdCompany = new CompanyToCreateDto { Name = "Microsoft1", Address = createdAddress }; //Update company CompanyToUpdateDto updatedCompany = new CompanyToUpdateDto { Name = "Microsoft 2", Address = updatedAddress }; //Create companyrole CompanyRoleToCreateDto createdCompanyRole = new CompanyRoleToCreateDto { Name = "CompanyRole1", Description = "It's just a test", IsDefault = true, ManageCompany = true, ManageUsers = false, ManageProjects = true, ManageRoles = true }; //Update companyrole CompanyRoleToUpdateDto updatedCompanyRole = new CompanyRoleToUpdateDto { Name = "CompanyRole1Updated", Description = "It's just a test for something", IsDefault = true, ManageCompany = true, ManageUsers = true, ManageProjects = true, ManageRoles = true }; //Create project ProjectToCreateDto createdProject = new ProjectToCreateDto { CompanyID = 1, Name = "Tim", Description = "desc" }; //Update project ProjectToUpdateDto updatedProject = new ProjectToUpdateDto { CompanyID = 2, Name = "Kevin", Description = "desc 2" }; //Testen API calls UserServices userServices = new UserServices(); CompanyServices companyServices = new CompanyServices(); ProjectServices projectServices = new ProjectServices(); CompanyRoleServices companyRoleServices = new CompanyRoleServices(); LogServices logServices = new LogServices(); SessionServices sessionServices = new SessionServices(); UserDto user1 = new UserDto(); CompanyDto c = new CompanyDto(); CompanyRoleDto cr = new CompanyRoleDto(); ProjectDto p = new ProjectDto(); //Userservices //OK //user1 = userServices.GetUserByIdAsync(1).GetAwaiter().GetResult(); //List<UserDto> userlist = userServices.GetAllUsersAsync().GetAwaiter().GetResult(); //user1 = userServices.CreateUserAsync(createdUser).GetAwaiter().GetResult(); //user1 = userServices.UpdateUserByIdAsync(updatedUser, 1).GetAwaiter().GetResult(); //user1 = userServices.DeleteUserByIdAsync(3).GetAwaiter().GetResult(); //List<LogDto> user = userServices.GetAllUserLogsAsync(1).GetAwaiter().GetResult(); //List<UserDto> users = userServices.GetUserByEmailAsync("*****@*****.**").GetAwaiter().GetResult(); //List<LogDto> lk = userServices.GetAllUserLogsAsync(5).GetAwaiter().GetResult(); //Sessionservices //OK //string str = sessionServices.CreateSession(login); //string str = sessionServices.DeleteSessionAsync().GetAwaiter().GetResult(); //Companyservices //OK //List<CompanyDto> companylist = companyServices.GetAllCompaniesAsync().GetAwaiter().GetResult(); //c = companyServices.GetCompanyByIdAsync(1).GetAwaiter().GetResult(); //c = companyServices.CreateCompanyAsync(createdCompany).GetAwaiter().GetResult(); //c = companyServices.UpdateCompanyByIdAsync(updatedCompany, 1).GetAwaiter().GetResult(); //List<UserDto> cl = companyServices.GetUsersFromCompanyByIdAsync(1).GetAwaiter().GetResult(); //bool b = companyServices.AddUserToCompanyByIdAsync(1, 8).GetAwaiter().GetResult(); //CompanyRoleservices //OK //cr = companyRoleServices.CreateCompanyRoleAsync(createdCompanyRole, 1).GetAwaiter().GetResult(); //List<CompanyRoleDto> crlist = companyRoleServices.GetAllCompanyRolesAsync(1).GetAwaiter().GetResult(); //cr = companyRoleServices.GetCompanyRoleByIdAsync(1, 3).GetAwaiter().GetResult(); //cr = companyRoleServices.UpdateCompanyRoleByIdAsync(updatedCompanyRole, 1, 3).GetAwaiter().GetResult(); //Projectservices //OK //bool bp = projectServices.UpdateProjectByIdAsync(updatedProject, 1).GetAwaiter().GetResult(); //List<ProjectDto> projects = companyServices.GetAllCompanyProjectsAsync(1).GetAwaiter().GetResult(); //List<ProjectDto> projects = userServices.GetAllUserProjectsAsync(1).GetAwaiter().GetResult(); //bool pu = projectServices.RemoveUserToProjectAsync(1, 1).GetAwaiter().GetResult(); //bool u = projectServices.AddUserToProjectAsync(1, "*****@*****.**").GetAwaiter().GetResult(); //bool u = projectServices.RemoveUserToProjectAsync(1, 7).GetAwaiter().GetResult(); }