예제 #1
0
        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));
            }
        }
예제 #3
0
 // 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"));
        }