private void RemoveOutOfOffice()
        {
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;


            using (Connection k2Con = new Connection())
            {
                k2Con.Open(base.K2ClientConnectionSetup);

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count != 1)
                {
                    throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations);
                }


                //  If configuration exist already, remove user and re-share
                else if (wsColl.Count == 1)
                {
                    WorklistShare worklistshare = wsColl[0];

                    int capacity = worklistshare.WorkTypes[0].Destinations.Count;

                    string[] existingDestinations = new string[capacity];

                    for (int i = 0; i < capacity; i++)
                    {
                        existingDestinations[i] = worklistshare.WorkTypes[0].Destinations[i].Name.ToUpper().Trim();
                    }

                    int destinationIndex = Array.IndexOf(existingDestinations, destinationUser.ToUpper().Trim());

                    if (destinationIndex != -1)
                    {
                        worklistshare.WorkTypes[0].Destinations.Remove(destinationIndex);
                    }

                    bool result = k2Con.ShareWorkList(worklistshare);

                    DataRow dr = results.NewRow();

                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;

                    results.Rows.Add(dr);;
                }

                k2Con.Close();
            }
        }
Beispiel #2
0
        /// <summary>
        /// Get User Out of Office status from K2 HostServer
        /// </summary>
        /// <param name="originalDestinationUser">The Originator Destination User</param>
        /// <returns>The Worklist user status</returns>
        public WorklistUserStatus GetOOFStatus(string originalDestinationUser)
        {
            bool status = false;
            WorklistUserStatus worklistUserStatus = new WorklistUserStatus();

            using (Connection workflowClient = this.GetWorkflowClient()) {
                switch (string.IsNullOrEmpty(originalDestinationUser) ? workflowClient.GetUserStatus() : workflowClient.GetUserStatus(originalDestinationUser))
                {
                case UserStatuses.None:
                case UserStatuses.Available:
                    status = true;
                    break;

                case UserStatuses.OOF:
                    status = false;
                    break;
                }
                worklistUserStatus.Status = status;
                if (!worklistUserStatus.Status)
                {
                    WorklistShares worklistShares = new WorklistShares();
                    worklistShares = workflowClient.GetCurrentSharingSettings(ShareType.OOF);
                    if (worklistShares.Count > 0)
                    {
                        WorklistShare worklistShare = worklistShares[0];
                        worklistShare.ShareType = ShareType.OOF;
                        List <OOFUser> list = new List <OOFUser>();
                        foreach (K2.Destination destination in worklistShare.WorkTypes[0].Destinations)
                        {
                            list.Add(new OOFUser {
                                UserName = destination.Name,
                                Type     = destination.DestinationType.ToString()
                            });
                        }
                        worklistUserStatus.users = list;
                    }
                }
            }
            return(worklistUserStatus);
        }
Beispiel #3
0
        /// <summary>
        /// Create or set the Out Of Office of current user
        /// </summary>
        /// <param name="wrapper">The Out Of Office criteria</param>
        /// <returns>Success(true) or Fail(False)</returns>
        public bool SetOutOfOffice(OOFWrapper wrapper)
        {
            if (wrapper.WorkType == null)
            {
                _connection.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);
                return(false);
            }


            bool           isNew          = false;
            WorklistShares worklistShares = new WorklistShares();

            worklistShares = _connection.GetCurrentSharingSettings(ShareType.OOF);
            WorklistShare worklistShare = null;

            if (worklistShares.Count > 0)
            {
                worklistShare           = worklistShares[0];
                worklistShare.ShareType = ShareType.OOF;
            }
            else
            {
                isNew = true;
            }

            if (worklistShare == null)
            {
                worklistShare           = new WorklistShare();
                worklistShare.ShareType = ShareType.OOF;
                isNew = true;
            }


            worklistShare.StartDate = wrapper.StartDate;
            worklistShare.EndDate   = wrapper.EndDate;

            WorkTypes workTypes = worklistShare.WorkTypes;
            WorkType  workType  = new WorkType();

            if (workTypes.Count > 0)
            {
                workType = workTypes[0];
            }
            else
            {
                workType = new WorkType();
                workTypes.Add(workType);
            }
            workType.Name = Guid.NewGuid().ToString();
            Destinations destinations = new Destinations();

            foreach (DestinationDto dest in wrapper.WorkType.Destinations)
            {
                var destination = new Destination(dest.LoginName.FQNWithK2Label(), DestinationType.User);
                destinations.Add(destination);
            }

            workType.Destinations       = destinations;
            workType.WorkTypeExceptions = GetWorkTypeExceptions(wrapper.WorkType.WorkTypeExceptions);
            worklistShare.WorkTypes     = workTypes;

            if (isNew)
            {
                _connection.ShareWorkList(worklistShare);
            }
            _connection.UpdateWorkType(worklistShare.WorkTypes[0]);
            _connection.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);


            return(true);
        }
Beispiel #4
0
        public void StartK2OOF()
        {
            string conStringIIF = this.AppConfig.IIFConnectionString;

            using (SqlConnection con = new SqlConnection(conStringIIF))
            {
                con.Open();
                string querySelect = "SELECT";
                querySelect = querySelect + " [Src].[Id], [Src].[FromDate], [Src].[ToDate]";
                querySelect = querySelect + " , [Src].[FromFQN], [Src].[ToFQN]";
                querySelect = querySelect + " , [Src].[IsActive], [Src].[IsCanceled], [Src].[IsExpired]";
                querySelect = querySelect + " , [Src].[IsStartedInK2], [Src].[IsEndedInK2]";
                querySelect = querySelect + " FROM [dbo].[Vw_TaskDelegation_NeedK2Started] AS [Src]";

                List <TaskDelegation> listTaskDelegation = new List <TaskDelegation>();

                using (SqlCommand cmd = con.CreateCommand())
                {
                    cmd.CommandType = CommandType.Text;
                    cmd.CommandText = querySelect;

                    using (SqlDataReader dr = cmd.ExecuteReader())
                    {
                        int indexOf_Id            = dr.GetOrdinal("Id");
                        int indexOf_FromDate      = dr.GetOrdinal("FromDate");
                        int indexOf_ToDate        = dr.GetOrdinal("ToDate");
                        int indexOf_FromFQN       = dr.GetOrdinal("FromFQN");
                        int indexOf_ToFQN         = dr.GetOrdinal("ToFQN");
                        int indexOf_IsActive      = dr.GetOrdinal("IsActive");
                        int indexOf_IsCanceled    = dr.GetOrdinal("IsCanceled");
                        int indexOf_IsExpired     = dr.GetOrdinal("IsExpired");
                        int indexOf_IsStartedInK2 = dr.GetOrdinal("IsStartedInK2");
                        int indexOf_IsEndedInK2   = dr.GetOrdinal("IsEndedInK2");

                        while (dr.Read())
                        {
                            TaskDelegation data = new TaskDelegation();
                            data.Id            = dr.GetInt64(indexOf_Id);
                            data.FromDate      = dr.GetDateTime(indexOf_FromDate);
                            data.ToDate        = dr.GetDateTime(indexOf_ToDate);
                            data.FromFQN       = dr.GetString(indexOf_FromFQN);
                            data.ToFQN         = dr.GetString(indexOf_ToFQN);
                            data.IsActive      = dr.GetBoolean(indexOf_IsActive);
                            data.IsCanceled    = dr.GetBoolean(indexOf_IsCanceled);
                            data.IsExpired     = dr.GetBoolean(indexOf_IsExpired);
                            data.IsStartedInK2 = dr.GetBoolean(indexOf_IsStartedInK2);
                            data.IsEndedInK2   = dr.GetBoolean(indexOf_IsEndedInK2);

                            listTaskDelegation.Add(data);
                        }
                    }
                }

                Exception innerEx = null;

                foreach (TaskDelegation taskDelegation in listTaskDelegation)
                {
                    try
                    {
                        using (Connection k2Con = new Connection())
                        {
                            k2Con.Open(this.AppConfig.K2Server);
                            k2Con.ImpersonateUser(taskDelegation.FromFQN);

                            WorklistCriteria worklistCriteria = new WorklistCriteria();
                            worklistCriteria.Platform = "ASP";
                            Destinations worktypeDestinations = new Destinations();
                            worktypeDestinations.Add(new Destination(taskDelegation.ToFQN, DestinationType.User));
                            WorkType workType = new WorkType("TaskDelegationWork_" + taskDelegation.Id.ToString(), worklistCriteria, worktypeDestinations);

                            WorklistShare worklistShare = new WorklistShare();
                            worklistShare.ShareType = ShareType.OOF;

                            worklistShare.StartDate = taskDelegation.FromDate;
                            worklistShare.EndDate   = taskDelegation.ToDate;

                            worklistShare.WorkTypes.Add(workType);
                            k2Con.ShareWorkList(worklistShare);

                            k2Con.SetUserStatus(UserStatuses.OOF);

                            string queryUpdate = "UPDATE [dbo].[TaskDelegation] SET";
                            queryUpdate = queryUpdate + " [IsActive] = 1";
                            queryUpdate = queryUpdate + ", [IsExpired] = 0";
                            queryUpdate = queryUpdate + ", [IsStartedInK2] = 1";
                            queryUpdate = queryUpdate + " WHERE [Id] = @Id";

                            using (SqlCommand cmd = con.CreateCommand())
                            {
                                cmd.CommandType = CommandType.Text;
                                cmd.CommandText = queryUpdate;
                                cmd.Parameters.Add(this.NewSqlParameter("Id", SqlDbType.BigInt, taskDelegation.Id));

                                cmd.ExecuteNonQuery();
                            }
                        }
                    }
                    catch (Exception ex)
                    {
                        innerEx = ex;
                    }
                }

                if (innerEx != null)
                {
                    throw new Exception("An error occured. " + innerEx.Message, innerEx);
                }

                con.Close();
            }
        }
        // Example from page - http://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.6.9/default.htm#How_to_set_a_users_Out_of_Office_Status.html%3FTocPath%3DRuntime%2520APIs%2520and%2520Services%7CWorkflow%7CWorkflow%2520Client%2520API%7CWorkflow%2520Client%2520API%2520Samples%7C_____10
        /// <summary>
        /// Add OOF share for current user
        /// </summary>
        private void AddOutOfOffice()
        {
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;


            using (Connection k2Con = this.ServiceBroker.K2Connection.GetWorkflowClientConnection())
            {
                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count > 1)
                {
                    throw new ApplicationException(Resources.MultipleOOFConfigurations);
                }
                else if (wsColl.Count == 1) //  If configuration exist already, add to it
                {
                    WorklistShare worklistshare = wsColl[0];
                    int           capacity      = worklistshare.WorkTypes[0].Destinations.Count;

                    string[] existingDestinations = new string[capacity];

                    for (int i = 0; i < capacity; i++)
                    {
                        existingDestinations[i] = worklistshare.WorkTypes[0].Destinations[i].Name.ToUpper().Trim();
                    }

                    if (Array.IndexOf(existingDestinations, destinationUser.ToUpper().Trim()) == -1)
                    {
                        worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User));
                    }

                    bool result = k2Con.ShareWorkList(worklistshare);

                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;
                    results.Rows.Add(dr);;
                }
                else   // New user, create configuration for OOF
                {
                    // ALL Work that remains which does not form part of any "WorkTypeException" Filter
                    WorklistCriteria worklistcriteria = new WorklistCriteria();
                    worklistcriteria.Platform = "ASP";

                    // Send ALL Work based on the above Filter to the following User
                    Destinations worktypedestinations = new Destinations();
                    worktypedestinations.Add(new Destination(destinationUser, DestinationType.User));

                    // Link the filters and destinations to the Work
                    WorkType worktype = new WorkType("MyWork_" + k2Con.User.FQN, worklistcriteria, worktypedestinations);

                    WorklistShare worklistshare = new WorklistShare();
                    worklistshare.ShareType = ShareType.OOF;
                    worklistshare.WorkTypes.Add(worktype);

                    bool result = k2Con.ShareWorkList(worklistshare);
                    k2Con.SetUserStatus(UserStatuses.Available);

                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;
                    results.Rows.Add(dr);
                }

                k2Con.Close();
            }
        }
        // Example from page - http://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.6.9/default.htm#How_to_set_a_users_Out_of_Office_Status.html%3FTocPath%3DRuntime%2520APIs%2520and%2520Services%7CWorkflow%7CWorkflow%2520Client%2520API%7CWorkflow%2520Client%2520API%2520Samples%7C_____10
        /// <summary>
        /// Add OOF share for current user
        /// </summary>
        private void AddOutOfOffice()
        {
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            using (Connection k2Con = new Connection())
            {
                k2Con.Open(base.K2ClientConnectionSetup);

                WorklistShares wsColl = k2Con.GetCurrentSharingSettings(ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count > 1)
                {
                    throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations);
                }

                //  If configuration exist already, add to it
                else if (wsColl.Count == 1)
                {

                    WorklistShare worklistshare = wsColl[0];

                    int capacity = worklistshare.WorkTypes[0].Destinations.Count;

                    string[] existingDestinations = new string[capacity];

                    for (int i = 0; i < capacity; i++)
                    {
                        existingDestinations[i] = worklistshare.WorkTypes[0].Destinations[i].Name.ToUpper().Trim();
                    }

                    if (Array.IndexOf(existingDestinations, destinationUser.ToUpper().Trim()) == -1)
                    {
                        worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User));
                    }

                    bool result = k2Con.ShareWorkList(worklistshare);

                    DataRow dr = results.NewRow();

                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;

                    results.Rows.Add(dr); ;

                }
                // New user, create configuration for OOF
                else
                {

                    // ALL Work that remains which does not form part of any "WorkTypeException" Filter
                    WorklistCriteria worklistcriteria = new WorklistCriteria();
                    worklistcriteria.Platform = "ASP";

                    // Send ALL Work based on the above Filter to the following User
                    Destinations worktypedestinations = new Destinations();
                    worktypedestinations.Add(new Destination(destinationUser, DestinationType.User));

                    // Link the filters and destinations to the Work
                    WorkType worktype = new WorkType("MyWork_" + k2Con.User.FQN, worklistcriteria, worktypedestinations);

                    WorklistShare worklistshare = new WorklistShare();
                    worklistshare.ShareType = ShareType.OOF;
                    worklistshare.WorkTypes.Add(worktype);

                    bool result = k2Con.ShareWorkList(worklistshare);
                    k2Con.SetUserStatus(UserStatuses.Available);

                    DataRow dr = results.NewRow();

                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;

                    results.Rows.Add(dr);

                }

                k2Con.Close();
            }
        }
        // Example from page - http://help.k2.com/onlinehelp/k2blackpearl/DevRef/4.6.9/default.htm#How_to_set_a_users_Out_of_Office_Status.html%3FTocPath%3DRuntime%2520APIs%2520and%2520Services%7CWorkflow%7CWorkflow%2520Client%2520API%7CWorkflow%2520Client%2520API%2520Samples%7C_____10
        private void AddOutOfOffice()
        {
            string userFQN = base.GetStringProperty(Constants.Properties.OutOfOffice.UserFQN);
            string destinationUser = base.GetStringProperty(Constants.Properties.OutOfOffice.DestinationUser);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];
            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = new WorkflowManagementServer();

            using (mngServer.CreateConnection())
            {
                mngServer.Open(BaseAPIConnectionString);

                WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count > 1)
                {
                    throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations);
                }

                //  If configuration exist already, add to it
                if (wsColl.Count == 1)
                {

                    WorklistShare worklistshare = wsColl[0];
                    worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User));
                    bool result = mngServer.ShareWorkList(userFQN, worklistshare);

                    DataRow dr = results.NewRow();
                    dr[Constants.Properties.OutOfOffice.UserFQN] = userFQN;
                    dr[Constants.Properties.OutOfOffice.DestinationUser] = destinationUser;
                    dr[Constants.Properties.OutOfOffice.CallSuccess] = result;
                    results.Rows.Add(dr); ;

                }
                // New user, create configuration for OOF
                else
                {
                    // ALL Work that remains which does not form part of any "WorkTypeException" Filter
                    WorklistCriteria worklistcriteria = new WorklistCriteria();
                    worklistcriteria.Platform = "ASP";

                    // Send ALL Work based on the above Filter to the following User
                    Destinations worktypedestinations = new Destinations();
                    worktypedestinations.Add(new Destination(destinationUser, DestinationType.User));

                    // Link the filters and destinations to the Work
                    WorkType worktype = new WorkType("MyWork", worklistcriteria, worktypedestinations);

                    WorklistShare worklistshare = new WorklistShare();
                    worklistshare.ShareType = ShareType.OOF;
                    worklistshare.WorkTypes.Add(worktype);

                    bool result = mngServer.ShareWorkList(userFQN, worklistshare);
                    mngServer.SetUserStatus(userFQN, UserStatuses.Available);

                    DataRow dr = results.NewRow();
                    dr[Constants.Properties.OutOfOffice.UserFQN] = userFQN;
                    dr[Constants.Properties.OutOfOffice.DestinationUser] = destinationUser;
                    dr[Constants.Properties.OutOfOffice.CallSuccess] = result;
                    results.Rows.Add(dr);
                }

            }
        }
Beispiel #8
0
        private void AddOutOfOffice()
        {
            string userFQN         = base.GetStringProperty(Constants.SOProperties.OutOfOffice.UserFQN, true);
            string destinationUser = base.GetStringProperty(Constants.SOProperties.OutOfOffice.DestinationUser, true);

            ServiceObject serviceObject = base.ServiceBroker.Service.ServiceObjects[0];

            serviceObject.Properties.InitResultTable();
            DataTable results = base.ServiceBroker.ServicePackage.ResultTable;

            WorkflowManagementServer mngServer = new WorkflowManagementServer();

            using (mngServer.CreateConnection())
            {
                mngServer.Open(BaseAPIConnectionString);

                WorklistShares wsColl = mngServer.GetCurrentSharingSettings(userFQN, ShareType.OOF);

                //  Throw error if multiple configurations (WorklistShare objects) detected, as this method cannot support that
                if (wsColl.Count > 1)
                {
                    throw new ApplicationException(Constants.ErrorMessages.MultipleOOFConfigurations);
                }

                //  If configuration exist already, add to it
                if (wsColl.Count == 1)
                {
                    WorklistShare worklistshare = wsColl[0];
                    worklistshare.WorkTypes[0].Destinations.Add(new Destination(destinationUser, DestinationType.User));
                    bool result = mngServer.ShareWorkList(userFQN, worklistshare);
                    if (!result)
                    {
                        throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF);
                    }
                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.UserFQN]         = userFQN;
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;

                    results.Rows.Add(dr);;
                }
                // New user, create configuration for OOF
                else
                {
                    // ALL Work that remains which does not form part of any "WorkTypeException" Filter
                    WorklistCriteria worklistcriteria = new WorklistCriteria();
                    worklistcriteria.Platform = "ASP";

                    // Send ALL Work based on the above Filter to the following User
                    Destinations worktypedestinations = new Destinations();
                    worktypedestinations.Add(new Destination(destinationUser, DestinationType.User));

                    // Link the filters and destinations to the Work
                    WorkType worktype = new WorkType("MyWork", worklistcriteria, worktypedestinations);

                    WorklistShare worklistshare = new WorklistShare();
                    worklistshare.ShareType = ShareType.OOF;
                    worklistshare.WorkTypes.Add(worktype);

                    bool result = mngServer.ShareWorkList(userFQN, worklistshare);
                    if (!result)
                    {
                        throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF);
                    }
                    result = mngServer.SetUserStatus(userFQN, UserStatuses.Available);
                    if (!result)
                    {
                        throw new ApplicationException(Constants.ErrorMessages.FailedToSetOOF);
                    }

                    DataRow dr = results.NewRow();
                    dr[Constants.SOProperties.OutOfOffice.UserFQN]         = userFQN;
                    dr[Constants.SOProperties.OutOfOffice.DestinationUser] = destinationUser;
                    results.Rows.Add(dr);
                }
            }
        }
Beispiel #9
0
        /// <summary>
        /// Create or set the Out Of Office of current user
        /// </summary>
        /// <param name="wrapper">The Out Of Office criteria</param>
        /// <returns>Success(true) or Fail(False)</returns>
        public bool SetOutOfOffice(OOFWrapper wrapper)
        {
            if (wrapper.WorkType == null)
            {
                using (Connection workflowClient = this.GetWorkflowClient()) {
                    workflowClient.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);
                }

                return(false);
            }

            using (Connection workflowClient = this.GetWorkflowClient()) {
                bool           isNew          = false;
                WorklistShares worklistShares = new WorklistShares();
                worklistShares = workflowClient.GetCurrentSharingSettings(ShareType.OOF);
                WorklistShare worklistShare = null;
                if (worklistShares.Count > 0)
                {
                    worklistShare           = worklistShares[0];
                    worklistShare.ShareType = ShareType.OOF;
                }
                else
                {
                    isNew = true;
                }

                if (worklistShare == null)
                {
                    worklistShare           = new WorklistShare();
                    worklistShare.ShareType = ShareType.OOF;
                    isNew = true;
                }


                worklistShare.StartDate = wrapper.StartDate;
                worklistShare.EndDate   = wrapper.EndDate;

                WorkTypes workTypes = worklistShare.WorkTypes;
                WorkType  workType  = new WorkType();

                if (workTypes.Count > 0)
                {
                    workType = workTypes[0];
                }
                else
                {
                    workType = new WorkType();
                    workTypes.Add(workType);
                }
                workType.Name = Guid.NewGuid().ToString();
                Destinations destinations = new Destinations();

                foreach (DestinationDto dest in wrapper.WorkType.Destinations)
                {
                    if (SecurityLabelUtils.IsCorrectUserName(dest.LoginName))
                    {
                        var destination = new K2.Destination(SecurityLabelUtils.GetNameWithLabel(dest.LoginName), DestinationType.User);
                        destinations.Add(destination);
                    }
                }

                workType.Destinations       = destinations;
                workType.WorkTypeExceptions = GetWorkTypeExceptions(wrapper.WorkType.WorkTypeExceptions);
                worklistShare.WorkTypes     = workTypes;

                if (isNew)
                {
                    workflowClient.ShareWorkList(worklistShare);
                }
                workflowClient.UpdateWorkType(worklistShare.WorkTypes[0]);
                workflowClient.SetUserStatus(Convert.ToBoolean(wrapper.Status) ? UserStatuses.Available : UserStatuses.OOF);
            }

            return(true);
        }