Beispiel #1
0
        private static void UpdateProjectAndManager(int todoId, int projectId, int managerId)
        {
            int oldProjectId = DBToDo.GetProject(todoId);
            int oldManagerId = DBToDo.GetManager(todoId);

            if (projectId == 0)            // leave old project
            {
                projectId = oldProjectId;
            }

            if (managerId == 0)                 // Leave old manager
            {
                managerId = oldManagerId;
            }

            if (projectId != oldProjectId && projectId > 0 && !ToDo.CanCreate(projectId))
            {
                throw new AccessDeniedException();
            }

            if (projectId != oldProjectId || managerId != oldManagerId)
            {
                using (DbTransaction tran = DbTransaction.Begin())
                {
                    DBToDo.UpdateProjectAndManager(todoId, projectId, managerId);

                    // OZ: User Role Addon
                    if (managerId != oldManagerId)
                    {
                        UserRoleHelper.DeleteTodoManagerRole(todoId, oldManagerId);
                        UserRoleHelper.AddTodoManagerRole(todoId, managerId);
                    }

                    if (projectId != oldProjectId)
                    {
                        ForeignContainerKey.Delete(UserRoleHelper.CreateTodoContainerKey(todoId), UserRoleHelper.CreateProjectContainerKey(oldProjectId));
                        if (projectId > 0)
                        {
                            ForeignContainerKey.Add(UserRoleHelper.CreateTodoContainerKey(todoId), UserRoleHelper.CreateProjectContainerKey(projectId));
                        }
                    }
                    // end OZ

                    if (projectId != oldProjectId)
                    {
                        if (projectId > 0)
                        {
                            SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_TodoList_TodoAdded, projectId, todoId);
                        }
                        else
                        {
                            SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_TodoList_TodoDeleted, oldProjectId, todoId);
                        }

                        // O.R. [2008-07-30]
                        if (oldProjectId > 0)
                        {
                            TimeTracking.RecalculateProjectTaskTime(oldProjectId);
                        }
                        if (projectId > 0)
                        {
                            TimeTracking.RecalculateProjectTaskTime(projectId);
                        }
                    }

                    if (managerId != oldManagerId)
                    {
                        SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Manager_ManagerDeleted, todoId, oldManagerId);
                        SystemEvents.AddSystemEvents(SystemEventTypes.Todo_Updated_Manager_ManagerAdded, todoId, managerId);
                    }

                    tran.Commit();
                }
            }
        }
Beispiel #2
0
        private static void UpdateProjectAndManager(int objectId, int projectId, int managerId)
        {
            int oldProjectId = DBEvent.GetProject(objectId);
            int oldManagerId = DBEvent.GetManager(objectId);

            if (managerId == 0)             // Don't change manager
            {
                managerId = oldManagerId;
            }

            if (projectId == 0)            // Don't change project
            {
                projectId = oldProjectId;
            }

            if (projectId != oldProjectId || managerId != oldManagerId)
            {
                using (DbTransaction tran = DbTransaction.Begin())
                {
                    DbCalendarEntry2.UpdateProjectAndManager(objectId, projectId, managerId);

                    // OZ: User Role Addon
                    if (managerId != oldManagerId)
                    {
                        UserRoleHelper.DeleteEventManagerRole(objectId, oldManagerId);
                        UserRoleHelper.AddEventManagerRole(objectId, managerId);
                    }

                    if (projectId != oldProjectId)
                    {
                        ForeignContainerKey.Delete(UserRoleHelper.CreateEventContainerKey(objectId), UserRoleHelper.CreateProjectContainerKey(oldProjectId));
                        if (projectId > 0)
                        {
                            ForeignContainerKey.Add(UserRoleHelper.CreateEventContainerKey(objectId), UserRoleHelper.CreateProjectContainerKey(projectId));
                        }
                    }
                    // end OZ

                    if (projectId != oldProjectId)
                    {
                        if (projectId > 0)
                        {
                            SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_CalendarEntryList_CalendarEntryAdded, projectId, objectId);
                        }
                        else
                        {
                            SystemEvents.AddSystemEvents(SystemEventTypes.Project_Updated_CalendarEntryList_CalendarEntryDeleted, oldProjectId, objectId);
                        }
                    }

                    if (managerId != oldManagerId)
                    {
                        SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Manager_ManagerDeleted, objectId, oldManagerId);
                        SystemEvents.AddSystemEvents(SystemEventTypes.CalendarEntry_Updated_Manager_ManagerAdded, objectId, managerId);
                    }

                    tran.Commit();
                }
            }
        }