Beispiel #1
0
        // Returns a view to invite a user
        public ActionResult InviteUser(int id)
        {
            string userId = User.Identity.GetUserId();

            if (pservice.AuthorizeProject(userId, id))
            {
                var user = new ShareProjectViewModel();
                user.ProjectID = id;
                return(View(user));
            }

            return(View("Error"));
        }
Beispiel #2
0
        public ActionResult Share(int ID)
        {
            // If the user can't open the file an exception is thrown.
            if (!Pservice.CanUserOpenProject(ID, User.Identity.Name))
            {
                throw new ArgumentException();
            }
            // Initializing the ShareProjectViewModel.
            ShareProjectViewModel Model = new ShareProjectViewModel();

            Model.SharedWith   = UService.GetSharedUsersFromProject(ID);
            Model.ShareProject = Pservice.GetProjectFromID(ID);
            return(View(Model));
        }
Beispiel #3
0
        public void TestShareProject()
        {
            string userId    = "2";
            var    projectVM = new ShareProjectViewModel
            {
                ProjectID = 3,
                UserName  = "******"
            };

            pservice.ShareProject(projectVM);

            var result = pservice.GetSharedProjects(userId);

            Assert.AreEqual(2, result.Count);
        }
Beispiel #4
0
        // Shares the project with the user in the ShareProjectViewModel
        public void ShareProject(ShareProjectViewModel projectVM)
        {
            var userID = (from usr in _db.Users
                          where usr.UserName == projectVM.UserName
                          select usr.Id)
                         .SingleOrDefault();

            UsersInProject uip = new UsersInProject
            {
                ProjectID = projectVM.ProjectID,
                UserID    = userID
            };

            _db.UsersInProjects.Add(uip);
            _db.SaveChanges();
        }
Beispiel #5
0
        public ActionResult InviteUser(ShareProjectViewModel model)
        {
            string userId = User.Identity.GetUserId();

            if (!pservice.UserExists(model.UserName))
            {
                ModelState.AddModelError("UserName", "User does not exist.");
            }

            else
            {
                string newUserId = pservice.GetUserId(model.UserName);

                if (pservice.HasSharedAccess(newUserId, model.ProjectID))
                {
                    ModelState.AddModelError("UserName", "User already has access to this project.");
                }

                if (newUserId == userId)
                {
                    ModelState.AddModelError("UserName", "You cannot invite yourself to this project.");
                }

                if (pservice.IsOwner(newUserId, model.ProjectID))
                {
                    ModelState.AddModelError("UserName", "This user is the owner of the project.");
                }
            }

            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            pservice.ShareProject(model);
            return(RedirectToAction("ViewProject", new { id = model.ProjectID }));
        }