public async Task <T> AddAsync(T entity) { _dbContext.Set <T>().Add(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task <IActionResult> PutListItem([FromRoute] int id, [FromBody] ListItem listItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != listItem.Id) { return(BadRequest()); } _context.Entry(listItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ListItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <bool> Cancel(int id, bool status) { var task = await Get(id); task.Status = status; _toDoListDbContext.Tasks.Update(task); await _toDoListDbContext.SaveChangesAsync(); return(true); }
public async Task CreateAsync(Core.Domain.Task task) { try { var taskDbModel = _mapper.Map <Core.Domain.Task, TaskDbModel>(task); _context.Task.Add(taskDbModel); await _context.SaveChangesAsync(); } catch (Exception ex) { Debug.Print($"Błąd zapisu nowego zadania do bazy danych {ex}"); } }
public async Task <Item <Guid, string> > AddAsync(Item <Guid, string> item) { var entity = new ToDoItem { Title = item.Title, Color = item.Color, Completed = item.IsCompleted }; await _context.ToDoItems.AddAsync(entity); await _context.SaveChangesAsync(); item.Id = entity.Id; return(item); }
public async Task <Project> CreateNewProject(Project project) { project.NewId(); try { _context.Projects.Add(project); await _context.SaveChangesAsync(); } catch (Exception) { _logger.LogError($"Error on project adding to DB occoured. Client: {project.ClientEmail}"); return(null); } return(project); }
public async Task <IActionResult> DeleteConfirmed(Guid id) { var toDoItem = await _toDo.GetItem(id); await _toDo.DeleteAsync(toDoItem); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("ToDoItemID,UserEmail,Title,Description,AddedDate,DueDate,Done,DoneDate")] ToDoItem toDoItem) { if (ModelState.IsValid) { _context.Add(toDoItem); await _context.SaveChangesAsync(); toDoItem.UserEmail = User.Identity.Name; toDoItem.AddedDate = DateTime.Now.ToString(); toDoItem.DueDate = DateTime.Now.AddDays(1).ToString(); toDoItem.DoneDate = "Unknown"; await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(toDoItem)); }
public static async Task AddTestData(ToDoListDbContext context) { try { if (context.ToDos.Any()) { return; } context.ToDos.AddRange(GetTasks()); await context.SaveChangesAsync(); } catch (Exception ex) { Console.WriteLine(ex); } }
public async Task CreateToDoTask(ToDo toDo) { _context.Add(toDo); await _context.SaveChangesAsync(); }
public async Task Create(T entity) { await _dbContext.Set <T>().AddAsync(entity); await _dbContext.SaveChangesAsync(); }