public async Task <ActionResult> NovoOuEditar([Bind("CategoriaNome,CategoriaFotoUrl,Id,CreateAt,UpdateAt")] CategoriaDTOCreate categoria) { try { if (ModelState.IsValid) { if (categoria.Id == 0) { await _serService.Post(categoria); } else { var usr = _mapper.Map <CategoriaDTO>(categoria); var u = _mapper.Map <CategoriaDTOUpdate>(usr); await _serService.Put(u); } return(RedirectToAction(nameof(Index))); } return(RedirectToAction(nameof(Index))); } catch { return(View()); } }
public async Task <ActionResult> Post([FromBody] CategoriaDTOCreate user) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); //400 bad request - solicitaçao invalidos } try { var result = await _service.Post(user); if (result != null) { //return Created(new Uri(Url.Link("GetById", new { id = result.Id })), result); return(CreatedAtAction(nameof(Get), new { id = result.Id }, result)); } else { return(BadRequest()); } } catch (ArgumentException e) { return(StatusCode((int)HttpStatusCode.InternalServerError, e.Message)); } }
public CategoriaDTOCreateResult Add(CategoriaDTOCreate categoria) { var model = _mapper.Map <CategoriaModel>(categoria); var entity = _mapper.Map <CategoriaEntity>(model); var result = _repository.Insert(entity); return(_mapper.Map <CategoriaDTOCreateResult>(result)); }
public async Task <CategoriaDTOCreateResult> Post(CategoriaDTOCreate categoria) { var model = _mapper.Map <CategoriaModel>(categoria); var entity = _mapper.Map <CategoriaEntity>(model); var result = await _repository.InsertAsync(entity); return(_mapper.Map <CategoriaDTOCreateResult>(result)); }