public async Task <int?> InsertAsync(EmployerRequest request) { string query = $"INSERT INTO Employee (NOM_EMPLOYEE, ID_DEPARTMENT, ID_OCCUPATION, GENDER, ACTIVE) VALUES('{ request.Name }',{ request.IdDepartment }, { request.IdOccupation }, '{ request.Gender }', '{ request.Active }')"; var result = await _connection.QueryAsync(query, null, _dbTransaction); return(result.FirstOrDefault()); }
public async Task InsertEmployerUseCaseAsync_WhenDataIsNotValid_MustReturnNotification() { // Arrange var useCase = InsertEmployerUseCase(); var employerRequest = new EmployerRequest(); // Act var result = await useCase.RunAsync(employerRequest); // Assert _notificationMessages.Verify(x => x.AddNotification("InsertEmployerUseCaseAsync", It.IsAny <string>(), HttpStatusCode.BadRequest), Times.Exactly(5)); }
public async Task <IActionResult> PostAsync( [FromServices] IInsertEmployerUseCaseAsync useCaseAsync, [FromBody] EmployerRequest request) { _logger.LogDebug("Insert employer"); var result = await useCaseAsync.RunAsync(request); if (_notificationMessages.HasNotification()) { return(BadRequest(_notificationMessages.Notications())); } return(Ok(result)); }
public HttpResponseMessage CreateEmployerRequest(string id) { try { var busLocIdGd = Guid.Parse(id); var email = HttpContext.Current.User.Identity.Name; //Check that employee email address is not already registered to the business if (db.Employees.Any(emp => emp.Email == email && emp.BusinessLocation.Id == busLocIdGd)) { return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Email address already registered with business location")); } //Check that employee is not already linked to the business if (db.Employees.Any(emp => emp.UserProfile.Email == email && emp.BusinessLocation.Id == busLocIdGd)) { return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "User is already registered with business location")); } //Check that a request hasn't already been lodged with the business previously if (db.EmployerRequests.Any(er => er.UserProfile.Email == email && er.BusinessLocation.Id == busLocIdGd)) { return(Request.CreateErrorResponse(HttpStatusCode.ExpectationFailed, "Request has already been registered with business location")); } var empRequest = new EmployerRequest(); empRequest.Id = Guid.NewGuid(); empRequest.CreatedDate = WebUI.Common.Common.DateTimeNowLocal(); empRequest.Status = RequestStatus.Pending; empRequest.BusinessLocation = db.BusinessLocations.SingleOrDefault(b => b.Id == busLocIdGd); empRequest.UserProfile = db.UserProfiles.SingleOrDefault(usr => usr.Email == email); db.EmployerRequests.Add(empRequest); db.SaveChanges(); return(Request.CreateResponse(HttpStatusCode.OK)); } catch (Exception ex) { throw new HttpResponseException(Request.CreateErrorResponse(HttpStatusCode.BadRequest, ex.Message)); } }
public async Task EmployerController_WhenInInsertEmployer_MustReturnValueOne() { // Arrange var employerController = GeEmployerContraller(); Mock <IInsertEmployerUseCaseAsync> _useCaseAsync = new Mock <IInsertEmployerUseCaseAsync>(); var request = new EmployerRequest() { IdDepartment = 1, Name = "Business" }; _useCaseAsync.Setup(x => x.RunAsync(request)).ReturnsAsync(1); var result = await employerController.PostAsync(_useCaseAsync.Object, request); // Act var objectResult = result.Should().BeOfType <OkObjectResult>().Subject; // Assert Assert.Equal(1, objectResult.Value); }
public async Task <int?> RunAsync(EmployerRequest request) { request.Gender = char.ToUpper(request.Gender); var notification = UtilValidators.ValidadorResult(new EmployerRequestValidator(), request); if (notification.Errors.Count > 0) { foreach (var item in notification.Errors.Select(x => x.ErrorMessage).ToArray().Distinct()) { _notificationMessages.AddNotification("InsertEmployerUseCaseAsync", item, HttpStatusCode.BadRequest); } return(0); } var result = await _unitOfWork.EmployerRepository.InsertAsync(request); _unitOfWork.Transaction(); return(result); }
public FluentMockEmployerRepository InsertAsync(EmployerRequest employerRequest) { Setup(x => x.InsertAsync(employerRequest)).ReturnsAsync(1); return(this); }