public ActionResult <Concorrente> DeleteConcorrente(int negociacaoId, int id) { try { Negociacao n = _service.Find(negociacaoId); if (n == null) { return(NotFound("Negociação não encontrada!")); } Concorrente c = _concorrentesService.Find(id); if (c == null) { return(NotFound("Concorrente não encontrado!")); } if (c.NegociacaoId != negociacaoId) { return(BadRequest("Código de negociação inválido!")); } return(Ok(_concorrentesService.Delete(id))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public ActionResult <Concorrente> PostConcorrente(int id, Concorrente concorrente) { try { if (concorrente.NegociacaoId != 0 && concorrente.NegociacaoId != id) { return(BadRequest("Id da negociação inválido!")); } return(Ok(_concorrentesService.Add(concorrente))); } catch (Exception e) { return(BadRequest(e.Message)); } }
public IBotConcorrente CreateBotConcorrente(Concorrente tipo) { IBotConcorrente botConcorrente = null; switch (tipo) { case Concorrente.PontoFrio: botConcorrente = new PontoFrioBot(); break; case Concorrente.Submarino: botConcorrente = new SubmarinoBot(); break; } return botConcorrente; }
public async Task <IActionResult> Create(ConcorrenteRequestCreate concorrente) { var concorrenteNew = new Concorrente { Nome = concorrente.Nome, Apelido = concorrente.Apelido, Cnpj = concorrente.Cnpj, Ativo = true, DataCriacao = DateTime.Now, DataAtualizacao = DateTime.Now }; context.Concorrentes.Add(concorrenteNew); await context.SaveChangesAsync(); return(Ok()); }
public IActionResult Salvar(Concorrente concorrente, string hfListaTelefones) { ConcorrenteBLL BLL = new ConcorrenteBLL(); string mensagemErro; List <TelefoneConcorrente.TelefoneTela> telefones = new List <TelefoneConcorrente.TelefoneTela>(); if (!String.IsNullOrEmpty(hfListaTelefones)) { telefones = JsonConvert.DeserializeObject <List <TelefoneConcorrente.TelefoneTela> >(hfListaTelefones); } if (concorrente.Codigo == null) { if (BLL.insertConcorrente(concorrente, telefones, out mensagemErro)) { TempData["mensagemSucesso"] = "Concorrente cadastrado com sucesso!"; } else { TempData["mensagemErro"] = mensagemErro; } } else { //ATUALIZAR AMBIENTE if (BLL.updateConcorrente(concorrente, telefones, out mensagemErro)) { TempData["mensagemSucesso"] = "Concorrente atualizado com sucesso!"; } else { TempData["mensagemErro"] = mensagemErro; } } return(RedirectToAction("List")); }
public IActionResult Edit(int?codigoConcorrente) { ConcorrenteBLL BLL = new ConcorrenteBLL(); TelefoneConcorrenteBLL telefoneBLL = new TelefoneConcorrenteBLL(); string mensagemErro; if (codigoConcorrente != null && codigoConcorrente != 0) { Concorrente concorrenteCorrente = BLL.getConcorrentes((int)codigoConcorrente, "", out mensagemErro).FirstOrDefault(); if (concorrenteCorrente != null) { List <TelefoneConcorrente.TelefoneTela> telefones = telefoneBLL.getTelefonesConcorrenteTela(concorrenteCorrente.Codigo, out mensagemErro); ViewBag.listaTelefones = JsonConvert.SerializeObject(telefones); } return(View(concorrenteCorrente)); } else { return(View()); } }