예제 #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);
        }
        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();
            }
        }
        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 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);
        }
        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);
        }
        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);
        }
        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);
            }
        }