/// <summary>
        /// Saves the new team entity and adds the owner to the team.  Optionally will
        /// add the owner's manager to the team is the add owner's manager checkbox is checked.
        /// </summary>
        /// <param name="form"></param>
        /// <param name="args"></param>
        public static void SaveButton_OnClickStep(IInsertTeam form, EventArgs args)
        {
            IWebDialogService dialogService = form.Services.Get <IWebDialogService>();
            // create the new team
            IOwner ownerTeam = EntityFactory.Create <IOwner>();

            ownerTeam.OwnerDescription = form.OwnerDescription.Text;
            ownerTeam.Type             = OwnerType.Team;

            if (!ownerTeam.IsValidName(form.OwnerDescription.Text))
            {
                string msg = form.GetResource("InvalidNameMessage").ToString();
                if (dialogService != null && !string.IsNullOrEmpty(msg))
                {
                    dialogService.ShowMessage(msg, form.GetResource("InvalidNameMessageTitle").ToString());
                }

                return;
            }

            if (ownerTeam.OwnerNameExists(form.OwnerDescription.Text))
            {
                string msg = form.GetResource("DuplicateOwnerMessage").ToString();
                if (dialogService != null && !string.IsNullOrEmpty(msg))
                {
                    dialogService.ShowMessage(msg, form.GetResource("DuplicateOwnerTitle").ToString());
                }

                return;
            }

            ownerTeam.Save();

            // set a default profile
            IOwnerSecurityProfile securityProfile = EntityFactory.GetById <IOwnerSecurityProfile>("PROF00000001");

            if (form.securityProfileLookup.LookupResultValue != null)
            {
                securityProfile = form.securityProfileLookup.LookupResultValue as IOwnerSecurityProfile;
            }

            // get a team object.  This is a view of the owner object
            ITeam team = EntityFactory.GetById <ITeam>(ownerTeam.Id);

            // add an ownerJoin record for the new team.  Both the parent and the
            // child ids will point to the team
            team.AddMemberWithSecurityProfile(ownerTeam, securityProfile);

            // get the selected owner of the team.  This will be a user
            IUser teamOwnerUser = form.DefaultOwner.LookupResultValue as IUser;

            if (teamOwnerUser != null)
            {
                // add the team owner as a member of the team
                IOwnerSecurityProfile ownerSecurityProfile = EntityFactory.GetById <IOwnerSecurityProfile>("PROF00000003");
                team.AddMemberWithSecurityProfile(teamOwnerUser.DefaultOwner, ownerSecurityProfile);
            }
            MySlx.MainView.Show <ITeam>(ownerTeam.Id.ToString());
        }
Esempio n. 2
0
        public static void SaveButton_OnClickStep(IInsertDepartment form, EventArgs args)
        {
            IWebDialogService dialogService = form.Services.Get <IWebDialogService>();
            IOwner            owner         = EntityFactory.Create <IOwner>();

            owner.OwnerDescription = form.OwnerDescription.Text;
            owner.Type             = OwnerType.Department;
            if (!owner.IsValidName(form.OwnerDescription.Text))
            {
                string msg = form.GetResource("InvalidNameMessage").ToString();
                if (dialogService != null && !string.IsNullOrEmpty(msg))
                {
                    dialogService.ShowMessage(msg, form.GetResource("InvalidNameMessageTitle").ToString());
                }

                return;
            }

            if (owner.OwnerNameExists(form.OwnerDescription.Text))
            {
                string msg = form.GetResource("DuplicateOwnerMessage").ToString();
                if (dialogService != null && !string.IsNullOrEmpty(msg))
                {
                    dialogService.ShowMessage(msg, form.GetResource("DuplicateOwnerTitle").ToString());
                }

                return;
            }

            owner.Save();

            IOwnerSecurityProfile securityProfile = EntityFactory.GetById <IOwnerSecurityProfile>("PROF00000001");

            if (form.securityProfileLookup.LookupResultValue != null)
            {
                securityProfile = form.securityProfileLookup.LookupResultValue as IOwnerSecurityProfile;
            }

            // get a department object.  This is a view of the owner object
            IDepartment department = EntityFactory.GetById <IDepartment>(owner.Id);

            // add an ownerJoin record for the new team.  Both the parent and the
            // child ids will point to the team
            department.AddMemberWithSecurityProfile(owner, securityProfile);

            HttpContext.Current.Response.Redirect(string.Format("~/Department.aspx?entityId={0}", owner.Id.ToString()), false);
        }