public void create(string userId, Team team) { EntityFrameworkContext db; using (db = new EntityFrameworkContext()) { using (var dbContextTransaction = db.Database.BeginTransaction()) { try { team.TeamLeaderUserId = userId; db.TeamList.Add(team); db.SaveChanges(); var user = db.Users.Find(userId); user.TeamId = team.Id; db.SaveChanges(); dbContextTransaction.Commit(); } catch (Exception) { dbContextTransaction.Rollback(); } } } }
public void Add(Task task) { var db = new EntityFrameworkContext(); task.CreatedAt = DateTime.Now; task.UpdatedAt = DateTime.Now; db.TaskList.Add(task); db.SaveChanges(); }
public void edit(Team updatedTeam) { var db = new EntityFrameworkContext(); var original = db.TeamList.Find(updatedTeam.Id); if (original != null) { db.Entry(original).CurrentValues.SetValues(updatedTeam); db.SaveChanges(); } }
public void Delete(int id) { var db = new EntityFrameworkContext(); Comment comment = new Comment { Id = id }; db.CommentList.Attach(comment); db.CommentList.Remove(comment); db.SaveChanges(); }
public void Edit(int id, Task updatedTask) { var db = new EntityFrameworkContext(); var original = db.TaskList.Find(id); if (original != null) { updatedTask.CreatedAt = original.CreatedAt; updatedTask.UpdatedAt = DateTime.Now; db.Entry(original).CurrentValues.SetValues(updatedTask); db.SaveChanges(); } }
public void Edit(int id, Comment updatedComment) { var db = new EntityFrameworkContext(); var original = db.CommentList.Find(id); if (original != null) { updatedComment.PostedAt = original.PostedAt; updatedComment.UpdatedAt = DateTime.Now; db.Entry(original).CurrentValues.SetValues(updatedComment); db.SaveChanges(); } }
public void Delete(int id) { var db = new EntityFrameworkContext(); Task task = new Task { Id = id }; db.TaskList.Attach(task); db.TaskList.Remove(task); db.SaveChanges(); CommentRepository commentRepository = CommentRepository.getInstance(); commentRepository.DeleteComments(id); }
public void Add(Comment comment, int taskId) { TaskRepository taskRepository = TaskRepository.getInstance(); var task = taskRepository.Search(taskId); if (task == null) { return; } comment.PostedAt = DateTime.Now; comment.UpdatedAt = DateTime.Now; comment.TaskId = taskId; var db = new EntityFrameworkContext(); db.CommentList.Add(comment); db.SaveChanges(); }