Ejemplo n.º 1
0
        public async Task <ActionResult <Categoria> > Post([FromBody] JObject postModel)
        {
            if (postModel == null)
            {
                return(BadRequest());
            }

            Postagem model = new Postagem()
            {
                UsuarioCodigo = postModel.GetValue("UsuarioCodigo").Value <int>(),
                DataCriacao   = DateTime.Now,
                Titulo        = postModel.GetValue("Titulo").Value <string>(),
                Subtitulo     = postModel.GetValue("Subtitulo").Value <string>(),
                Resumo        = postModel.GetValue("Resumo").Value <string>(),
                Conteudo      = postModel.GetValue("Conteudo").Value <string>(),
                DataInicial   = new DateTime(2019, 05, 1),
                DataFinal     = new DateTime(2019, 12, 31),
                Status        = 1
            };

            _context.Postagem.Add(model);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { codigo = model.Codigo }, model));
        }
Ejemplo n.º 2
0
        public async Task <T> AddAsync(T entity)
        {
            await this._entity.AddAsync(entity);

            await _context.SaveChangesAsync();

            return(entity);
        }
Ejemplo n.º 3
0
        public virtual async Task <T> AddAsync(T entity, bool save = true)
        {
            _entity.Add(entity);

            if (save)
            {
                await _context.SaveChangesAsync();
            }

            return(entity);
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Categoria> > Post([FromBody] JObject postModel)
        {
            if (postModel == null)
            {
                return(BadRequest());
            }

            Categoria model = new Categoria()
            {
                Nome      = postModel.GetValue("Nome").Value <string>(),
                Descricao = postModel.GetValue("Descricao").Value <string>()
            };

            _context.Categoria.Add(model);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(Get), new { codigo = model.Codigo }, model));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Add()
        {
            Categoria categoria = new Categoria()
            {
                Nome      = "Artesenato",
                Descricao = "Para se fazer em casa"
            };

            _context.Add(categoria);
            await _context.SaveChangesAsync();

            return(View(await _context.Categoria.ToListAsync()));
        }