예제 #1
0
        /// <summary>
        /// Crea un artículo en la base de datos
        /// </summary>
        /// <param name="Artículo"></param>
        /// <returns></returns>
        public async Task <ArtículoDto> AdicionarAsync(ArtículoDto Artículo)
        {
            HttpResponseMessage response;

            var elUri = $"{_MyStringUri}/Adicionar";

            Artículo.EstadoId = EstadoEnum.Activo;

            string json = JsonSerializer.Serialize(Artículo);

            try
            {
                response = await _consumirAPIService.POSTRequestAsync(elUri, json);
            }
            catch (Exception ex)
            {
                _logger.LogError(ex.Message);
                return(null);
            }
            return(JsonSerializer.Deserialize <ArtículoDto>(response.Content.ReadAsStringAsync().Result, new JsonSerializerOptions()
            {
                PropertyNameCaseInsensitive = true
            }));

            ;
        }
예제 #2
0
        /// <summary>
        /// Eliminar un artículo por Id
        /// </summary>
        /// <param name="artículoId"></param>
        /// <returns></returns>
        public async Task <bool> EliminarAsync(ArtículoDto Artículo)
        {
            HttpResponseMessage response;
            var elUri = $"{_MyStringUri}/Eliminar";

            string json = JsonSerializer.Serialize(Artículo);

            try
            {
                response = await _consumirAPIService.DELETERequestAsync(elUri, json);
            }
            catch (Exception ex)
            {
                Console.WriteLine(ex.Message);
                _logger.LogError(ex.Message);
                return(false);
            }
            return(true);;
        }
예제 #3
0
		protected override void OnInitialized()
		{

			ElArtículo = new ArtículoDto();
		}