コード例 #1
0
        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();
                    }
                }
            }
        }
コード例 #2
0
        public Team search(int id)
        {
            var db       = new EntityFrameworkContext();
            var original = db.TeamList.Find(id);

            return(original);
        }
コード例 #3
0
        public AppUser getUser(string userId)
        {
            var db = new EntityFrameworkContext();

            AppUser userQuery = db.Users.Find(userId);

            return(userQuery);
        }
コード例 #4
0
        public void Add(Task task)
        {
            var db = new EntityFrameworkContext();

            task.CreatedAt = DateTime.Now;
            task.UpdatedAt = DateTime.Now;
            db.TaskList.Add(task);
            db.SaveChanges();
        }
コード例 #5
0
        public Task Search(int id)
        {
            var db        = new EntityFrameworkContext();
            var taskQuery = (from task in db.TaskList.Include("comments")//am inclus comentariile, aduce doar primitive
                             where task.Id == id
                             select task).FirstOrDefault();

            return(taskQuery);
        }
コード例 #6
0
        public Comment Search(int id)
        {
            var db   = new EntityFrameworkContext();
            var find = (from comment in db.CommentList
                        where comment.Id == id
                        select comment).FirstOrDefault();

            return(find);
        }
コード例 #7
0
        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();
            }
        }
コード例 #8
0
        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();
        }
コード例 #9
0
        public void DeleteComments(int taskId)
        {
            var db           = new EntityFrameworkContext();
            var commentsList = (from comment in db.CommentList
                                where comment.TaskId == taskId
                                select comment).ToList();

            foreach (var c in commentsList)
            {
                Delete(c.Id);
            }
        }
コード例 #10
0
        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();
            }
        }
コード例 #11
0
        public List <Task> getAll(int?teamId)
        {
            if (teamId == null)
            {
                return(new List <Task>());
            }
            var         db   = new EntityFrameworkContext();
            List <Task> list = (from task in db.TaskList
                                where task.TeamId == teamId
                                select task).ToList();

            return(list);
        }
コード例 #12
0
        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();
            }
        }
コード例 #13
0
        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);
        }
コード例 #14
0
        public List <Comment> getAll(int taskId)
        {
            TaskRepository taskRepository = TaskRepository.getInstance();
            var            task           = taskRepository.Search(taskId);

            if (task == null)
            {
                return(null);
            }

            var db       = new EntityFrameworkContext();
            var comments = (from comment in db.CommentList
                            where comment.TaskId == taskId
                            select comment).ToList();

            return(comments);
        }
コード例 #15
0
        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();
        }
コード例 #16
0
        public Team getTeamForUser(string userId)
        {
            UserRepository userRepository = UserRepository.getInstance();
            var            user           = userRepository.getUser(userId);

            if (user.TeamId == null)
            {
                return(null);
            }
            else
            {
                var db        = new EntityFrameworkContext();
                var teamQuery = (from team in db.TeamList.Include("TeamMembers")
                                 where team.Id == user.TeamId
                                 select team).FirstOrDefault();
                var teamLeaderUser = db.Users.Find(teamQuery.TeamLeaderUserId);
                teamQuery.TeamLeaderEmail = teamLeaderUser.UserName;
                return(teamQuery);
            }
        }