public async Task <IActionResult> Create([Bind("Id,Nome,Telefone,Site,TaxaAvaliacaoPadrao,TaxaVendaPadrao")] Leiloeiro leiloeiro) { if (ModelState.IsValid) { _context.Add(leiloeiro); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(leiloeiro)); }
public async Task <IActionResult> Create(Leilao leilao) { if (ModelState.IsValid) { _context.Add(leilao); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(leilao)); }
public async Task <IActionResult> Create(Lote Lote) { if (ModelState.IsValid) { _context.Add(Lote); await _context.SaveChangesAsync(); return(RedirectToAction("Details", "Leiloes", new { Id = Lote.LeilaoId })); } return(View(Lote)); }
public async Task <IActionResult> Create([Bind("Id,OlxIdVendedor,Nome")] VendedorProibido vendedorProibido) { if (ModelState.IsValid) { _context.Add(vendedorProibido); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(vendedorProibido)); }
public async Task <IActionResult> Create([Bind("Id,Descricao,Data,TaxaAvaliacao,TaxaVenda,LeiloeiroId")] Leilao leilao) { if (ModelState.IsValid) { _context.Add(leilao); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LeiloeiroId"] = new SelectList(_context.Leiloeiro, "Id", "Id", leilao.LeiloeiroId); return(View(leilao)); }
public async Task <IActionResult> Create([Bind("Id,Numero,VlAvalicao,VlCondicional,VlLance,ProdutoId,LeilaoId")] Lote lote) { if (ModelState.IsValid) { _context.Add(lote); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["LeilaoId"] = new SelectList(_context.Leilao, "Id", "Id", lote.LeilaoId); return(View(lote)); }
//POST: Atualizar NotView em anuncio public async Task <bool> UpdateNotView(bool notView, int id) { var anuncio = await _context.Anuncio.FindAsync(id); if (anuncio == null) { return(false); } anuncio.NotView = notView; if (ModelState.IsValid) { try { _context.Update(anuncio); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { return(false); } } return(true); }
//[Authorize(Roles = "Administrator")] public async Task <IActionResult> Edit(string id, Usuario Usuario) { if (id != Usuario.Id) { return(NotFound()); } if (ModelState.IsValid) { var UsuarioAtual = await _context.Usuario.FindAsync(id); if (Usuario.UserName != UsuarioAtual.UserName) { var pathAntigo = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/avatars", UsuarioAtual.UserName + ".jpg"); var pathNovo = Path.Combine(Directory.GetCurrentDirectory(), "wwwroot/img/avatars", Usuario.UserName + ".jpg"); var setUserNameResult = await _userManager .SetUserNameAsync(UsuarioAtual, Usuario.UserName); if (!setUserNameResult.Succeeded) { throw new InvalidOperationException( $"Erro ao alterar o Nome de Usuário: '{Usuario.UserName}'."); } if (System.IO.File.Exists(pathAntigo)) { System.IO.File.Move(pathAntigo, pathNovo); System.IO.File.Delete(pathAntigo); } else if (!System.IO.File.Exists(pathNovo)) { CriarAvatar(avatarDefault, Usuario.UserName); } } if (Usuario.Email != UsuarioAtual.Email) { var setEmailResult = await _userManager .SetEmailAsync(UsuarioAtual, Usuario.Email); if (!setEmailResult.Succeeded) { throw new InvalidOperationException($"Erro ao alterar o email do usuário: '{Usuario.UserName}'."); } } if (Usuario.PhoneNumber != UsuarioAtual.PhoneNumber) { var setPhoneResult = await _userManager .SetPhoneNumberAsync(UsuarioAtual, Usuario.PhoneNumber); if (!setPhoneResult.Succeeded) { throw new InvalidOperationException($"Erro ao alterar o telefone do usuário: '{Usuario.UserName}'."); } } if (Usuario.LockoutEnd != UsuarioAtual.LockoutEnd) { Usuario.LockoutEnd = null; var setLockoutEndResult = await _userManager .SetLockoutEndDateAsync(UsuarioAtual, Usuario.LockoutEnd); if (!setLockoutEndResult.Succeeded) { throw new InvalidOperationException($"Erro ao alterar o LockoutEnd do usuário: '{Usuario.UserName}'."); } } if (Usuario.EmailConfirmed != UsuarioAtual.EmailConfirmed) { UsuarioAtual.EmailConfirmed = Usuario.EmailConfirmed; } UsuarioAtual.Nome = Usuario.Nome; UsuarioAtual.Endereco = Usuario.Endereco; UsuarioAtual.Celular = Usuario.Celular; try { _context.Update(UsuarioAtual); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!UsuarioExists(Usuario.Id)) { return(NotFound()); } else { throw; } } if (Usuario.UserName == User.Identity.Name) { return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Lista))); } return(View(Usuario)); }
public async Task <IActionResult> BuscarLotesBsb(string username, string password) { if (username == null) { return(RedirectToAction("ImportarBsb", "Produtos")); } try { CookieContainer cookieJar = new CookieContainer(); var client = new RestClient("https://www.bsbleiloes.com.br/arrematante/login"); client.CookieContainer = cookieJar; client.Timeout = -1; var request = new RestRequest(Method.POST); request.AddParameter("_password", password); request.AddParameter("_username", username); var response = client.Execute(request); client = new RestClient("https://www.bsbleiloes.com.br/arrematante/minhas-arrematacoes"); client.CookieContainer = cookieJar; client.Timeout = -1; request = new RestRequest(Method.GET); response = client.Execute(request); if (response.StatusCode == HttpStatusCode.OK) { var textoGeral = response.Content; List <Produto> listProduto = new List <Produto>(); int pos1; int pos2; int limite; DateTime dataLeilao; int x = 0; pos1 = textoGeral.LastIndexOf("card card-plain"); if (pos1 > -1) { //busca ultimo Id de produto no BD e incrementa-o quando for criar novo produto int lastId = await _context.Produto.OrderByDescending(o => o.Id).Select(o => o.Id).FirstOrDefaultAsync(); var usuario = await _userManager.FindByNameAsync(User.Identity.Name); //lastId = (ultimoProduto != null) ? ultimoProduto.Id + 1 : 1; // data do leilao pos1 = textoGeral.IndexOf("aria-controls", pos1); pos1 = textoGeral.IndexOf(">", pos1) + 1; pos2 = textoGeral.IndexOf("<i class=", pos1) - 1; dataLeilao = DateTime.Parse(textoGeral.Substring(pos2 - 104, 10).TrimStart().TrimEnd()); //tituloLeilao = "BSB-" + dataLeilao.ToString("dd/MM/yy"); //verifica no banco de dados se o primeiro produto já está cadastrado if (await _context.Produto.AnyAsync(m => m.DataAnuncio == dataLeilao && m.Vendedor == "BSB")) { pos1 = -1; //não processa os dados da página } while (pos1 > -1) { limite = textoGeral.IndexOf("</tbody>", pos1); pos1 = textoGeral.IndexOf("<td>", pos1) + 5; while (pos1 < limite && pos1 > 0) { listProduto.Add(new Produto() { Id = ++lastId, UsuarioId = usuario.Id, DataAnuncio = dataLeilao, DataCadastro = DateTime.Now.Date, Vendedor = "BSB" }); //lote pos2 = textoGeral.IndexOf("</td>", pos1) - 1; listProduto[x].Descricao += $"Lote {textoGeral.Substring(pos1, pos2 - pos1).Trim()}"; //bem pos1 = textoGeral.IndexOf("<td>", pos1 + 1) + 5; pos2 = textoGeral.IndexOf("</td>", pos1) - 1; listProduto[x].Titulo = textoGeral.Substring(pos1, pos2 - pos1).TrimStart().TrimEnd(); if (listProduto[x].Titulo.IndexOf("(NO ESTADO)") > 0) { listProduto[x].Titulo = listProduto[x].Titulo.Remove(listProduto[x].Titulo.IndexOf("(NO ESTADO)"), 11); } //valor pago for (int i = 0; i < 5; i++) { pos1 = textoGeral.IndexOf("<td>", pos1 + 2); } pos1 = textoGeral.IndexOf("R$", pos1) + 3; pos2 = textoGeral.IndexOf("\n", pos1); double valorTemp = 0; bool result = double.TryParse(textoGeral.Substring(pos1, pos2 - pos1).TrimStart().TrimEnd(), out valorTemp); listProduto[x].VlCompra = valorTemp; ++x; pos1 = textoGeral.IndexOf("<td>", pos1) + 5; } //proximo leilão textoGeral = textoGeral.Substring(0, textoGeral.LastIndexOf("card card-plain") - 1); pos1 = textoGeral.LastIndexOf("card card-plain"); // data do leilao pos1 = textoGeral.IndexOf("aria-controls", pos1); pos1 = textoGeral.IndexOf(">", pos1) + 1; pos2 = textoGeral.IndexOf("<i class=", pos1) - 1; dataLeilao = DateTime.Parse(textoGeral.Substring(pos2 - 104, 10).TrimStart().TrimEnd()); } if (listProduto.Count > 0) { //incluir produtos no BD _context.Produto.AddRange(listProduto); await _context.SaveChangesAsync(); return(RedirectToAction("Index", "Produtos")); } } } } catch (WebException) { return(RedirectToAction("ImportarBsb", "Produtos")); } return(RedirectToAction("ImportarBsb", "Produtos")); }