public void NoteData(DbContextOptions <TodoApiContext> options) { using (var todocontext = new TodoApiContext(options)) { var note = new List <Note>() { new Note() { ID = 1, Title = "Boeing", PlainText = "Aerospace company", Pinned = false, CheckLists = new List <CheckList>() { new CheckList() { CheckListData = "Jumbo Jet", Status = true } }, Labels = new List <Label>() { new Label() { LabelData = "Dreamliner" } } }, new Note() { ID = 3, Title = "Boeings", PlainText = "Aerospace companys", Pinned = false, CheckLists = new List <CheckList>() { new CheckList() { CheckListData = "Jumbo Jets", Status = true } }, Labels = new List <Label>() { new Label() { LabelData = "Dreamliners" } } } }; todocontext.Note.AddRange(note); todocontext.SaveChanges(); } }
public TodoController(TodoApiContext context) { _context = context; if (_context.Tareas.Count() == 0) { // Create a new TodoItem if collection is empty, _context.Tareas.Add(new Tarea { Descripcion = "Item1" }); _context.SaveChanges(); } }
public TodoController(TodoApiContext context) { _context = context; if (_context.TodoItems.Count() == 0) { _context.TodoItems.Add(new TodoItem { Name = "Item1" }); _context.SaveChanges(); } }
private Todo create(object args) { Todo todo = this.Bind(); var connection = @"Server=localhost;Port=5432;User ID=postgres;Password=postgres;Database=nancy;"; var options = new DbContextOptionsBuilder <TodoApiContext>(); options.UseNpgsql(connection); using (var context = new TodoApiContext(options.Options)) { context.Add <Todo>(todo); context.SaveChanges(); } return(todo); }
public IHttpActionResult PostTodo(Todo todo) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var principal = User as ClaimsPrincipal; var owner = (from c in principal.Claims where c.Type == "hovland.name/Display name" select c.Value).FirstOrDefault(); todo.Owner = owner; db.Todos.Add(todo); db.SaveChanges(); return(CreatedAtRoute("DefaultApi", new { id = todo.TodoId }, todo)); }
public bool Add(TEntity obj) { _db.Set <TEntity>().Add(obj); return(_db.SaveChanges() > 0); }
public ActionResult <Tarea> PostTodoItem(Tarea item) { _context.Tareas.Add(item); _context.SaveChanges(); return(CreatedAtAction(nameof(GetTodoItem), new { id = item.Id }, item)); }