public async Task <User> Update(User user) { using (var ctx = new BugTrackingContext()) { _logger.Debug("Update(). Updating user: {0}.", user.UserLogin); ctx.Entry(user).State = EntityState.Modified; await ctx.SaveChangesAsync(); } _logger.Debug("Update(). User {0} have updated.", user.UserLogin); return(user); }
public async Task <Project> Update(Project project) { using (var ctx = new BugTrackingContext()) { _logger.Debug("Update(). Updating Project: {0}.", project.Name); ctx.Entry(project).State = EntityState.Modified; await ctx.SaveChangesAsync(); } _logger.Debug("Update(). Project {0} have updated.", project.Name); return(project); }
public async Task Delete(int id) { using (var ctx = new BugTrackingContext()) { _logger.Debug("Delete(). Deleting user by id: {0}.", id); var user = await ctx.Users.FirstOrDefaultAsync(p => p.Id == id); ctx.Entry(user).State = EntityState.Deleted; var a = await ctx.SaveChangesAsync(); } _logger.Debug("Delete(). User deleted by id: {0}.", id); }
public async Task Delete(int id) { using (var ctx = new BugTrackingContext()) { _logger.Debug("Delete(). Deleting project by id: {0}.", id); var project = await ctx.Projects.FirstOrDefaultAsync(p => p.Id == id); ctx.Entry(project).State = EntityState.Deleted; await ctx.SaveChangesAsync(); _logger.Debug("Delete(). Project deleted by id: {0}.", id); } }
public async Task <UsersTask> Update(UsersTask usersTask) { using (var ctx = new BugTrackingContext()) { _logger.Debug("Update(). Updating task: {0}.", usersTask.Topic); ctx.Entry(usersTask).State = EntityState.Modified; await ctx.SaveChangesAsync(); _logger.Debug("Update(). Task {0} have updated.", usersTask.Topic); } return(usersTask); }
public async Task <IActionResult> PutTaskItem([FromRoute] int id, [FromBody] TaskItem taskItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != taskItem.TaskId) { return(BadRequest()); } var _taskItem = await _context.TaskItem.FindAsync(id); if (_taskItem == null) { return(NotFound()); } if (_taskItem.TaskStatus == Enums.TaskStatus.Closed) { return(BadRequest()); } _taskItem.TaskName = taskItem.TaskName; _taskItem.TaskDescription = taskItem.TaskDescription; _taskItem.TaskPriority = taskItem.TaskPriority; _taskItem.TaskStatus = taskItem.TaskStatus; _taskItem.TaskDateUpdated = DateTime.Now; _context.Entry(_taskItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!TaskItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutProjectItem([FromRoute] int id, [FromBody] ProjectItem projectItem) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != projectItem.ProjectId) { return(BadRequest()); } var _projectItem = await _context.ProjectItems.FindAsync(id); if (_projectItem == null) { return(NotFound()); } _projectItem.ProjectName = projectItem.ProjectName; _projectItem.ProjectDescription = projectItem.ProjectDescription; _projectItem.ProjectDateUpdated = DateTime.Now; _context.Entry(_projectItem).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ProjectItemExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }