public virtual async Task <T> AddAsync(T entity) { _dbContext.Set <T>().Add(entity); await _dbContext.SaveChangesAsync(); return(entity); }
public async Task EnsureSeedData() { _context.Database.EnsureCreated(); _context.Tasks.RemoveRange(_context.Tasks); _context.SaveChanges(); var task = new TaskEntity { Title = "Read a book", TaskDetails = "Read Sadguru books" }; _context.Add(task); var task2 = new TaskEntity { Title = "Go to temple", TaskDetails = "Go to temple" }; _context.Add(task2); await _context.SaveChangesAsync(); }
public async System.Threading.Tasks.Task DeleteUser(int id) { using (var taskManagerDbContext = new TaskManagerDbContext()) { var deletedUser = await GetUserById(id); taskManagerDbContext.Users.Remove(deletedUser); await taskManagerDbContext.SaveChangesAsync(); } }
public async Task <User> UpdateUser(User user) { using (var taskManagerDbContext = new TaskManagerDbContext()) { taskManagerDbContext.Users.Update(user); await taskManagerDbContext.SaveChangesAsync(); return(user); } }
public async System.Threading.Tasks.Task DeleteTask(int id) { using (var taskManagerDbContext = new TaskManagerDbContext()) { var deletedTask = await GetTaskById(id); taskManagerDbContext.Tasks.Remove(deletedTask); await taskManagerDbContext.SaveChangesAsync(); } }
public async System.Threading.Tasks.Task <Task> UpdateTask(Task task) { using (var taskManagerDbContext = new TaskManagerDbContext()) { taskManagerDbContext.Tasks.Update(task); await taskManagerDbContext.SaveChangesAsync(); return(task); } }
public async Task <IActionResult> Create(Task task) { if (ModelState.IsValid) { task.Id = 0; task.DateOfRegistration = DateTime.Now; task.TaskStatus = TaskStatus.Appointed; _context.Add(task); await _context.SaveChangesAsync(); } return(RedirectToAction("Index", new { selectedTaskId = task.Id })); }
public async Task <IActionResult> Post([FromBody] RegistrationViewModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var userIdentity = _mapper.Map <AppUser>(model); var result = await _userManager.CreateAsync(userIdentity, model.Password); if (!result.Succeeded) { return(new BadRequestObjectResult(Errors.AddErrorsToModelState(result, ModelState))); } await _taskManagerContext.Customers.AddAsync(new Customer { IdentityId = userIdentity.Id }); await _taskManagerContext.SaveChangesAsync(); return(new OkObjectResult("Account created")); }
public Task <int> Save() => _context.SaveChangesAsync();
public async Task <bool> SaveChangesAsync() { return(await _context.SaveChangesAsync() >= 0); }
public async Task Add(T entity) { _context.Set <T>().Add(entity); await _context.SaveChangesAsync(); }