public async Task <Guid> PostPositionAsync(PositionDto position) { var newId = await PostGuidEntityAsync(positionsEndpoint, position); position.Id = newId.ToString(); return(newId); }
public static async void SetPositionAsync(Object send, Business.Events.EventArgs ea) // funzione chiamata da engine per inserire la propria posizione nel server { var position = new PositionDto { UserId = CurrentUser.Id, X = ea.X, Y = ea.Y }; var content = new StringContent(JsonConvert.SerializeObject(position), Encoding.UTF8, "application/json"); content.Headers.Add("id", CurrentUser.Id.ToString()); var response = new HttpResponseMessage(); try { response = await Client.PostAsync($"{ConnectionString}/api/1/position/addposition", content); var result = await response.Content.ReadAsStringAsync(); if (!ServerOnline) { System.Console.WriteLine("Connessione con il server ristabilita"); ServerOnline = true; } } catch (Exception) { System.Console.WriteLine("Server Offline"); ServerOnline = false; } }
public async Task <PositionDto> Update(PositionDto entity) { var result = mapper.Map <Position>(entity); await positionRepository.Update(result); return(entity); }
public async Task UpdatePosition_ShouldFail_GivenDuplicateName() { // Given // user authenticated in tenant #1 (Gryffindor House) // created 2 branch offices: "Position #2" & "Position #3" var pos2name = "Position #2"; var positionDto = new PositionDto { Id = Guid.NewGuid().ToString(), Name = pos2name, }; var positionDtoResponse = await _apiClient.PostPositionAsync(positionDto); positionDto.Name = "Position #3"; positionDto.Id = Guid.NewGuid().ToString(); var pos3guid = await _apiClient.PostPositionAsync(positionDto); positionDto.Id = pos3guid.ToString(); positionDto.Name = pos2name; // When // user attempts to rename Position #3 to Position #2 AsyncTestDelegate action = async() => await _apiClient.PutPositionAsync(positionDto); // Then // the request should fail Assert.ThrowsAsync <BadRequestException>(action); }
private void AssertPosition(PositionDto currentPosition, int posX, int posY, string orientation) { currentPosition.Should().NotBeNull(); currentPosition.X.Should().Be(posX); currentPosition.Y.Should().Be(posY); currentPosition.Orientation.Should().Be(orientation); }
private void btnSave_Click(object sender, RoutedEventArgs e) { if (string.IsNullOrEmpty(tbPositionName.Text)) { MessageBox.Show("Название вакансии не может быть пустым", "Проверка"); return; } if (string.IsNullOrEmpty(tbIsOpen.Text)) { MessageBox.Show("Открытость вакансии не может быть пустой", "Проверка"); return; } decimal salary; decimal.TryParse(tbSalary.Text, out salary); PositionDto position = new PositionDto(); position.PositionName = tbPositionName.Text; position.IsOpen = tbIsOpen.Text; position.Salary = salary; position.employer = cbEmployer.SelectedItem as EmployerDto; IPositionProcess positionProcess = ProcessFactory.GetPositionProcess(); if (_positionid == 0) { positionProcess.Add(position); } else { position.PositionID = _positionid; positionProcess.Update(position); } Close(); }
public void Load(PositionDto positionDto) { if (positionDto == null) { return; } _positionid = positionDto.PositionID; if (positionDto.Salary.HasValue) { tbSalary.Text = positionDto.Salary.ToString(); } if (!string.IsNullOrEmpty(positionDto.PositionName)) { tbPositionName.Text = positionDto.PositionName; } if (!string.IsNullOrEmpty(positionDto.IsOpen)) { tbIsOpen.Text = positionDto.IsOpen; } if (positionDto.employer != null) { foreach (EmployerDto employerDto in Employers) { if (positionDto.employer.EmployerID == employerDto.EmployerID) { this.cbEmployer.SelectedItem = employerDto; break; } } } }
public IActionResult AddAPosition([FromBody] PositionDto positionDto) { if (positionDto == null) { return(BadRequest(ModelState)); } if (_npRepo.CountryExists(positionDto.Name)) { ModelState.AddModelError("", "Country already exists."); return(StatusCode(404, ModelState)); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } // var ContactInfoObj = _mapper.Map<CreateEmployeeDto, ContactInfo>(createEmployeeDto); var positionObj = _mapper.Map <PositionDto, Position>(positionDto); // employeePIObj.ContactInfo = ContactInfoObj; if (!_npRepo.CreatePosition(positionObj)) { ModelState.AddModelError("", $"Something went wrong when saving the record {positionObj.Name}"); return(StatusCode(500, ModelState)); } return(Ok()); }
public async Task <IActionResult> SavePostion([FromBody] PositionDto positionDto) { try { if (positionDto == null) { return(BadRequest()); } var pos = new Position(); pos.Id = Guid.NewGuid(); pos.Name = positionDto.Name; pos.Description = positionDto.Description; pos.Status = true; pos.CreationDate = DateTime.Now; _db.Positions.Add(pos); await _db.Commit(); return(NoContent()); }catch (Exception ex) { _logger.LogError(ex, "Error guardando posición"); return(StatusCode(500)); } }
public async Task GetById_PositionId_ReturnsNotFound() { // Arrange var positionServiceMock1 = new Mock <IPositionService>(); var mapper1 = new Mock <IMapper>(); Position position = new Position { Id = 1 }; PositionDto positionDTO = new PositionDto { Id = 1 }; positionServiceMock1.Setup(p => p.GetPositionByIdAsync(position.Id)) .ReturnsAsync(null as Position); mapper1.Setup(m => m.Map <PositionDto>(position)) .Returns(positionDTO); var positionController1 = new PositionsController(positionServiceMock1.Object, mapper1.Object); // Act var actualResult = await positionController1.GetAsync(position.Id); // Assert Assert.True(actualResult is NotFoundResult); positionServiceMock1.Verify(m => m.GetPositionByIdAsync(position.Id), Times.Once); }
public override void AddRowButtonClick() { PositionDto area = new PositionDto(); area.PositionCode = "0"; dataHandler.AddRow(area); }
public async Task <IList <EmployeeDto> > GetByPosition(int posId) { List <Employee> employees = employeeRepository.GetByPosition(posId).ToList(); List <EmployeeDto> employeeDtos = new List <EmployeeDto>(); if (employees.Any()) { foreach (var employee in employees) { EmployeeDto empDtotemp = null; List <PositionDto> positions = new List <PositionDto>(); foreach (var pos in employee.EmployeePositions.Select(x => x.PositionId)) { Position temp = await positionRepository.Get(pos); PositionDto positionDto = mapper.Map <PositionDto>(temp); positions.Add(positionDto); } empDtotemp = mapper.Map <EmployeeDto>(employee); empDtotemp.Positions = positions.ToArray(); employeeDtos.Add(empDtotemp); positions = null; } return(employeeDtos); } return(null); }
public IActionResult PublishPosition([FromBody] PositionDto positionDto) { PositionDto savedPosition = null; if (!ModelState.IsValid) { return(BadRequest()); } else { int skillsWeightSum = (int)positionDto.PositionSkills.Select(ps => ps.SkillWeight).Sum(); if (skillsWeightSum != 10) { return(BadRequest()); } try { var repository = new PositionsRepository(_appDbContext); savedPosition = repository.SavePosition(positionDto, _clientData); savedPosition = repository.IncludeSkills(savedPosition); } catch (Exception e) { _log.LogError(e, "Error publishing position"); return(BadRequest()); } return(new OkObjectResult(savedPosition)); } }
public async Task <EmployeeDto> Get(int id) { var employee = await db.Get(id); EmployeeDto result = null; if (employee != null) { result = new EmployeeDto() { ID = employee.ID, FullName = employee.FullName, Birthdate = employee.Birthdate }; foreach (var item in employee.EmployeePositions) { if (item.Position != null) { var positionDto = new PositionDto() { ID = item.Position.ID, Name = item.Position.Name, Grad = item.Position.Grad }; result.Positions.Add(positionDto); } } } return(result); }
public async Task DeletePosition_ShouldSucceed_GivenPositionInUsersTenant() { // Given // user authenticated in tenant #1 (Gryffindor House) // and created Position named Position #5 var position2name = "Position #500"; var positionDto = new PositionDto { Id = Guid.NewGuid().ToString(), Name = position2name, }; await _apiClient.PostPositionAsync(positionDto); // When // the user attempts to delete the Position await _apiClient.DeletePositionAsync(positionDto.Id); // Then // the request should succeed // and the following request to get the position should fail Assert.ThrowsAsync <ItemNotFoundException>( async() => await _apiClient.GetPositionAsync(positionDto.Id) ); }
public DesignEmployee(int id, string firstName, PositionDto position, DateTime dateOfBirth) { Id = id; FirstName = firstName; Position = position; DateOfBirth = dateOfBirth; }
public async Task UpdatePosition_ShouldSucceed() { // Given // user authenticated in tenant #1 (Gryffindor House) // and created Position named Position #5 var bo2Name = "Position #5"; var positionDto = new PositionDto { Id = Guid.NewGuid().ToString(), Name = bo2Name, }; var bo2Guid = await _apiClient.PostPositionAsync(positionDto); positionDto.Id = bo2Guid.ToString(); positionDto.Name = "Position #5.1"; // When // the user attempts to rename Position #5 to Position #5.1 await _apiClient.PutPositionAsync(positionDto); // Then // the request should succeed }
public async Task CreatePosition_ShouldSucceed_GivenSameNames_InTwoTenants()// { // Given // user authenticated in tenant #1 (Gryffindor House) var positionDto = new PositionDto { Name = "Position #101" }; // created a tenant with the name "Position #100" var newGryffindorPositionId = await _apiClient.PostPositionAsync(positionDto); // switch to tenant #2 await _apiClient.AsSlytherinAdminAsync(_httpClient); // When // user from different tenant creates a Position with the name // duplicating name of a Position in a different tenant... positionDto.Id = null; var newSlytherinPositionId = await _apiClient.PostPositionAsync(positionDto); // Then // the request should succeed Assert.That(newSlytherinPositionId, Is.Not.EqualTo(newGryffindorPositionId)); }
public void Update_ShouldFail_GivenPositionDoesntExist() { // Given // PositionController over a mock service that would alway throw exceptions on Get & GetAsync _positionService.When(s => s.GetAsync(Arg.Any <Guid>())) .Do(v => throw new ItemNotFoundException(v[0].ToString(), "position")); var positionController = new PositionController( _positionService, _tenantIdProvider, Substitute.For <ILogger <PositionController> >()); var positionId = Guid.NewGuid(); var positionDto = new PositionDto { Id = positionId.ToString(), Name = "Position" }; // When // Put is called on the controller AsyncTestDelegate action = async() => await positionController.Put(positionId, positionDto); // Then // The controller should thrown ItemNotFoundException Assert.ThrowsAsync <ItemNotFoundException>(action); }
public async Task <PositionDto> GetAddressAsync(string latitude, string longitude) { if (string.IsNullOrEmpty(latitude) || string.IsNullOrEmpty(longitude)) { throw new ArgumentNullException(); } HttpClientHandler handler = new HttpClientHandler() { AutomaticDecompression = DecompressionMethods.GZip, }; using (var client = new HttpClient(handler)) { // client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json")); // client.DefaultRequestHeaders.AcceptLanguage.Add(new StringWithQualityHeaderValue("bg")); // client.DefaultRequestHeaders.AcceptEncoding.Add(new StringWithQualityHeaderValue("gzip")); var dto = new PositionDto(); try { var result = await client.GetAsync($"https://eu1.locationiq.com/v1/reverse.php?key={this.apiKey}&lat={latitude}&lon={longitude}&format=json&accept-language=native"); var byteArray = await result.Content.ReadAsByteArrayAsync(); var resultContent = ASCIIEncoding.UTF8.GetString(byteArray, 0, byteArray.Length); dto = JsonConvert.DeserializeObject <PositionDto>(resultContent); } catch (Exception) { throw new Exception(); } return(dto); } }
public async Task Update(PositionDto entity) { var position = await this.unitOfWork.Positions.Get(entity.Id); PositionMapper.MapUpdate(position, entity); await this.unitOfWork.Positions.Update(position); }
public void Create(PositionDto value) { if (value != null) { var position = mapper.Map <PositionDto, Position>(value); unitOfWork.PositionRepository.Create(position); } }
public IHttpActionResult CreatePosition(PositionDto position) { _unitOfWork.Positions.Add(Mapper.Map <Position>(position)); _unitOfWork.Complete(); return(Ok(position)); }
/// <summary> /// 转换为岗位实体 /// </summary> /// <param name="dto">岗位数据传输对象</param> public static Position ToEntity(this PositionDto dto) { if (dto == null) { return(new Position()); } return(dto.MapTo(new Position(dto.Id.ToGuid()))); }
public static Position Map(PositionDto position) { return(new Position { Id = position.Id, Name = position.Name, }); }
public async Task <long> UpdatePositionAsync(PositionDto positionDto) { var position = new Position(); Mapper.Map(positionDto, position); var rowsUpdated = await positionRepository.UpdatePositionAsync(position, positionDto.MappingScheme); return(rowsUpdated); }
private async void PositionChangedHandler(string axisName, Length currentPosition) { var positionDto = new PositionDto() { AxisName = axisName, Positon = currentPosition.ToUnit(LengthUnit.Millimeter) }; await _hubContext.Clients.All.PositionChanged(positionDto); }
private PositionDto ReadPosition(XmlReader xmlReader) { var position = new PositionDto(); var name = ReadValue(xmlReader); position.Name = name; return(position); }
public async Task <IActionResult> Update(PositionDto request) { if (request == null) { return(BadRequest()); } await service.Update(request); return(Ok()); }
public static PositionViewModel MapPosition(PositionDto position) { PositionViewModel positionViewModel = new PositionViewModel(); positionViewModel.Id = position.Id; positionViewModel.Name = position.Name; positionViewModel.Salary = position.Salary; positionViewModel.Staff = new List <StaffViewModel>(); return(positionViewModel); }