public ServiceResult <bool> CreateIncidenciaUsuario(IncidenciaUsuarioDtoIn incidenciaUsuarioDto)
        {
            try
            {
                if (!incidenciaValidationService.IsExistingIncidenciaId(incidenciaUsuarioDto.IncidenciaId))
                {
                    throw new ValidationException(IncidenciaMessageConstants.NotExistingIncidenciaId);
                }

                if (!usuarioValidationService.IsExistingUsuarioId(incidenciaUsuarioDto.UsuarioId))
                {
                    throw new ValidationException(UsuarioMessageConstants.NotExistingUsuarioId);
                }

                if (incidenciaUsuarioValidationService.IsExisingApoyo(incidenciaUsuarioDto.IncidenciaId, incidenciaUsuarioDto.UsuarioId))
                {
                    throw new ValidationException(IncidenciaUsuarioMessageConstants.ExistingApoyo);
                }

                var incidenciaUsuario = mapper.Map <IncidenciaUsuario>(incidenciaUsuarioDto);

                masterRepository.IncidenciaUsuario.Create(incidenciaUsuario);
                masterRepository.Save();

                return(ServiceResult <bool> .ResultOk(true));
            }
            catch (ValidationException e)
            {
                return(ServiceResult <bool> .ResultFailed(ResponseCode.Warning, e.Message));
            }
            catch (Exception e)
            {
                return(ServiceResult <bool> .ResultFailed(ResponseCode.Error, e.Message));
            }
        }
Example #2
0
        public ServiceResult <IncidenciaDtoOut> GetIncidenciaByIncidenciaId(int incidenciaId)
        {
            try
            {
                if (!incidenciaValidationService.IsExistingIncidenciaId(incidenciaId))
                {
                    throw new ValidationException(IncidenciaMessageConstants.NotExistingIncidenciaId);
                }

                var incidencia = masterRepository.Incidencia.FindByCondition(i =>
                                                                             i.IncidenciaId == incidenciaId).FirstOrDefault();

                var incidenciaDto = MapToDto(incidencia);

                return(ServiceResult <IncidenciaDtoOut> .ResultOk(incidenciaDto));
            }
            catch (ValidationException e)
            {
                return(ServiceResult <IncidenciaDtoOut> .ResultFailed(ResponseCode.Warning, e.Message));
            }
            catch (Exception e)
            {
                return(ServiceResult <IncidenciaDtoOut> .ResultFailed(ResponseCode.Error, e.Message));
            }
        }