public VMProject(Project p, int userId)
        {
            Title = p.Title;
            Description = p.Description;
            Collaborators = new List<VMContribution>();
            if (p.Contributions != null && p.Contributions.Count > 0)
            {
                foreach (Contribution c in p.Contributions)
                {
                    Collaborators.Add(new VMContribution(c));
                }
            }
            Media = new List<VMProjectMedium>();
            if (p.ProjectMedia != null && p.ProjectMedia.Count > 0)
            {
                foreach (ProjectMedium u in p.ProjectMedia)
                {
                    Media.Add(new VMProjectMedium(u));
                }
            }
            Template = (ProjectTemplate)p.Template;
            Id = p.Id;
            currentUserId = userId;
            if (p.Contributions != null && p.Contributions.Count > 0)
            {
                if(p.Contributions.Any(c => c.UserId == userId))
                {
                    PersonalContribution = new VMContribution(p.Contributions.FirstOrDefault(c => c.UserId == userId));
                }
            }
            ProjectMasterIds = new List<int>();
            ProjectEditorIds = new List<int>();
            if(p.ProjectPermissions !=null && p.ProjectPermissions.Count>0)
            {
                foreach (ProjectPermission pm in p.ProjectPermissions)
                {
                    if (pm.IsProjectEditor)
                    {
                        ProjectEditorIds.Add(pm.UserId);
                    }
                    if (pm.IsProjectMaster)
                    {
                        ProjectMasterIds.Add(pm.UserId);
                    }
                }
            }

            ContributionSetting = (ContributionSetting)p.CollaborationSetting;
        }
        public VMEditingProject(Project p, IEnumerable<User> quickContacts, int currentUserId)
        {
            Title = p.Title;
            Description = p.Description;
            Media = new List<VMProjectMedium>();
            if (p.ProjectMedia != null && p.ProjectMedia.Count > 0)
            {
                foreach (ProjectMedium u in p.ProjectMedia)
                {
                    Media.Add(new VMProjectMedium(u));
                }
            }
            EditingCollaborators = new VMEditingCollaborators(p.Contributions, quickContacts);
            Template = (ProjectTemplate)p.Template;
            ContributionSetting = (ContributionSetting)p.CollaborationSetting;

            Id = p.Id;
            _currentUserId = currentUserId;
            if (p.Contributions != null && p.Contributions.FirstOrDefault(c => c.UserId == _currentUserId) != null)
            {
                PersonalContribution = new VMContribution(p.Contributions.FirstOrDefault(c => c.UserId == _currentUserId));
            }
            else
            {
                PersonalContribution = new VMContribution();
            }
            ProjectEditorIds = new List<int>();
            ProjectMasterIds = new List<int>();
            if (p.ProjectPermissions != null && p.ProjectPermissions.Count > 0)
            {
                foreach (ProjectPermission pm in p.ProjectPermissions)
                {
                    if (pm.IsProjectEditor)
                    {
                        ProjectEditorIds.Add(pm.UserId);
                    }
                    if (pm.IsProjectMaster)
                    {
                        ProjectMasterIds.Add(pm.UserId);
                    }
                }
            }
        }
 public VMManagingCollaborator(VMContribution contribution, bool collaboratorIsProjectEditor, bool collaboratorIsProjectMaster, bool userIsProjectMaster)
 {
     if (!string.IsNullOrEmpty(contribution.Name))
     {
         UserName = contribution.Name;
     }
     CollaboratorIsProjectEditor = collaboratorIsProjectEditor;
     CollaboratorIsProjectMaster = collaboratorIsProjectMaster;
     UserIsProjectMaster = userIsProjectMaster;
     UserId = contribution.UserId;
     if (!string.IsNullOrEmpty(contribution.Title))
     {
         Title = contribution.Title;
     }
     if (!string.IsNullOrEmpty(contribution.Description))
     {
         int length = (contribution.Description.Length >= 150)? 150: contribution.Description.Length;
         DescriptionShort = contribution.Description.Substring(0, length) + "...";
     }
     ProjectId = contribution.ProjectId;
 }
 public ActionResult NewCollaboratorEntry()
 {
     var contribution = new VMContribution();
     return View("Partial/FormEntry/_NewCollaboratorEntry", contribution);
 }
        public ActionResult EditContribution(VMContribution model)
        {
            int projectId = int.Parse(Request.Form["ProjectId"]);
            int userId = int.Parse(Request.Form["UserId"]);

            Contribution contribution = new Contribution();
            if (PersonalContributionVerified(out contribution, userId))
            {
                contribution.UserId = userId;
                contribution.ProjectId = projectId;
                if (db.retrieveProject(projectId).Contributions.Any(c => c.UserId == userId && c.ProjectId == projectId))
                {
                    db.updateContribution(contribution, projectId);
                    if (contribution.ContributionMedia != null && contribution.ContributionMedia.Count > 0)
                    {
                        foreach (ContributionMedium cm in contribution.ContributionMedia)
                        {
                            if (db.retrieveContribution(userId, projectId).ContributionMedia.Any(m => m.Id == cm.Id))
                            {
                                if (string.IsNullOrEmpty(cm.Caption) && string.IsNullOrEmpty(cm.Link))
                                {
                                    db.removeContributionMedium(cm);
                                }
                                else
                                {
                                    db.updateContributionMedium(cm);
                                }
                            }
                            else
                            {
                                db.addContributionMedium(cm, userId, projectId);
                            }
                        }
                    }
                }
                else
                {
                    db.addContribution(contribution, projectId);
                }

                return RedirectToAction("ProjectCatalog", routeValues: new { id = userId });
            }
            contribution.UserId = userId;
            contribution.ProjectId = projectId;
            VMContribution contrib = new VMContribution(contribution);
            return View(contrib);
        }
 public ActionResult EditContribution(int projectId, int userId)
 {
     #region route data validation
     if (RouteData.Values["projectId"] != null)
     {
         if (int.TryParse(RouteData.Values["projectId"].ToString(), out projectId)) { }
     }
     Project project;
     if (projectId != -1)
     {
         project = db.retrieveProject(projectId);
         if (project == null)
         {
             string error1 = "The Project, the contribution to which you tried to edit, either does not exist or could not be found.";
             string error2 = "Project Id: " + projectId;
             TempData["ErrorMessages"] = new string[] { error1, error2 };
             return RedirectToAction("Http404", "Error");
         }
     }
     else
     {
         string error1 = "A project Id is required to edit a project contribution.";
         TempData["ErrorMessages"] = new string[] { error1 };
         return RedirectToAction("Http404", "Error");
     }
     if (RouteData.Values["userId"] != null)
     {
         if (int.TryParse(RouteData.Values["userId"].ToString(), out userId)) { }
     }
     PortfolioUnleashed.User user;
     if (userId != -1)
     {
         user = db.retrieveUser(userId);
         if (user == null)
         {
             string error1 = "The User whose project contribution you tried to edit either does not exist or could not be found.";
             string error2 = "User Id: " + userId;
             TempData["ErrorMessages"] = new string[] { error1, error2 };
             return RedirectToAction("Http404", "Error");
         }
     }
     else
     {
         string error1 = "A User Id is required to edit a User's contribution.";
         TempData["ErrorMessages"] = new string[] { error1 };
         return RedirectToAction("Http404", "Error");
     }
     #endregion
     VMProject vmProj = new VMProject(project, userId);
     VMContribution vmCon = new VMContribution();
     if (vmProj.PersonalContribution != null)
     {
         vmCon = vmProj.PersonalContribution;
     }
     else
     {
         vmCon = new VMContribution(new Contribution() { UserId = userId, ProjectId = projectId });
     }
     ViewBag.ProjectTitle = vmProj.Title;
     return View(model: vmCon);
 }