private bool GetActivityByProjectAndContact(Guid projectId, Guid contactId, bool useAllChildrenLevels = false)
        {
            var entitySchemaManager = UserConnection.EntitySchemaManager;
            var esq      = new EntitySchemaQuery(entitySchemaManager, "Activity");
            var idColumn = esq.AddColumn("Id");

            if (useAllChildrenLevels)
            {
                var projects      = HierarchicalProjectUtilities.GetChildProjectsIDs(projectId, UserConnection);
                var projectFilter = esq.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                   "Project", projects.Select(x => (object)x).ToArray());
                esq.Filters.Add(projectFilter);
            }
            else
            {
                var projectFilter = esq.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                   "Project", projectId);
                esq.Filters.Add(projectFilter);
            }
            var ownerFilter = esq.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                             "Owner", contactId);

            esq.Filters.Add(ownerFilter);
            var entities = esq.GetEntityCollection(UserConnection);

            return(entities.Count > 0);
        }
Example #2
0
        private CanDeleteResponse GetCanDeleteByProjectResourceId(Guid projectResourceId)
        {
            var entitySchemaManager  = UserConnection.EntitySchemaManager;
            CanDeleteResponse result = new CanDeleteResponse();

            result.Success = true;
            var esqWork = new EntitySchemaQuery(entitySchemaManager, "WorkResourceElement");

            esqWork.AddColumn("Id");
            var projectResFilter = esqWork.CreateFilterWithParameters(FilterComparisonType.Equal, "ProjectResourceElement", projectResourceId);

            esqWork.Filters.Add(projectResFilter);
            var workEntities = esqWork.GetEntityCollection(UserConnection);

            if (workEntities.Count > 0)
            {
                result.Success = false;
                result.Code    = 200;
                return(result);
            }
            var projectResourceElementSchema = entitySchemaManager.GetInstanceByName("ProjectResourceElement");
            var projectResourceEntity        = projectResourceElementSchema.CreateEntity(UserConnection);

            if (!projectResourceEntity.FetchFromDB(projectResourceElementSchema.GetPrimaryColumnName(), projectResourceId))
            {
                return(result);
            }
            var projectId = projectResourceEntity.GetTypedColumnValue <Guid>(projectResourceElementSchema.Columns.FindByName("Project").ColumnValueName);
            var contactId = projectResourceEntity.GetTypedColumnValue <Guid>(projectResourceElementSchema.Columns.FindByName("Contact").ColumnValueName);

            if (projectId == null || projectId == Guid.Empty || contactId == null || contactId == Guid.Empty)
            {
                return(result);
            }
            var esqActivity = new EntitySchemaQuery(entitySchemaManager, "Activity");

            esqActivity.AddColumn("Id");
            var projects      = HierarchicalProjectUtilities.GetChildProjectsIDs(projectId, UserConnection);
            var projectFilter = esqActivity.CreateFilterWithParameters(FilterComparisonType.Equal, "Project", projects.Select(x => (object)x).ToArray());

            esqActivity.Filters.Add(projectFilter);
            var ownerFilter = esqActivity.CreateFilterWithParameters(FilterComparisonType.Equal, "Owner", contactId);

            esqActivity.Filters.Add(ownerFilter);
            var activityEntities = esqActivity.GetEntityCollection(UserConnection);

            if (activityEntities.Count > 0)
            {
                result.Success = false;
                result.Code    = 300;
                return(result);
            }
            return(result);
        }
Example #3
0
        public decimal RestProjectManhourByRole(Guid projectId, Guid roleId)
        {
            var     entitySchemaManager = UserConnection.EntitySchemaManager;
            decimal manhour             = 0m;
            var     esqManhour          = new EntitySchemaQuery(entitySchemaManager, "ProjectManhour");
            var     workManhourColumn   = esqManhour.AddColumn("PlanningWork");
            var     manhourRoleFilter   = esqManhour.CreateFilterWithParameters(FilterComparisonType.Equal, "Role", roleId);

            esqManhour.Filters.Add(manhourRoleFilter);
            var manhourProjectFilter = esqManhour.CreateFilterWithParameters(FilterComparisonType.Equal, "Project", projectId);

            esqManhour.Filters.Add(manhourProjectFilter);
            var manhourEntities = esqManhour.GetEntityCollection(UserConnection);

            if (manhourEntities.Count > 0)
            {
                manhour = manhourEntities[0].GetTypedColumnValue <decimal>(workManhourColumn.Name);
            }
            if (manhour <= 0)
            {
                return(0m);
            }
            List <Guid> childrens      = HierarchicalProjectUtilities.GetChildProjectsIDs(projectId, UserConnection);
            var         esqTemp        = new EntitySchemaQuery(entitySchemaManager, "ProjectTeamParticipant");
            var         workTeamColumn = esqTemp.AddColumn("PlanningWork");
            var         teamRoleFilter = esqTemp.CreateFilterWithParameters(FilterComparisonType.Equal, "Role", roleId);

            esqTemp.Filters.Add(teamRoleFilter);
            var teamProjectFilter = esqTemp.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                       "Project", childrens.Select(x => (object)x).ToArray());

            esqTemp.Filters.Add(teamProjectFilter);
            var teamEntities = esqTemp.GetEntityCollection(UserConnection);

            if (teamEntities.Count > 0)
            {
                foreach (var teamEntity in teamEntities)
                {
                    manhour -= teamEntity.GetTypedColumnValue <decimal>(workTeamColumn.Name);
                }
            }
            if (manhour > 0)
            {
                return(manhour);
            }
            else
            {
                return(0m);
            }
        }
        private Dictionary <Guid, WorkElement> GetChildWorkByProjectId(Guid projectId, Guid projectResourceElementId, bool useAllChildrenLevels = false)
        {
            var response                = new Dictionary <Guid, WorkElement>();
            var entitySchemaManager     = UserConnection.EntitySchemaManager;
            var esqChildWork            = new EntitySchemaQuery(entitySchemaManager, "WorkResourceElement");
            var childPlanningWorkColumn = esqChildWork.AddColumn("PlanningWork");
            var childProjectIdColumn    = esqChildWork.AddColumn("Project.Id");

            if (useAllChildrenLevels)
            {
                var projects            = HierarchicalProjectUtilities.GetChildProjectsIDs(projectId, UserConnection);
                var parentProjectFilter = esqChildWork.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                                  "Project.ParentProject", projects.Select(x => (object)x).ToArray());
                esqChildWork.Filters.Add(parentProjectFilter);
            }
            else
            {
                var parentProjectFilter = esqChildWork.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                                  "Project.ParentProject", projectId);
                esqChildWork.Filters.Add(parentProjectFilter);
            }
            var childResourceFilter = esqChildWork.CreateFilterWithParameters(FilterComparisonType.Equal,
                                                                              "ProjectResourceElement", projectResourceElementId);

            esqChildWork.Filters.Add(childResourceFilter);
            decimal childsWork    = 0m;
            var     childEntities = esqChildWork.GetEntityCollection(UserConnection);

            if (childEntities.Count > 0)
            {
                foreach (var childEntity in childEntities)
                {
                    var childProjectId = childEntity.GetTypedColumnValue <Guid>(childProjectIdColumn.Name);
                    var planningWork   = childEntity.GetTypedColumnValue <decimal>(childPlanningWorkColumn.Name);
                    if (response.ContainsKey(childProjectId))
                    {
                        response[childProjectId].PlanningWork += planningWork;
                    }
                    else
                    {
                        var workElement = new WorkElement();
                        workElement.PlanningWork = planningWork;
                        response.Add(childProjectId, workElement);
                    }
                }
            }
            return(response);
        }