コード例 #1
0
 public HttpResponseMessage Post([FromBody] Tarefa t)
 {
     if (ModelState.IsValid)
     {
         using (TarefaModel model = new TarefaModel())
         {
             t.Data = DateTime.Now;
             model.Create(t);
             return(Request.CreateResponse(HttpStatusCode.OK, "Cadastrado com sucesso"));
         }
     }
     else
     {
         return(Request.CreateResponse(HttpStatusCode.PreconditionFailed, ModelState.Values));
     }
 }
コード例 #2
0
        public ActionResult Create(Tarefa t)
        {
            if (ModelState.IsValid)
            {
                t.Concluida = false;
                t.Data      = DateTime.Now;

                using (TarefaModel model = new TarefaModel())
                {
                    model.Create(t);
                    return(RedirectToAction("Index"));
                }
            }
            else
            {
                ViewBag.Erro = "Preencha a descrição da tarefa.";
                return(View());
            }
        }