public UserDto AddResource(UserManipulationDto resource) { var userToCreate = new User() { Id = Guid.NewGuid(), FirstName = resource.FirstName, LastName = resource.LastName }; _context.Add(userToCreate); return(new UserDto() { Id = userToCreate.Id, FullName = userToCreate.FirstName + " " + userToCreate.LastName }); }
public async Task <IActionResult> Create(Item items) { if (ModelState.IsValid) { _context.Add(items); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(items)); }
public async Task <IActionResult> Add([Bind("Id,Title,Description,Status")] ToDoList.Models.SomeTask SomeTask) { if (ModelState.IsValid) { _context.Add(SomeTask); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(SomeTask)); }
public async Task <IActionResult> Create([Bind("Id,Description,DueDate,Complete,IdNetUsers")] TodoItem todoItem) { if (ModelState.IsValid) { _context.Add(todoItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } ViewData["IdNetUsers"] = new SelectList(_context.TodoItem, "Id", "Description", todoItem.IdNetUsers); return(View(todoItem)); }
public async Task <IActionResult> AjaxCreate([Bind("Id,Description")] ToDoItem toDoItem) { toDoItem.IsDone = false; if (ModelState.IsValid) { _context.Add(toDoItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(PartialView("ToDoItemsTable", GetToDoItems())); }
public IActionResult Create(Tarefa tarefa) { // verificando se o model está válido if (!ModelState.IsValid) { return(View(tarefa)); } // inserindo o registro _context.Add(tarefa); _context.SaveChanges(); return(RedirectToAction("Index")); }
public Task <ToDoTask> Add(ToDoTask toDoTaskToAdd) { return(Task.Run(() => { if (_toDoListContext != null) { _toDoListContext.Add(toDoTaskToAdd); _toDoListContext.SaveChanges(); return toDoTaskToAdd; } else { return null; } })); }
public async Task <ActionResult> Create(TodoList item) { var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; if (ModelState.IsValid) { item.UserId = userId; context.Add(item); await context.SaveChangesAsync(); TempData["Success"] = "The item has been added!"; return(RedirectToAction("Index")); } return(View(item)); }
public T Add(User source, T entity) { T toCreate = _context.Set <T>().CreateProxy(); _context.Entry(toCreate).CurrentValues.SetValues(entity); var tracked = _context.Add(toCreate); _context.SaveChanges(); var log = new DbLog(); log.ExecUserId = source.Id; log.Action = ACTION.ADD; this.Logging(log, tracked.Entity); return(tracked.Entity); }
public ItemDto AddResource(ItemManipulationDto resource, Guid id) { var createdItem = new Item() { Id = Guid.NewGuid(), Name = resource.Name, ListId = id, isCompleted = false, Completed = DateTimeOffset.MinValue }; _context.Add(createdItem); return(new ItemDto() { Id = createdItem.Id, Name = createdItem.Name, Status = createdItem.GetStatus() }); }
public ListDto AddResource(ListManipulationDto resource, Guid id) { var createdList = new List() { Id = Guid.NewGuid(), Name = resource.Name, UserId = id, Created = DateTimeOffset.UtcNow }; _context.Add(createdList); return(new ListDto() { Id = createdList.Id, Name = createdList.Name, AuthorId = createdList.UserId, Author = _context.Users.Where(u => u.Id == createdList.UserId).Select(name => name.FirstName + " " + name.LastName).FirstOrDefault(), ItemsLeftToComplete = 0, Items = new List <ItemDto>() }); }