示例#1
0
 public HttpResponseMessage AdicionaOuAtualizaAnuncio(Anuncio anuncio)
 {
     try
     {
         AnuncioService anuncioService = new AnuncioService();
         anuncioService.AddOrUpdate(anuncio);
         if (anuncioService.ResponseType.Equals("Error"))
         {
             return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, anuncioService.ResponseMessage));
         }
         else
         {
             return(Request.CreateResponse(HttpStatusCode.OK, new
             {
                 Message = anuncioService.ResponseMessage,
                 Type = anuncioService.ResponseType,
                 FieldsInvalids = anuncioService.FieldsInvalids
             }));
         }
     }
     catch (Exception ex)
     {
         return(Request.CreateErrorResponse(
                    HttpStatusCode.BadRequest, "Erro ao cadastrar anuncio."));
     }
 }
示例#2
0
        public HttpResponseMessage Get()
        {
            try
            {
                AnuncioService anuncioService = new AnuncioService();

                var anuncios = anuncioService.Get();

                if (anuncioService.ResponseType.Equals("Error"))
                {
                    return(Request.CreateErrorResponse(HttpStatusCode.BadRequest, anuncioService.ResponseMessage));
                }
                else
                {
                    return(Request.CreateResponse(HttpStatusCode.OK, new
                    {
                        ListaAnuncios = anuncios,
                        Message = anuncioService.ResponseMessage,
                        Type = anuncioService.ResponseType,
                        FieldsInvalids = anuncioService.FieldsInvalids
                    }));
                }
            }
            catch (Exception ex)
            {
                return(Request.CreateErrorResponse(
                           HttpStatusCode.BadRequest, "Erro ao recuperar lista de anúncios."));
            }
        }
示例#3
0
        public AnuncioServiceTest() : base()
        {
            _anuncioRepository = new Mock <IAnuncioRepository>();
            SetupAnuncioRepository();
            SetupUnitOfWork();

            _anuncioService = new AnuncioService(handler, _uow.Object, _anuncioRepository.Object);
        }
        public void Deve_Retornar_Erro_De_Validacao_De_Todas_As_Propriedades_Obrigatoria_Para_Edicao()
        {
            var       db      = new Db();
            var       anuncio = new Anuncio();
            const int totalDePropriedadeObrigatorio = 8;
            var       resposta = new AnuncioService(db).Editar(anuncio);

            Assert.Equal(totalDePropriedadeObrigatorio, resposta.Errors.Count);
        }
示例#5
0
        public IActionResult Editar([FromServices] Db db, Anuncio param)
        {
            var service  = new AnuncioService(db);
            var response = service.Editar(param);

            response.RotaRetorno = "/Anuncio/Index";
            if (response.IsValidResponse())
            {
                return(Ok(response));
            }
            return(BadRequest(response));
        }
        public void Deve_Cadastrar_Um_Anuncio()
        {
            var db      = new Db();
            var anuncio = new Anuncio()
            {
                IdMarca         = InicializadorDeValores.IdMarcaInicializado,
                IdModelo        = InicializadorDeValores.IdModeloInicializado,
                Ano             = 2020,
                ValorCompra     = 20000,
                ValorVenda      = 25000,
                Cor             = "Preto_Teste",
                TipoCombustivel = Veiculos.Dominio.TipoCombustivel.Gasolina
            };
            var resposta = new AnuncioService(db).Cadastrar(anuncio);

            if (!resposta.IsValidResponse())
            {
                System.Console.WriteLine(resposta.Errors[0].Message);
            }


            Assert.True(resposta.IsValidResponse());
        }
示例#7
0
 public ApiController(AnuncioService anuncio, ModeloService modelo, MarcaService marca)
 {
     _anuncio = anuncio;
     _modelo  = modelo;
     _marca   = marca;
 }
示例#8
0
 public AnuncioWebMotorsController(AnuncioService <AnuncionWebMotorsModel, AnuncioWebMotorsEntity> anuncioService)
 {
     _anuncioService = anuncioService;
 }
 public AnuncioController(AnuncioService anuncioService, OnlineChallengeApiService onlineChallengeApiService)
 {
     _anuncioService            = anuncioService;
     _onlineChallengeApiService = onlineChallengeApiService;
 }
示例#10
0
        static void Main(string[] args)
        {
            Console.WriteLine("Hello World!");
            AnuncioService anuncioService = new AnuncioService(null, null, null, null);
            string         folder         = "C:\\Users\\Rafael Fernanadez\\Documents\\Trabajos\\RT\\Recuperacion de Anuncios\\Alain";

            //try
            //{
            //    using (StreamReader reader = new StreamReader("C:\\Users\\Rafael Fernanadez\\source\\repos\\RepublishCore\\RestoreAnuncios\\source.txt"))
            //    using (StreamWriter writer = new StreamWriter("C:\\Users\\Rafael Fernanadez\\source\\repos\\RepublishCore\\RestoreAnuncios\\target.txt"))
            //    {
            //        string url;
            //        int cnt = 1;
            //        while (!reader.EndOfStream && (url = reader.ReadLine()).Length > 0)
            //        {
            //            Console.WriteLine(cnt);
            //            try
            //            {
            //                FormInsertAnuncio formInsertAnuncio = anuncioService.Retrieve(url).GetAwaiter().GetResult();
            //                string jsonForm = $"{JsonConvert.SerializeObject(formInsertAnuncio)}";

            //                writer.WriteLine(jsonForm);
            //            }
            //            catch (Exception)
            //            {
            //                writer.WriteLine(" no " + url);
            //            }
            //            cnt++;
            //        }
            //    }
            //}
            //catch (Exception ex)
            //{
            //    Console.WriteLine(ex.Message);
            //}

            using (StreamReader reader = new StreamReader(folder + "\\target.txt"))
                using (StreamWriter writer = new StreamWriter(folder + "\\links-modificar.txt"))
                {
                    string line;
                    int    cnt = 1;
                    while (!reader.EndOfStream && (line = reader.ReadLine()).Length > 0)
                    {
                        Console.WriteLine(cnt);
                        try
                        {
                            FormInsertAnuncio formInsertAnuncio = JsonConvert.DeserializeObject <FormInsertAnuncio>(line);
                            //Captcha
                            string        html          = "DS\", \"RECAPTCHA_V2_SITE_KEY\":\"6LfyRCIUAAAAAP5zhuXfbwh63Sx4zqfPmh3Jnjy7\",\"RECAPTCHA_V3_SITE_KEY\":\"6Lfw";
                            CaptchaAnswer captchaAnswer = anuncioService.ResolveCaptcha("91092bd5c3c38f309e077e595d94226c", "https://www.revolico.com/insertar-anuncio.html", html).GetAwaiter().GetResult();
                            formInsertAnuncio.variables.captchaResponse = captchaAnswer.Answerv2;
                            //formInsertAnuncio.variables.botScore = captchaAnswer.Answerv3;

                            string       answer       = anuncioService.InsertAnuncio(formInsertAnuncio).GetAwaiter().GetResult();
                            InsertResult insertResult = anuncioService.ParseInsertResult(answer);
                            writer.WriteLine("https://www.revolico.com/modificar-anuncio.html?key=" + insertResult.FullId);
                        }
                        catch (Exception ex)
                        {
                            writer.WriteLine(" no " + cnt);
                            Console.WriteLine(ex.Message);
                        }
                        cnt++;
                    }
                }
        }