Esempio n. 1
0
        public JsonResult Get(int id)
        {
            var apiResult = TryExecute(() =>
            {
                var project              = _projectRepository.Get(id, "Client.Person,ParentProject");
                var projectVm            = new ProjectModel(project);
                var projectTechnologyIds = _projectTechnologyMapRepository.GetAllBy(m => m.ProjectId == id).Select(m => m.TechnologyId).ToList();
                projectVm.TechnologyIds  = projectTechnologyIds;
                return(projectVm);
            }, "Project Fetched sucessfully");

            return(Json(apiResult, JsonRequestBehavior.AllowGet));
        }
Esempio n. 2
0
        public ActionResult Details(int id)
        {
            // Check whether i have access to this Project details
            var employee = _employeeRepository.GetBy(u => u.UserId == WebUser.Id, "User,User.Person,ReportingPerson.User.Person,Manager.User.Person,Location,Department,Designation,Shift");
            var isMember = _projectMemberRepository.Any(m => m.EmployeeId == employee.Id && m.ProjectId == id);

            if (!isMember && !WebUser.IsAdmin)
            {
                return(RedirectToAction("NotAuthorized", "Error", new { area = "" }));
            }

            var project = _projectRepository.Get(id, "Client,Client.Person,ParentProject");

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

            // My Projects -> Projects to which i have access
            var myProjects   = _projectMemberRepository.GetAllBy(m => m.EmployeeId == employee.Id).Select(m => m.ProjectId).Distinct().ToList();
            var projectsList = _projectRepository.GetAllBy(p => myProjects.Contains(p.Id) && !(p.Status == ProjectStatus.Closed || p.Status == ProjectStatus.Cancelled)).Select(p => new SelectItem
            {
                Id    = p.Id,
                Title = p.Title
            }).OrderBy(p => p.Title).ToList();


            if (WebUser.IsAdmin == true)
            {
                ViewBag.webUser = WebUser.IsAdmin;
                var allProjects = _projectRepository.GetAllBy(p => !(p.Status == ProjectStatus.Closed || p.Status == ProjectStatus.Cancelled)).Select(p => new SelectItem
                {
                    Id    = p.Id,
                    Title = p.Title
                }).OrderBy(p => p.Title).ToList();

                ViewBag.AllProject = new SelectList(allProjects, "Id", "Title", project.Id);
            }

            ViewBag.MyProjectsId = new SelectList(projectsList, "Id", "Title", project.Id);

            // Set Billing Access
            var hasBillingAccess = _projectMemberRepository.Any(m => m.EmployeeId == employee.Id && m.ProjectId == project.Id && m.ProjectMemberRole.Role == MemberRole.Sales) || WebUser.IsAdmin;

            ViewBag.HasBillingAccess = hasBillingAccess;

            // Set PM Access
            var hasPMAccess = _projectMemberRepository.Any(m => m.EmployeeId == employee.Id && m.ProjectId == project.Id && m.ProjectMemberRole.Role == MemberRole.ProjectManager) || WebUser.IsAdmin;

            ViewBag.HasPMAccess = hasPMAccess;

            // Set Lead Access
            var hasLeadAccess = _projectMemberRepository.Any(m => m.EmployeeId == employee.Id && m.ProjectId == project.Id && m.ProjectMemberRole.Role == MemberRole.Lead) || WebUser.IsAdmin;

            ViewBag.HasLeadAccess = hasLeadAccess;


            var projectBillings           = _projectBillingRepository.GetAllBy(b => b.ProjectId == project.Id);
            var projectMembers            = _projectMemberRepository.GetAllBy(m => m.ProjectId == project.Id, "MemberEmployee.User.Person");
            var projectMileStones         = _projectMileStoneRepository.GetAllBy(m => m.ProjectId == project.Id);
            var projectDocuments          = _projectDocumentRepository.GetAllBy(p => p.ProjectId == project.Id);
            var projectBillingCorrections = _projectBillingCorrectionRepository.GetAllBy(b => b.ProjectId == project.Id);

            List <Task> tasks;

            if (WebUser.IsAdmin || hasPMAccess || hasLeadAccess)
            {
                tasks = _taskRepository.GetAllBy(m => m.ProjectId == project.Id, o => o.OrderByDescending(p => p.DueDate)).ToList();
            }
            else
            {
                tasks = _taskRepository.GetAllBy(m => m.ProjectId == project.Id && (m.AssigneeId == employee.Id || m.CreatedByUserId == WebUser.Id), o => o.OrderByDescending(p => p.DueDate)).ToList();
            }

            var technologies = _projectTechnologyMapRepository.GetAllBy(r => r.ProjectId == project.Id, "Technology").Select(t => t.Technology).ToList();

            // Timesheet Details
            var projectContributions = _timeSheetLineItemRepository.GetAllBy(p => p.ProjectId == project.Id, "Timesheet")
                                       .GroupBy(g => g.TimeSheet.CreatedByUserId)
                                       .Select(i => new ProjectContribution
            {
                UserId = i.Key,
                Effort = i.Sum(k => k.Effort)
            }).ToList();

            // Cannot use Project members as public projects doesnt have any project members
            var allUsers = _userRepository.GetAll("Person").ToList();

            foreach (var projectContribution in projectContributions)
            {
                var selectedUser = allUsers.FirstOrDefault(p => p.Id == projectContribution.UserId);
                if (selectedUser != null)
                {
                    projectContribution.Name = selectedUser.Person.Name;
                }
            }

            var projectViewModel = new ProjectViewModel
            {
                Id                        = project.Id,
                ClientId                  = project.ClientId,
                Client                    = project.Client,
                Title                     = project.Title,
                Description               = project.Description,
                StartDate                 = project.StartDate,
                EndDate                   = project.EndDate,
                Status                    = project.Status.Value,
                ParentId                  = project.ParentId,
                ParentProject             = project.ParentProject,
                Billing                   = project.Billing,
                ExpectedBillingAmount     = project.ExpectedBillingAmount,
                ProjectBillings           = projectBillings.ToList(),
                ProjectBillingCorrections = projectBillingCorrections.ToList(),
                ProjectMembers            = projectMembers.ToList(),
                ProjectMileStonesStones   = projectMileStones.ToList(),
                Tasks                     = tasks,
                ProjectDocuments          = projectDocuments.ToList(),
                CreatedOn                 = project.CreatedOn,
                Contributions             = projectContributions,
                Technologies              = technologies,
                Settings                  =
                    !string.IsNullOrEmpty(project.Setting)
                        ? JsonConvert.DeserializeObject <ProjectSettings>(project.Setting)
                        : new ProjectSettings()
            };

            // Take saved Settings or fallback to default.

            return(View(projectViewModel));
        }