Exemplo n.º 1
0
        public static MemberModel MapProjectMemberView(ProjectMemberView pmv)
        {
            var memberModel = new MemberModel
            {
                Id           = pmv.ProjectMemberId,
                UserId       = pmv.UserId,
                Email        = pmv.UserEmail,
                Municipality = pmv.County,
                Name         = pmv.UserName,
                ProjectId    = pmv.ProjectId,
                Domain       = pmv.Domain,
                Organization = pmv.Organization
            };

            memberModel.MemberRoles = new List <RoleModel>();
            foreach (ProjectRoleView roleView in pmv.ProjectRoles)
            {
                memberModel.MemberRoles.Add(MapProjectRoleView(roleView));
            }
            return(ObjectTextTrim.TrimStringProperties(memberModel));
        }
Exemplo n.º 2
0
        public MemberModel CreateProjectMember(MemberModel memberModel)
        {
            // Mapp to backend model
            var member = new ProjectMember();

            if (memberModel != null)
            {
                member = ApplicationMapper.MapProjectMember(memberModel);
            }
            // Create P.Member
            bool memberExists;
            bool userExists;
            ProjectMemberView pmv = projectRepository.CreateProjectMember(member, out memberExists, out userExists);

            //If the member is a new member
            if (!userExists)
            {
                if (!string.IsNullOrEmpty(pmv.UserEmail))
                {
                    ITextReplace replace = new TextReplace();
                    //replace.Add("%name%", pmv.UserName);
                    replace.Add("%username%", pmv.UserEmail.Trim());
                    string body = replace.ReplaceFromFile(Path.Combine(AppDomain.CurrentDomain.BaseDirectory, "Templates", "NewUser.html"));
                    // TODO replace with setting
                    MailService smtp   = new MailService("http://communicationservice.woxion.com/MailService.asmx");
                    bool        result = smtp.Send("Projektplaneraren", "*****@*****.**", pmv.UserEmail.Trim(), null, "Projektplaneraren", body);
                }
                else
                {
                    throw new Exception("Could not send new member email. Email is null or empty.");
                }
            }

            MemberModel createMemberModel = ApplicationMapper.MapProjectMemberView(pmv);

            createMemberModel.memberExists = memberExists;
            createMemberModel.MemberRoles  = memberModel.MemberRoles;
            return(createMemberModel);
        }
Exemplo n.º 3
0
        public Project GetProjectForPublish(int id)
        {
            using (SqlConnection conn = SqlHelper.GetOpenConnection())
            {
                using (var multi = conn.QueryMultiple("GetProject", new { ProjectId = id }, commandType: CommandType.StoredProcedure))
                {
                    //var project = multi.Read<Project>().FirstOrDefault();

                    var project = multi.Read <Project, Organization, UserView, Program, Project>((p, o, uv, program) =>
                    {
                        p.Organization = o;
                        p.User         = uv;
                        p.Program      = program;
                        return(p);
                    }).FirstOrDefault();

                    var projectActivities = multi.Read <ProjectActivity>();
                    var projectFollowUps  = multi.Read <ProjectFollowUp>();
                    var projectGoals      = multi.Read <ProjectGoal>();
                    var projectMembers    = multi.Read <ProjectMemberView>();
                    var projectRoles      = multi.Read <ProjectRoleView>();
                    var projectRisks      = multi.Read <ProjectRisk>();

                    if (project == null)
                    {
                        return(null);
                    }

                    if (projectActivities.Any())
                    {
                        project.ProjectActivities = projectActivities.ToList();
                    }

                    if (projectFollowUps.Any())
                    {
                        project.ProjectFollowUps = projectFollowUps.ToList();
                    }

                    if (projectGoals.Any())
                    {
                        project.ProjectGoals = projectGoals.ToList();
                    }

                    var projectMemberViews = projectMembers as List <ProjectMemberView> ?? projectMembers.ToList();
                    if (projectMemberViews.Any())
                    {
                        project.ProjectMembers = projectMemberViews;
                    }

                    // add member roles
                    var projectRoleView = projectRoles as List <ProjectRoleView> ?? projectRoles.ToList();
                    foreach (var member in project.ProjectMembers)
                    {
                        ProjectMemberView memberCopy = member;
                        foreach (var roleView in projectRoleView.Where(roleView => memberCopy.UserId == roleView.UserId))
                        {
                            member.ProjectRoles.Add(roleView);
                        }
                    }

                    if (projectRisks.Any())
                    {
                        project.ProjectRisks = projectRisks.ToList();
                    }

                    return(project);
                }
            }
        }
Exemplo n.º 4
0
        public Project GetProject(int id)
        {
            using (SqlConnection conn = SqlHelper.GetOpenConnection())
            {
                using (var multi = conn.QueryMultiple("GetProject", new { ProjectId = id }, commandType: CommandType.StoredProcedure))
                {
                    //var project = multi.Read<Project>().FirstOrDefault();

                    var project = multi.Read <Project, Organization, UserView, Program, Project>((p, o, uv, program) =>
                    {
                        p.Organization = o;
                        p.User         = uv;
                        p.Program      = program;
                        return(p);
                    }).FirstOrDefault();

                    var projectActivities = multi.Read <ProjectActivity>();
                    var projectFollowUps  = multi.Read <ProjectFollowUp>();
                    var projectGoals      = multi.Read <ProjectGoal>();
                    var projectMembers    = multi.Read <ProjectMemberView>();
                    var projectRoles      = multi.Read <ProjectRoleView>();
                    var projectRisks      = multi.Read <ProjectRisk>();

                    if (project == null)
                    {
                        return(null);
                    }

                    if (projectActivities.Any())
                    {
                        project.ProjectActivities = projectActivities.ToList();
                    }

                    if (projectFollowUps.Any())
                    {
                        project.ProjectFollowUps = projectFollowUps.ToList();
                    }

                    if (projectGoals.Any())
                    {
                        project.ProjectGoals = projectGoals.ToList();
                    }

                    var projectMemberViews = projectMembers as List <ProjectMemberView> ?? projectMembers.ToList();
                    if (projectMemberViews.Any())
                    {
                        project.ProjectMembers = projectMemberViews;
                    }

                    // add member roles
                    var projectRoleView = projectRoles as List <ProjectRoleView> ?? projectRoles.ToList();
                    foreach (var member in project.ProjectMembers)
                    {
                        ProjectMemberView memberCopy = member;
                        foreach (var roleView in projectRoleView.Where(roleView => memberCopy.UserId == roleView.UserId))
                        {
                            member.ProjectRoles.Add(roleView);
                        }
                    }

                    if (projectRisks.Any())
                    {
                        project.ProjectRisks = projectRisks.ToList();
                    }

                    var query = @"SELECT prv.* FROM [ProjectRoleView] prv WHERE prv.ProjectId = @ProjectId AND prv.UserId = @UserId";

                    var user = IdentityContext.Current.User;

                    IEnumerable <ProjectRoleView> currentUserRoles = conn.Query <ProjectRoleView>(query, new { ProjectId = id, UserId = user.Id });

                    //add the project permissions
                    if (project != null)
                    {
                        IProjectRepository        projectRepository = CoreFactory.ProjectRepository;
                        IEnumerable <ProjectRole> avaliableRoles    = projectRepository.GetAvaliableRoles(user.Id, project.Id);
                        project.Permissions = PermissionLogic.GetPermissions(currentUserRoles, project, user, avaliableRoles.Any());
                    }

                    //set the current project to identity context
                    IdentityContext.CurrentProjectId = project.Id;

                    return(project);
                }
            }
        }