public async Task <IActionResult> Editar(string idUsuario, EdicionAnuncioRequest request) { try { var responseUser = await ValidarPropietario(idUsuario); if (!responseUser.Success) { return(StatusCode(StatusCodes.Status403Forbidden, responseUser.Message)); } var response = await _anuncioService.EditarAsync(idUsuario, request); if (!response.Success) { return(StatusCode(StatusCodes.Status400BadRequest, response.Message)); } return(Ok(response)); } catch (Exception ex) { return(StatusCode(StatusCodes.Status500InternalServerError, ex.Message)); } }
public AnuncioServiceIntegrationTest() { //Arrange string connectionString = "Server=HIDEAKIUCHIDA;Database=EVERESTDB;Integrated Security=True;"; string avanticaConnectionString = "Server=LIM-WS00279\\SQLEXPRESS;Database=EVERESTDB;Integrated Security=True;"; IDbConnection dbConnection = new SqlConnection(avanticaConnectionString); IAnuncioRepository anuncioRepository = new AnuncioRepository(dbConnection); IAnuncioDetalleRepository anuncioDetalleRepository = new AnuncioDetalleRepository(dbConnection); IUbicacionRepository ubicacionRepository = new UbicacionRepository(dbConnection); IUsuarioRepository usuarioRepository = new UsuarioRepository(dbConnection); ITipoPropiedadRepository tipoPropiedadRepository = new TipoPropiedadRepository(dbConnection); IEvaluacionRepository evaluacionRepository = new EvaluacionRepository(dbConnection); IImagenRepository imagenRepository = new ImagenRepository(dbConnection); IMapper mapper = new Mapper( new MapperConfiguration( configure => { configure.AddProfile <AutoMapperProfiles>(); } ) ); _anuncioService = new AnuncioService(anuncioRepository, anuncioDetalleRepository, usuarioRepository, tipoPropiedadRepository, ubicacionRepository, evaluacionRepository, imagenRepository, mapper); ValidCreacionAnuncioRequest = AnuncioFake.GetCreacionAnuncioRequest(); ValidEdicionAnuncioRequest = AnuncioFake.GetEdicionAnuncioRequest(); }
public AnuncioControllerUnitTest() { _anuncioServiceMock = new Mock <IAnuncioService>(); _usuarioServiceMock = new Mock <IUsuarioService>(); ValidCreacionAnuncioRequest = AnuncioFake.GetCreacionAnuncioRequest(); ValidEdicionAnuncioRequest = AnuncioFake.GetEdicionAnuncioRequest(); }
public async Task <BaseServiceResponse <bool> > EditarAsync(string idUsuario, EdicionAnuncioRequest request) { BaseServiceResponse <bool> response = new BaseServiceResponse <bool>(); var usuario = await _usuarioRepository.ConsultarUsuarioAsync(idUsuario); var anuncioResult = await _anuncioRepository.ConsultarAsync(request.IdAnuncio.Value); if (anuncioResult == null) { response.Message = "No existe el anuncio."; return(response); } if (anuncioResult.Activo) { response.Message = "No se puedo editar el anuncio porque se encuentra activo."; return(response); } var anuncio = _mapper.Map <AnuncioEntity>(request); anuncio.IdUsuario = usuario.IdUsuario; var anuncioUpdated = await _anuncioRepository.EditarAnuncioAsync(anuncio); if (!anuncioUpdated) { response.Message = "No se puedo editar el anuncio."; return(response); } var anuncioDetalle = _mapper.Map <AnuncioDetalleEntity>(request); var anuncioDetalleEntity = await _anuncioDetalleRepository.ConsultarAnuncioDetallePorAnuncioAsync(request.IdAnuncio.Value); anuncioDetalle.IdAnuncioDetalle = anuncioDetalleEntity != default ? anuncioDetalleEntity.IdAnuncioDetalle : default; var anuncioDetalleUpdated = await _anuncioDetalleRepository.EditarAnuncioDetalleAsync(anuncioDetalle); if (!anuncioDetalleUpdated) { response.Message = "No se puedo editar el detalle del anuncio."; return(response); } var ubicacion = _mapper.Map <UbicacionEntity>(request); var ubicacionEntity = await _ubicacionRepository.ConsultarPorAnuncioAsync(request.IdAnuncio.Value); ubicacion.IdUbicacion = ubicacionEntity != default ? ubicacionEntity.IdUbicacion : default; var ubicacionUpdated = await _ubicacionRepository.EditarUbicacionAsync(ubicacion); if (!ubicacionUpdated) { response.Message = "No se puedo editar la ubicación."; return(response); } response.Data = anuncioUpdated; response.Success = anuncioUpdated; response.Message = "Se actualizó exitosamente"; return(response); }