public ActionResult CreateAnuncio(AnuncioViewModel anuncio) { anuncio anuncioNew = new anuncio(); string guid = Guid.NewGuid().ToString().ToUpper(); var toPathUpload = Server.MapPath($"~/images/anuncio/{guid}"); var newPathUploadFileName = $"{toPathUpload}/{anuncio.foto1}"; var newPathUploadFileName2 = $"{toPathUpload}/{anuncio.foto2}"; Directory.CreateDirectory(toPathUpload); System.IO.File.Create(newPathUploadFileName); System.IO.File.Create(newPathUploadFileName2); anuncioNew.idCategoria = anuncio.idcategoria; anuncioNew.preco = anuncio.preco; anuncioNew.medida = anuncio.medida; anuncioNew.descricao = anuncio.descricao; anuncioNew.foto1 = anuncio.foto1; anuncioNew.foto2 = anuncio.foto2; anuncioNew.idUsuario = anuncio.idUsuario; db.anuncio.Add(anuncioNew); db.SaveChanges(); return(RedirectToAction("Index", "Home")); }
public ActionResult Create(AnuncioViewModel anuncio, FormCollection fobj) { try { if (ModelState.IsValid) { var anuncioDomain = Mapper.Map <AnuncioViewModel, Anuncio>(anuncio); anuncioDomain.Marca = fobj["hiddenMarca"].ToString(); anuncioDomain.Modelo = fobj["hiddenModelo"].ToString(); anuncioDomain.Versao = fobj["hiddenVersao"].ToString(); _boAnuncio.Incluir(anuncioDomain); ViewBag.Incluir = 1; return(RedirectToAction("Index")); } return(View(anuncio)); } catch (Exception) { return(View(anuncio)); } }
public async Task <IActionResult> Edit(int id, [Bind("Id,Marca,Modelo,Versao,Ano,Quilometragem,Observacao")] AnuncioViewModel anuncioModel) { if (id != anuncioModel.Id) { return(NotFound()); } if (ModelState.IsValid) { try { HttpResponseMessage response = await _client.PutAsJsonAsync("api/Anuncio/" + id.ToString().Trim(), anuncioModel); } catch (DbUpdateConcurrencyException) { if (!AnuncioModelExists(anuncioModel.Id)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(anuncioModel)); }
public AnuncioViewModel ConverteParaAnuncioViewModel(Anuncio anuncio) { var apiAcess = new APIAccess(); var marca = apiAcess.GetMarcas().FirstOrDefault(x => x.Name == anuncio.Marca); int marcaId = marca != null ? marca.ID : 0; var modelo = apiAcess.GetModelos(marcaId).FirstOrDefault(x => x.Name == anuncio.Modelo); var modeloId = modelo != null ? modelo.ID : 0; var versao = apiAcess.GetVersoes(modeloId).FirstOrDefault(x => x.Name == anuncio.Versao); var versaoId = versao != null ? versao.ID : 0; var anuncioViewModel = new AnuncioViewModel() { Id = anuncio.Id, MarcaId = marcaId, Marca = anuncio.Marca, ModeloId = modeloId, Modelo = anuncio.Modelo, VersaoId = versaoId, Versao = anuncio.Versao, Ano = anuncio.Ano, Quilometragem = anuncio.Quilometragem, Observacao = anuncio.Observacao }; return(anuncioViewModel); }
public List <AnuncioViewModel> GetAll() { try { var anuncios = _anuncioServices.GetAll(); var listaAnuncios = new List <AnuncioViewModel>(); foreach (var item in anuncios) { var anuncio = new AnuncioViewModel() { ID = item.ID, Ano = item.Ano, Marca = item.Marca, Modelo = item.Modelo, Observacao = item.Observacao, Quilometragem = item.Quilometragem, Versao = item.Versao }; listaAnuncios.Add(anuncio); } return(listaAnuncios); } catch (Exception ex) { throw ex; } }
public async Task <IActionResult> PutAnuncioModel(int id, AnuncioViewModel anuncioModel) { if (id != anuncioModel.Id) { return(BadRequest()); } var anuncio = _mapper.Map <Anuncio>(anuncioModel); _context.Entry(anuncio).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AnuncioModelExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public IActionResult Edit(int id) { if (id == 0) { return(NotFound()); } var anuncio = _anuncioApplication.ObterPorId(id); if (anuncio == null) { return(NotFound()); } var anuncioViewModel = new AnuncioViewModel { ID = anuncio.ID, Ano = anuncio.Ano, Marca = anuncio.Marca, Modelo = anuncio.Modelo, Observacao = anuncio.Observacao, Quilometragem = anuncio.Quilometragem, Versao = anuncio.Versao }; return(View(anuncioViewModel)); }
public ActionResult EditarAnuncioEscolhido(AnuncioViewModel anuncio) { try { AnuncioViewModel anuncioUpdate = new AnuncioViewModel(); anuncio anunEditar = db.anuncio.FirstOrDefault(x => x.id == anuncio.id); anunEditar.descricao = anuncio.descricao; anunEditar.idCategoria = anuncio.idcategoria; anunEditar.idUsuario = anuncio.idUsuario; anunEditar.medida = anuncio.medida; anunEditar.preco = anuncio.preco; anunEditar.foto1 = anuncio.foto1; anunEditar.foto2 = anuncio.foto2; db.SaveChanges(); return(Json(new { Success = true })); } catch { return(Json(new { Success = false, Response = "Falha ao editar o registro" })); } }
public async Task <IActionResult> Index() { AnuncioViewModel vm = new AnuncioViewModel(); vm.AnuncioList = db.TbAnuncioWebmotors.ToList(); return(View(vm)); }
public async Task <IActionResult> Editar(int id) { AnuncioViewModel vm = new AnuncioViewModel(); vm.Anuncio = db.TbAnuncioWebmotors.FirstOrDefault(x => x.Id == id); return(View(vm)); }
public async Task <ActionResult <AnuncioViewModel> > PostAnuncioModel(AnuncioViewModel anuncioModel) { var anuncio = _mapper.Map <Anuncio>(anuncioModel); _context.Anuncio.Add(anuncio); await _context.SaveChangesAsync(); return(CreatedAtAction("GetAnuncioModel", new { id = anuncio.Id }, anuncioModel)); }
public async Task <IActionResult> Create() { AnuncioViewModel model = new AnuncioViewModel() { Anuncio = new Anuncio(), Makes = await _makeService.GetAsync() }; return(View(model)); }
public async Task <IActionResult> Create([Bind("Id,Marca,Modelo,Versao,Ano,Quilometragem,Observacao")] AnuncioViewModel anuncioModel) { if (ModelState.IsValid) { HttpResponseMessage response = await _client.PostAsJsonAsync("api/Anuncio", anuncioModel); return(RedirectToAction(nameof(Index))); } return(View(anuncioModel)); }
public IActionResult Add([Bind] AnuncioViewModel anuncioViewModel) { if (ModelState.IsValid) { _anuncioApplication.Adicionar(anuncioViewModel); return(RedirectToAction("Index")); } return(View(anuncioViewModel)); }
public ActionResult Create(AnuncioViewModel collection) { if (!ModelState.IsValid) { return(View(collection)); } context.Registrar(collection); return(RedirectToAction("Index")); }
public IHttpActionResult Get(int id) { AnuncioViewModel anuncioViewModel = db.AnuncioViewModels.Find(id); if (anuncioViewModel == null) { return(NotFound()); } return(Ok(anuncioViewModel)); }
public static Anuncio MapearAnuncio(AnuncioViewModel anuncioViewModel) { var anuncio = new Anuncio(anuncioViewModel.Marca, anuncioViewModel.Modelo, anuncioViewModel.Versao, anuncioViewModel.Ano, anuncioViewModel.Quilometragem, anuncioViewModel.Observacao); return(anuncio); }
public ActionResult Edit(int?id, AnuncioViewModel collection) { if (!ModelState.IsValid) { return(View(collection)); } context.Atualizar(collection); return(RedirectToAction("Index")); }
public ActionResult Create(AnuncioViewModel collection) { if (!ModelState.IsValid) { return(View(collection)); } context.Registrar(collection); ViewBag.RetornoPost = OperacaoValida() ? "sucesso,Evento registrado com sucesso" : "error,Evento nao registrado verifique as mensagens!"; return(View(collection)); }
public ActionResult Edit(AnuncioViewModel anuncio) { if (ModelState.IsValid) { var anuncioDomain = _mapper.Map <AnuncioViewModel, Anuncio>(anuncio); _anuncioApp.Update(anuncioDomain); return(RedirectToAction("Index")); } return(View(anuncio)); }
public ActionResult Edit(AnuncioViewModel anuncio) { if (!ModelState.IsValid) { return(View(anuncio)); } var novoAnuncio = Mapper.Map <AnuncioViewModel, Anuncio>(anuncio); _anuncioApp.Update(novoAnuncio); return(View(Mapper.Map <Anuncio, AnuncioViewModel>(novoAnuncio))); }
// POST: api/Anuncio public IHttpActionResult Post([FromBody] AnuncioViewModel value) { try { _appService.Add(value); _appService.Save(); return(Ok(new { ok = true })); } catch (Exception e) { return(Ok(new { ok = false, msg = e.Message })); } }
public async Task <IActionResult> Atualizar(int id) { if (id <= 0) { return(RedirectToAction("index")); } var anuncio = await _repositorio.ObterPorIdComCliente(id); var anuncioViewModel = new AnuncioViewModel(anuncio); return(View(anuncioViewModel)); }
public ActionResult Edit(int?id, AnuncioViewModel collection) { if (!ModelState.IsValid) { return(View(collection)); } context.Atualizar(collection); // TODO: Validar se a operação ocorreu com sucesso! ViewBag.RetornoPost = OperacaoValida() ? "sucesso,Evento Atualizado com sucesso" : "error,Evento nao pode ser atualizado verifique as mensagens!"; return(View(collection)); }
public IActionResult AtualizarAnuncio([FromBody] AnuncioViewModel dados) { try { var anuncio = _mapper.Map <Anuncio>(dados); var sucesso = _anuncioService.AtualizarAnuncio(anuncio); return(Resposta(sucesso)); } catch (Exception ex) { return(InternalServerError(ex)); } }
public ActionResult Create(AnuncioViewModel anuncio) { if (!ModelState.IsValid) { ViewBag.ClienteId = new SelectList(_clienteApp.GetAll(), "ClienteId", "Nome", anuncio.ClienteId); return(View(anuncio)); } anuncio.ClienteId = Convert.ToInt32(Session["usuarioLogadoId"].ToString()); var novoAnuncio = Mapper.Map <AnuncioViewModel, Anuncio>(anuncio); _anuncioApp.Add(novoAnuncio); return(RedirectToAction("Index")); }
public HttpResponseMessage Post(AnuncioViewModel model) { var anuncio = Mapper.Map <Anuncio>(model); anuncio.DataCadastro = anuncio.DataAlteracao = DateTime.Now; foreach (var tag in model.Tags) { var dbTag = _anuncioRepository.BuscarTagPorPalavra(tag.Palavra); if (dbTag != null) { anuncio.Tags.Add(dbTag); } else { anuncio.Tags.Add(new Tag { Palavra = tag.Palavra }); } } anuncio.IdUsuario = User.Identity.GetUserId <int>(); if (model.DiasUteis) { anuncio.HoraInicialDiaUtil = TimeSpan.FromMinutes(model.DiaUtil[0]); anuncio.HoraFinalDiaUtil = TimeSpan.FromMinutes(model.DiaUtil[1]); } if (model.FinsDeSemanaEFeriados) { anuncio.HoraInicialFimDeSemanaEFeriado = TimeSpan.FromMinutes(model.FimDeSemanaFeriado[0]); anuncio.HoraFinalDeSemanaEFeriado = TimeSpan.FromMinutes(model.FimDeSemanaFeriado[1]); } if (model.BairroIds != null) { foreach (var bairroId in model.BairroIds) { var bairro = _anuncioRepository.BuscarBairroPorId(bairroId); anuncio.Bairros.Add(bairro); } } _anuncioRepository.Add(anuncio); return(Request.CreateResponse(HttpStatusCode.OK)); }
public static AnuncioViewModel MapearAnuncioViewModel(Anuncio anuncio) { var anuncioViewModel = new AnuncioViewModel() { Id = anuncio.Identity, Marca = anuncio.Marca, Modelo = anuncio.Modelo, Versao = anuncio.Versao, Ano = anuncio.Ano, Quilometragem = anuncio.Quilometragem, Observacao = anuncio.Observacao }; return(anuncioViewModel); }
public async Task <IActionResult> Criar(AnuncioViewModel anuncioViewModel) { if (!ModelState.IsValid) { await PreencherViewBags(); return(View(anuncioViewModel)); } var anuncio = AnuncioFactory.MapearAnuncio(anuncioViewModel); await _criarAnuncio.Executar(anuncio); return(RedirectToAction("Index")); }
public bool Atualizar(AnuncioViewModel anuncioViewModel) { var anuncio = new Anuncio { ID = anuncioViewModel.ID, Ano = anuncioViewModel.Ano, Marca = anuncioViewModel.Marca.Split('|')[1], Modelo = anuncioViewModel.Modelo.Split('|')[1], Observacao = anuncioViewModel.Observacao, Quilometragem = anuncioViewModel.Quilometragem, Versao = anuncioViewModel.Versao.Split('|')[1], }; return(_anuncioRepository.Atualizar(anuncio)); }