public AcceptInvitationStatus AcceptProjectInvitation(int invitationID) { ProjectInvitation invitation = ProjectInvitations.Get(invitationID); if (invitation == null) { return(AcceptInvitationStatus.NoSuchInvitation); } if (invitation.TargetUserID != UserContext.AccountID) { return(AcceptInvitationStatus.NotTarget); } if (invitation.Type == ProjectInvitationType.Manager) { invitation.TargetProject.Managers.Add(invitation.TargetUser); } else if (invitation.Type == ProjectInvitationType.Reader) { invitation.TargetProject.Readers.Add(invitation.TargetUser); } else if (invitation.Type == ProjectInvitationType.Owner) { invitation.TargetProject.OwnerUserID = invitation.TargetUserID; } ActivityService.ProjectInvitationAccepted(invitation.ID); ProjectRepository.Update(invitation.TargetProject); ProjectInvitations.Delete(invitation); return(AcceptInvitationStatus.Accepted); }
public IQueryable <ProjectInvitation> GetCreatedProjectInvitations(int projectID) { if (!ProjectService.IsUserOwner(UserContext.AccountID)) { return(new List <ProjectInvitation>().AsQueryable()); } return(ProjectInvitations.Where(pi => pi.TargetProjectID == projectID)); }
public DeleteInvitationStatus DeleteProjectInvitation(int invitationID) { ProjectInvitation invitation = ProjectInvitations.Get(invitationID); if (invitation == null) { return(DeleteInvitationStatus.NoSuchInvitation); } if (invitation.TargetProject.OwnerUserID != UserContext.AccountID) { return(DeleteInvitationStatus.NotOwner); } ActivityService.ProjectInvitationDeleted(invitation.ID); ProjectInvitations.Delete(invitation); return(DeleteInvitationStatus.Deleted); }
public CreateInvitationStatus InviteToProject(int projectID, string accountPublicIdentifier, int type) { Project project = ProjectService.Get(projectID); if (project == null || !ProjectService.IsUserOwner(projectID)) { return(CreateInvitationStatus.NotOwner); } UserAccount account = UserService.GetByIdentifier(accountPublicIdentifier); if (account == null) { return(CreateInvitationStatus.NoSuchUser); } ProjectInvitation other = ProjectInvitations.FirstOrDefault(pi => pi.TargetProjectID == projectID && pi.TargetUserID == account.ID); if (other != null) { if (other.Type == type) { return(CreateInvitationStatus.AlreadyExists); } other.Type = type; ProjectInvitations.Update(other); return(CreateInvitationStatus.UpdatedExisting); } ProjectInvitation invitation = new ProjectInvitation { Created = DateTime.Now, TargetProjectID = projectID, TargetUserID = account.ID, OwnerUserID = project.OwnerUserID, Type = type }; ProjectInvitations.Insert(invitation); ActivityService.ProjectInvitationCreated(invitation.ID); return(CreateInvitationStatus.Created); }
public IQueryable <ProjectInvitation> GetProjectInvitations() { return(ProjectInvitations.Where(pi => pi.TargetUserID == UserContext.AccountID)); }