Exemplo n.º 1
0
        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());
            }
        }
Exemplo n.º 2
0
        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));
            }
        }
Exemplo n.º 3
0
        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));
        }
Exemplo n.º 4
0
        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));
        }