예제 #1
0
        public async void Area_GetAll_Test_IntegrationTest()
        {
            ServiceProvider provider = ServiceCollectionArea();

            var areaService     = provider.GetRequiredService <IAreaService>();
            var areaRepositorio = provider.GetRequiredService <IAreaRepositorio>();
            var mapper          = provider.GetRequiredService <IMapper>();

            var dtoArea = new AreaRequestDto
            {
                Id                    = Guid.NewGuid(),
                NombreArea            = "Area_GetAll_Test_ITest",
                EmpleadoResponsableId = Guid.NewGuid(),
            };

            var area = areaRepositorio
                       .SearchMatching <AreaEntity>(x => x.Id == dtoArea.Id)
                       .FirstOrDefault();

            if (area != null || area != default)
            {
                _ = await areaRepositorio.Delete(area).ConfigureAwait(false);
            }

            _ = await areaService.Insert(dtoArea).ConfigureAwait(false);

            var result = mapper.Map <IEnumerable <AreaEntity> >(await areaService.GetAll().ConfigureAwait(false));

            Assert.NotNull(result.ToString());
            Assert.True(result.Any());

            _ = await areaService.Delete(dtoArea).ConfigureAwait(false);
        }
        public Task <AreaDto> Get(AreaRequestDto requestDto)
        {
            ValidationDto(requestDto);
            var entity = ValidationEntity(requestDto);

            return(Task.FromResult(_mapper.Map <AreaDto>(entity)));
        }
예제 #3
0
        public async Task <Guid?> AddArea(AreaRequestDto request)
        {
            ValidateRequireFields(request);
            if (string.IsNullOrEmpty(request.LiableEmployerId.ToString()))
            {
                var responseArea = await _repoArea.Insert(_mapper.Map <AreaEntity>(request)).ConfigureAwait(false);

                return(responseArea.AreaId);
            }
            var employedIdExist = _repoEmployed
                                  .SearchMatching <EmployedEntity>(employed => employed.EmployedId == request.LiableEmployerId).Any();

            if (!employedIdExist)
            {
                throw new AreaEmployeIdDontExistException($"El empleado con el id: {request.LiableEmployerId} no existe");
            }

            var employedLiableExist = _repoArea
                                      .SearchMatching <AreaEntity>(area => area.LiableEmployerId == request.LiableEmployerId)
                                      .Any();

            if (employedLiableExist)
            {
                throw new AreaLiableAlreadyExistException($"El empleado con el id: {request.LiableEmployerId} ya esta asignado a una area");
            }

            var response = await _repoArea.Insert(_mapper.Map <AreaEntity>(request)).ConfigureAwait(false);

            return(response.AreaId);
        }
        private AreaEntity ValidationEntity(AreaRequestDto requestDto)
        {
            var entity = _areaRepositorio.SearchMatchingOneResult <AreaEntity>(x => x.Id == requestDto.Id);

            if (entity == null || entity == default)
            {
                throw new AreaNoExistException(requestDto.NombreArea);
            }
            return(entity);
        }
예제 #5
0
 private static void ValidateRequireFields(AreaRequestDto request)
 {
     if (string.IsNullOrEmpty(request.AreaName))
     {
         throw new AreaNameNotDefinedException();
     }
     if (request.LiableEmployerId == Guid.Empty)
     {
         throw new AreaLiableEmployeedIdNotDefinedException();
     }
 }
 private static void ValidationDto(AreaRequestDto requestDto)
 {
     if (requestDto == null)
     {
         throw new AreaRequestDtoNullException();
     }
     if (requestDto.EmpleadoResponsableId == default)
     {
         throw new AreaEmpleadoResponsableIdNullException();
     }
 }
        public async Task <AreaResponseDto> AreaManagementUpdate(AreaRequestDto requestDto)
        {
            var result = await _areaService.Update(requestDto).ConfigureAwait(false) != default;

            return(new AreaResponseDto
            {
                Aceptado = result,
                StatusCode = result ? HttpStatusCode.OK : HttpStatusCode.Unauthorized,
                StatusDescription = result ? "Update" : "No Update"
            });
        }
        protected async void Agregar()
        {
            var areaDto = new AreaRequestDto {
                Id = Guid.NewGuid(), NombreArea = NuevoValor, EmpleadoResponsableId = Guid.NewGuid()
            };
            var response = await ClienteHttp.Post(areaDto).ConfigureAwait(false);

            await InvokeAsync(StateHasChanged).ConfigureAwait(false);

            NavigationManager.NavigateTo("/arealist");
        }
        public Task <bool> Update(AreaRequestDto requestDto)
        {
            ValidationDto(requestDto);
            var entity = ValidationEntity(requestDto);

            if (!string.IsNullOrEmpty(requestDto.NombreArea))
            {
                entity.NombreArea = requestDto.NombreArea;
            }

            entity.EmpleadoResponsableId = requestDto.EmpleadoResponsableId;

            return(_areaRepositorio.Update(entity));
        }
        public Task <bool> Delete(AreaRequestDto requestDto)
        {
            ValidationDto(requestDto);

            var empleado = _empleadoRepositorio
                           .SearchMatching <EmpleadoEntity>(x => x.AreaId == requestDto.Id)
                           .Any();

            if (empleado)
            {
                throw new EmpleadoAreaAlreadyExistException(requestDto.NombreArea);
            }
            var entity = _mapper.Map <AreaEntity>(requestDto);

            return(_areaRepositorio.Delete(entity));
        }
        public async Task <Guid> Insert(AreaRequestDto requestDto)
        {
            ValidationDto(requestDto);
            var usernameExist = _areaRepositorio
                                .SearchMatching <AreaEntity>(x => x.NombreArea == requestDto.NombreArea)
                                .Any();

            if (usernameExist)
            {
                throw new AreanameAlreadyExistException(requestDto.NombreArea);
            }

            var response = await _areaRepositorio.Insert(_mapper.Map <AreaEntity>(requestDto)).ConfigureAwait(false);

            return(response.Id);
        }
예제 #12
0
        public async void No_Eliminar_areas_que_tengan_empleados_asociados_Full_IntegrationTest()
        {
            ServiceProvider provider = ServiceCollectionArea();

            var areaService = provider.GetRequiredService <IAreaService>();

            var dtoArea = new AreaRequestDto
            {
                Id                    = Guid.NewGuid(),
                NombreArea            = "FakeAreaOk",
                EmpleadoResponsableId = Guid.NewGuid()
            };

            _ = await areaService.Insert(dtoArea).ConfigureAwait(false);

            bool response = await areaService.Delete(dtoArea).ConfigureAwait(false);

            Assert.NotEqual(default, response);
예제 #13
0
        protected override async Task OnInitializedAsync()
        {
            if (Id != "")
            {
                var areaDto = new AreaRequestDto {
                    Id = Guid.Parse(Id), NombreArea = "id", EmpleadoResponsableId = Guid.NewGuid()
                };
                AreaDto = await ClienteHttp.GetId(areaDto).ConfigureAwait(false);

                if (AreaDto != null)
                {
                    NuevoValor = AreaDto.NombreArea;
                    Loading    = false;
                }
                else
                {
                    Loading = true;
                }
            }
            _ = base.OnInitializedAsync();
        }
        public async void Area_Get_Test_IntegrationTest()
        {
            ServiceProvider provider = ServiceCollectionArea();

            var areaService     = provider.GetRequiredService <IAreaService>();
            var areaRepositorio = provider.GetRequiredService <IAreaRepositorio>();

            var dtoArea = new AreaRequestDto
            {
                Id                    = Guid.NewGuid(),
                NombreArea            = "FakeListAreaGetI",
                EmpleadoResponsableId = Guid.NewGuid()
            };

            var area = areaRepositorio
                       .SearchMatching <AreaEntity>(x => x.NombreArea == dtoArea.NombreArea)
                       .FirstOrDefault();

            if (area != null || area != default)
            {
                _ = await areaRepositorio.Delete(area).ConfigureAwait(false);
            }

            _ = await areaService.Insert(dtoArea).ConfigureAwait(false);

            var dtoArea2 = new AreaRequestDto
            {
                Id = dtoArea.Id,
                EmpleadoResponsableId = Guid.NewGuid()
            };
            var result = await areaService.Get(dtoArea2).ConfigureAwait(false);

            Assert.Equal(dtoArea.Id, result.Id);

            _ = await areaService.Delete(dtoArea).ConfigureAwait(false);
        }
 public async Task <AreaResponseDto> DeleteArea(AreaRequestDto requestDto) =>
 await _fachadaGenericasService.AreaManagementDelete(requestDto).ConfigureAwait(false);
예제 #16
0
 public async Task <AreaResponseDto> CreateArea(AreaRequestDto request) =>
 await _areaFacade.CreateArea(request).ConfigureAwait(false);
 public async Task <AreaDto> Post(AreaRequestDto areaDto) => await Post <AreaRequestDto>("InsertArea", areaDto).ConfigureAwait(false);
 public async Task <AreaDto> Put(AreaRequestDto areaDto) => await Put <AreaRequestDto>("UpdateArea", areaDto).ConfigureAwait(false);
 public async Task <AreaDto> GetId(AreaRequestDto areaDto) => await GetId <AreaRequestDto>("GetArea", areaDto).ConfigureAwait(false);
 public Task <AreaDto> AreaManagementGet(AreaRequestDto requestDto)
 {
     return(_areaService.Get(requestDto));
 }
 public async Task <AreaDto> GetArea(AreaRequestDto requestDto) =>
 await _fachadaGenericasService.AreaManagementGet(requestDto).ConfigureAwait(false);