Beispiel #1
0
        private void RenderContentForTimer()
        {
            var participantId = Guid.Empty;

            if (!WebItemSecurity.IsProductAdministrator(EngineFactory.ProductId, SecurityContext.CurrentAccount.ID))
            {
                participantId = Participant.ID;
            }

            UserProjects = EngineFactory.ProjectEngine.GetOpenProjectsWithTasks(participantId);

            if (UserProjects.Any() && (Project == null || !UserProjects.Contains(Project)))
            {
                Project = UserProjects.First();
            }

            var tasks = EngineFactory.TaskEngine.GetByProject(Project.ID, null, Participant.IsVisitor ? participantId : Guid.Empty);

            OpenUserTasks   = tasks.Where(r => r.Status == TaskStatus.Open).OrderBy(r => r.Title);
            ClosedUserTasks = tasks.Where(r => r.Status == TaskStatus.Closed).OrderBy(r => r.Title);

            Users = EngineFactory.ProjectEngine.GetTeam(Project.ID).OrderBy(r => DisplayUserSettings.GetFullUserName(r.UserInfo)).Where(r => r.UserInfo.IsVisitor() != true).ToList();

            if (!string.IsNullOrEmpty(Request.QueryString["taskId"]))
            {
                Target = int.Parse(Request.QueryString["taskId"]);
            }
        }
Beispiel #2
0
        private void RenderContentForTimer()
        {
            var participantId = Guid.Empty;

            if (!WebItemSecurity.IsProductAdministrator(EngineFactory.ProductId, SecurityContext.CurrentAccount.ID))
            {
                participantId = Participant.ID;
            }

            UserProjects = EngineFactory.ProjectEngine.GetByFilter(new TaskFilter
            {
                ProjectStatuses = new List <ProjectStatus> {
                    ProjectStatus.Open
                },
                SortBy    = "title",
                SortOrder = true
            }).Where(r => r.TaskCountTotal > 0).ToList();

            if (UserProjects.Any() && (Project == null || !UserProjects.Contains(Project)))
            {
                Project = UserProjects.First();
            }

            var tasks = EngineFactory.TaskEngine.GetByProject(Project.ID, null, Participant.IsVisitor ? participantId : Guid.Empty).Where(r => ProjectSecurity.CanCreateTimeSpend(r)).ToList();

            OpenUserTasks   = tasks.Where(r => r.Status == TaskStatus.Open).OrderBy(r => r.Title);
            ClosedUserTasks = tasks.Where(r => r.Status == TaskStatus.Closed).OrderBy(r => r.Title);

            Users = EngineFactory.ProjectEngine.GetProjectTeamExcluded(Project.ID).OrderBy(r => DisplayUserSettings.GetFullUserName(r.UserInfo)).Where(r => !r.UserInfo.IsVisitor()).ToList();

            if (!string.IsNullOrEmpty(Request.QueryString["taskId"]))
            {
                Target = int.Parse(Request.QueryString["taskId"]);
            }
        }
Beispiel #3
0
        public ActionResult Invite(int projectID, string userName)
        {
            var fromUserName = _service.GetProjectByID(projectID).AppUser.UserName;
            var userID       = _service.getUserID(userName);

            if (userID == 0)
            {
                return(Json(new { success = "userNotFound", name = userName, projectID = projectID }));
            }

            var inv = new Invitation();

            inv.fromUserName = fromUserName;
            inv.AppUserID    = userID;
            inv.ProjectID    = projectID;

            var project = new UserProjects();

            project.AppUserID = userID;
            project.ProjectID = projectID;

            if (_service.ContainsInvitation(inv))
            {
                return(Json(new { success = "hasInvite", name = userName, projectID = projectID }));
            }
            else if (_service.HasUserProject(project))
            {
                return(Json(new { success = "hasProject", name = userName, projectID = projectID }));
            }
            else
            {
                _service.AddInvitation(inv);
                return(Json(new { success = true, name = userName, projectID = projectID }));
            }
        }
Beispiel #4
0
        private void RenderContentForTimer()
        {
            var participantId = Guid.Empty;

            if (!Participant.IsAdmin)
            {
                participantId = Participant.ID;
            }

            UserProjects = Global.EngineFactory.GetProjectEngine().GetOpenProjectsWithTasks(participantId);

            if (UserProjects.Any() && (Project == null || !UserProjects.Contains(Project)))
            {
                Project = UserProjects[0];
            }

            if (Project == null)
            {
                return;
            }

            var tasks = Global.EngineFactory.GetTaskEngine().GetByProject(Project.ID, null, Participant.IsVisitor ? participantId : Guid.Empty);

            OpenUserTasks   = tasks.Where(r => r.Status == TaskStatus.Open).OrderBy(r => r.Title);
            ClosedUserTasks = tasks.Where(r => r.Status == TaskStatus.Closed).OrderBy(r => r.Title);

            Users = Global.EngineFactory.GetProjectEngine().GetTeam(Project.ID).OrderBy(r => DisplayUserSettings.GetFullUserName(r.UserInfo)).Where(r => r.UserInfo.IsVisitor() != true).ToList();

            if (!string.IsNullOrEmpty(Request.QueryString["taskId"]))
            {
                Target = int.Parse(Request.QueryString["taskId"]);
            }
        }
Beispiel #5
0
        private void SetCurrentUser(Guid userID, Guid projectID)
        {
            if (!AuthorizedUsers.ContainsKeys(userID, projectID))
            {
                var authorized = UserProjects.Any(up => up.ProjectID == projectID && up.UserID == userID);
                if (authorized)
                {
                    AuthorizedUsers[userID, projectID] = DateTime.Now;
                }
            }
            //set current user

            if (AuthorizedUsers.ContainsKeys(userID, projectID))
            {
                CurrentUser = CurrentProject.UserProjects.Where(up => up.UserID == userID).Select(up => up.User).First();

                if (AuthorizedUsers[userID, projectID].AddHours(1) < DateTime.Now)
                {
                    AuthorizedUsers.Remove(userID, projectID);
                }
                return;
            }

            throw new UnauthorizedAccessException();
        }
        public ActionResult DeleteConfirmed(int id)
        {
            UserProjects userProjects = db.UserProjects.Find(id);

            db.UserProjects.Remove(userProjects);
            db.SaveChanges();
            return(RedirectToAction("Index"));
        }
        public bool HasUserProject(UserProjects userProject)
        {
            var result = (from up in Db.UserProjects
                          where up.AppUserID == userProject.AppUserID &&
                          up.ProjectID == userProject.ProjectID
                          select up).SingleOrDefault();

            return(!(result == null));
        }
Beispiel #8
0
        public async Task <bool> AddUserProject(Object obj)
        {
            UserProjects usp = (UserProjects)obj;

            await GetContext().AddAsync(usp);
            await GetContext().SaveChangesAsync();

            return(true);
        }
Beispiel #9
0
        public async Task <bool> Insert(Project project, UserProjects usp)
        {
            await GetContext().AddAsync(project);
            await GetContext().SaveChangesAsync();

            usp.ProjectId = project.Id;
            await GetContext().AddAsync(usp);
            await GetContext().SaveChangesAsync();

            return(true);
        }
Beispiel #10
0
        public async Task <bool> Decline(int id, int uid)
        {
            UserProjects usp = await GetContext().UserProjects
                               .FirstOrDefaultAsync(w => w.UserId == uid && w.ProjectId == id);

            GetContext().Remove(usp);

            await GetContext().SaveChangesAsync();

            return(true);
        }
 public ActionResult Edit([Bind(Include = "Id,UserId,ProjectId,IsActive")] UserProjects userProjects)
 {
     if (ModelState.IsValid)
     {
         db.Entry(userProjects).State = EntityState.Modified;
         db.SaveChanges();
         return(RedirectToAction("Index"));
     }
     ViewBag.ProjectId = new SelectList(db.Project, "Id", "Id", userProjects.ProjectId);
     ViewBag.UserId    = new SelectList(db.User, "Id", "FirstName", userProjects.UserId);
     return(View(userProjects));
 }
Beispiel #12
0
        public async Task <bool> Accept(int id, int uid)
        {
            UserProjects usp = await GetContext().UserProjects
                               .FirstOrDefaultAsync(w => w.UserId == uid && w.ProjectId == id);

            usp.IsAccept = true;
            GetContext().Update(usp);

            await GetContext().SaveChangesAsync();

            return(true);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            var currentUser = SecurityContext.CurrentAccount.ID;

            UserTasks = Global.EngineFactory.GetTaskEngine().GetByProject(ProjectFat.Project.ID, TaskStatus.Open, currentUser);
            var projects = Global.EngineFactory.GetProjectEngine().GetByParticipant(currentUser);

            UserProjects = projects.FindAll(p =>
                                            Global.EngineFactory.GetTaskEngine().GetByProject(p.ID, TaskStatus.Open, currentUser).Count > 0
                                            );
            UserTasks.Sort((x, y) => String.Compare(x.Title, y.Title));
            UserProjects.Sort((x, y) => String.Compare(x.Title, y.Title));
        }
        public void Initialize()
        {
            var mockContext = new MockDataContext();

            var user1 = new AppUser {
                ID       = 1,
                UserName = "******",
                Email    = "*****@*****.**"
            };

            mockContext.AppUsers.Add(user1);

            var user2 = new AppUser {
                ID       = 2,
                UserName = "******",
                Email    = "*****@*****.**"
            };

            mockContext.AppUsers.Add(user2);

            var user3 = new AppUser {
                ID       = 3,
                UserName = "******",
                Email    = "*****@*****.**"
            };

            mockContext.AppUsers.Add(user3);

            var project1 = new Project {
                ID          = 1,
                OwnerID     = 1,
                Name        = "Project1",
                DateCreated = new DateTime(2017, 1, 1),
                AppUser     = user1,
                ProjectType = "HTML"
            };

            mockContext.Projects.Add(project1);

            var userProject1 = new UserProjects {
                ID        = 1,
                AppUserID = 1,
                ProjectID = 1,
                AppUser   = user1,
                Project   = project1
            };

            mockContext.UserProjects.Add(userProject1);

            _AppUserService = new AppUserService(mockContext);
        }
Beispiel #15
0
        public async Task <bool> Request(int mateId, int projectId)
        {
            UserProjects usp = new UserProjects
            {
                UserId    = mateId,
                ProjectId = projectId,
                IsAccept  = false
            };

            await GetContext().AddAsync(usp);
            await GetContext().SaveChangesAsync();

            return(await MailManager.ProjectRequestMessage(GetContext().User.Find(mateId), GetContext().Project.Find(projectId)));
        }
        // GET: UserProjects/Details/5
        public ActionResult Details(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserProjects userProjects = db.UserProjects.Find(id);

            if (userProjects == null)
            {
                return(HttpNotFound());
            }
            return(View(userProjects));
        }
        public void TestHasUserProject()
        {
            // Arrange:
            var userProject1 = new UserProjects {
                ID        = 3,
                AppUserID = 2,
                ProjectID = 2
            };

            // Act:
            var isLinked = _ProjectService.HasUserProject(userProject1);

            // Assert:
            Assert.IsTrue(isLinked);
        }
        public bool AddProject(Project newProject)
        {
            Db.Projects.Add(newProject);
            Db.SaveChanges();
            UserProjects newLink      = new UserProjects();
            var          newProjectID = (from p in Db.Projects
                                         orderby p.ID descending
                                         select p.ID).FirstOrDefault();

            newLink.AppUserID = newProject.OwnerID;
            newLink.ProjectID = newProjectID;
            Db.UserProjects.Add(newLink);
            Db.SaveChanges();
            return(true);
        }
        // GET: UserProjects/Edit/5
        public ActionResult Edit(int?id)
        {
            if (id == null)
            {
                return(new HttpStatusCodeResult(HttpStatusCode.BadRequest));
            }
            UserProjects userProjects = db.UserProjects.Find(id);

            if (userProjects == null)
            {
                return(HttpNotFound());
            }
            ViewBag.ProjectId = new SelectList(db.Project, "Id", "Id", userProjects.ProjectId);
            ViewBag.UserId    = new SelectList(db.User, "Id", "FirstName", userProjects.UserId);
            return(View(userProjects));
        }
        public void TestAddUserToProject()
        {
            // Arrange:
            var userProject4 = new UserProjects {
                ID        = 4,
                AppUserID = 2,
                ProjectID = 1
            };

            // Act:
            var added    = _ProjectService.AddUserToProject(userProject4);
            var isLinked = _ProjectService.HasUserProject(userProject4);

            // Assert:
            Assert.IsTrue(added);
            Assert.IsTrue(isLinked);
        }
Beispiel #21
0
        public void UserConstructorAndPropertyGettersWork()
        {
            var validUserName    = "******";
            var validDisplayName = "display1";
            var validPassword    = UserValidationHelper.HashPassword("abc123");
            var validProjects    = new UserProjects(new[]
            {
                new BasicProject("id2", "name1"),
                new BasicProject("id3", "name2"),
            });

            var user = new User("id1", validUserName, validDisplayName, validPassword, validProjects);

            Assert.Equal(validUserName, user.UserName);
            Assert.Equal(validDisplayName, user.DisplayName);
            Assert.Equal(validPassword, user.PasswordHash);
        }
        /// <summary>
        /// Adds a new project to the project table and the UserProjects table for the supplied userId and project object
        /// </summary>
        /// <param name="project">An object of type Project that will be added to the db</param>
        /// <param name="userId">An integer representing UserId</param>
        /// <returns>An integer with the id of the added project</returns>
        public int AddProject(Project project, int userId)
        {
            // Add the project to the DB
            dbContext.Projects.Add(project);
            dbContext.SaveChanges();

            // Build a new UserProjects object to insert into the association table
            UserProjects userProject = new UserProjects();

            userProject.BTUserId = userId;

            // Project object will have the Id of the newly created project so use it to get Id
            userProject.ProjectId = project.ProjectId;
            dbContext.UserProjects.Add(userProject);
            dbContext.SaveChanges();

            return(project.ProjectId);
        }
Beispiel #23
0
        public ActionResult AcceptProject(int projectID)
        {
            var userID = _service.getUserID(User.Identity.GetUserName());

            var newUserProject = new UserProjects();

            newUserProject.AppUserID = userID;
            newUserProject.ProjectID = projectID;

            var invite = new Invitation();

            invite.AppUserID = userID;
            invite.ProjectID = projectID;

            if (_service.AddUserToProject(newUserProject) && _service.RemoveInvite(invite))
            {
                return(Json(new { success = true }));
            }
            return(Json(new { success = false }));
        }
Beispiel #24
0
        public HashSet <Guid> GetAttributeExclusions(Guid projectID)
        {
//            if (_prevFetchedProjectID == projectID)
//                return _attributeExclusions;

            var attributeExclusions =
                UserProjects.Where(
                    p =>
                    p.ProjectID == projectID &&
                    p.Group.GroupType.StartsWith("USER_", StringComparison.OrdinalIgnoreCase))
                .SelectMany(p => p.Group.Roles)
                .Where(r => r.Permission == false && r.ObjectType == Role.TaskObjectType.Attribute.ToString())
                .Select(r => r.ObjectID)
                .ToList()
                .ToHashSet();

            _prevFetchedProjectID = projectID;
            _attributeExclusions  = attributeExclusions;

            return(attributeExclusions);
        }
Beispiel #25
0
        public void UserConstructorArgumentValidationWorks()
        {
            var validUserName   = "******";
            var invalidUserName = new string('u', 51);

            var validDisplayName   = "display1";
            var invalidDisplayName = new string('d', 101);

            var validPassword    = UserValidationHelper.HashPassword("abc123");
            var invalidPassword1 = "abc123";
            var invalidPassword2 = new string('p', 33);

            var validProjects = new UserProjects(new[]
            {
                new BasicProject("id2", "name1"),
                new BasicProject("id3", "name2"),
            });
            var invalidProjects = new UserProjects(new[]
            {
                new BasicProject("id4", "name3"),
                new BasicProject("id5", "name3"),
            });

            Assert.Throws <ArgumentException>(() =>
                                              new User("id1", invalidUserName, validDisplayName, validPassword, validProjects));

            Assert.Throws <ArgumentException>(() =>
                                              new User("id1", validUserName, invalidDisplayName, validPassword, validProjects));

            Assert.Throws <ArgumentException>(() =>
                                              new User("id1", validUserName, validDisplayName, invalidPassword1, validProjects));

            Assert.Throws <ArgumentException>(() =>
                                              new User("id1", validUserName, validDisplayName, invalidPassword2, validProjects));

            Assert.Throws <ArgumentException>(() =>
                                              new User("id1", validUserName, validDisplayName, validPassword, invalidProjects));
        }
Beispiel #26
0
        public HashSet <Guid> GetTaxonomyExclusions(Guid projectID)
        {
            if (_prevFetchedProjectID == projectID)
            {
                return(_taxonomyExclusions);
            }

            var taxonomyExclusions =
                UserProjects.Where(
                    p =>
                    p.ProjectID == projectID &&
                    p.Group.GroupType.StartsWith("USER_", StringComparison.OrdinalIgnoreCase))
                .SelectMany(p => p.Group.Roles)
                .Where(r => r.Permission == false && r.ObjectType == Role.TaskObjectType.Sku.ToString())
                .Select(r => r.ObjectID)
                .ToList()
                .ToHashSet();

            _taxonomyExclusions   = taxonomyExclusions;
            _prevFetchedProjectID = projectID;

            return(taxonomyExclusions);
        }
        private async void LoadUserProjects()
        {
            UserManager userManager = (UserManager)dataService.GetUserManager();

            Dictionary <string, object> userDicoCharge = new Dictionary <string, object>
            {
                { "_token", AppStaticInfo.Account.Token }
            };
            List <Models.Project> projectList = await userManager.ChargeProjects(AppStaticInfo.Account.Uuid, null);

            if (projectList != null)
            {
                UserProjects = new ObservableCollection <Models.Project>(projectList);
            }
            Models.Project proj = new Models.Project()
            {
                Name        = "Last!!!",
                Description = "Desc",
                Uuid        = "ezf"
            };

            UserProjects.Add(proj);
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            CurrentUser = SecurityContext.CurrentAccount.ID;

            var filter = new TaskFilter
            {
                SortBy          = "title",
                SortOrder       = true,
                ProjectStatuses = new List <ProjectStatus> {
                    ProjectStatus.Open
                }
            };

            if (!ProjectSecurity.IsAdministrator(CurrentUser))
            {
                filter.ParticipantId = CurrentUser;
            }

            UserProjects = Global.EngineFactory.GetProjectEngine().GetByFilter(filter);

            if (UserProjects.Any() && (Project == null || !UserProjects.Contains(Project)))
            {
                Project = UserProjects[0];
            }

            var tasks = Global.EngineFactory.GetTaskEngine().GetByProject(Project.ID, null, Guid.Empty);

            OpenUserTasks   = tasks.Where(r => r.Status == TaskStatus.Open).OrderBy(r => r.Title);
            ClosedUserTasks = tasks.Where(r => r.Status == TaskStatus.Closed).OrderBy(r => r.Title);

            Users = Global.EngineFactory.GetProjectEngine().GetTeam(Project.ID).OrderBy(r => DisplayUserSettings.GetFullUserName(r.UserInfo)).ToList();

            if (!string.IsNullOrEmpty(Request.QueryString["taskId"]))
            {
                Target = int.Parse(Request.QueryString["taskId"]);
            }
        }
        public void TestAddUserToProject()
        {
            // Arrange:
            var user2 = new AppUser {
                ID       = 2,
                UserName = "******",
                Email    = "*****@*****.**"
            };

            var project2 = new Project {
                ID          = 2,
                OwnerID     = 2,
                Name        = "Project2",
                DateCreated = new DateTime(2017, 1, 1),
                AppUser     = user2,
                ProjectType = "HTML"
            };

            var userProject2 = new UserProjects {
                ID        = 2,
                AppUserID = 2,
                ProjectID = 2,
                AppUser   = user2,
                Project   = project2
            };

            // Act:
            _AppUserService.addUserToProject(userProject2);
            var AllUserProjects = _AppUserService.getAllUserProjects();

            // Assert:
            Assert.AreEqual(2, AllUserProjects.Count);
            Assert.AreEqual(2, AllUserProjects[1].ID);
            Assert.AreEqual(2, AllUserProjects[1].AppUserID);
            Assert.AreEqual(user2, AllUserProjects[1].AppUser);
            Assert.AreEqual(project2, AllUserProjects[1].Project);
        }
        public bool AddUserToProject(UserProjects newUserProject)
        {
            Db.UserProjects.Add(newUserProject);

            return(Db.SaveChanges() == 1);
        }
Beispiel #31
0
 private void Init()
 {
     Projects = new UserProjects(this, Caching.Enabled);
     ModuleAssignment = new UserModuleAssignment(this);
 }