public ActionResult Create(AnuncioViewModel anuncio) { if (ModelState.IsValid) { var anuncioDomain = _mapper.Map <AnuncioViewModel, Anuncio>(anuncio); _anuncioApp.Add(anuncioDomain); return(RedirectToAction("Index")); } return(View(anuncio)); }
public async Task <IActionResult> Add([FromBody] Anuncio anuncio) { try { anuncio = await _anuncioAppService.Add(anuncio); return(Ok(anuncio)); } catch (Exception ex) { return(BadRequest(ex.Message)); } }
// 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 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")); }