コード例 #1
0
ファイル: Repository.cs プロジェクト: JoseMilhazes/DSS4
        public void DeleteProfile(zAppDev.DotNet.Framework.Identity.Model.Profile profile, bool doNotCallDeleteForThis = false, bool isCascaded = false, object calledBy = null)
        {
            if (profile == null || profile.IsTransient())
            {
                return;
            }
            foreach (var toDelete in profile.Settings)
            {
                profile.RemoveSettings(toDelete);
                DeleteProfileSetting(toDelete, false, isCascaded);
            }
            var _ApplicationUserApplicationUserProfilecount = this.Get <zAppDev.DotNet.Framework.Identity.Model.ApplicationUser>(ap => ap.Profile == profile).Count;

            if (
                (calledBy != null)
                &&
                (
                    (calledBy.GetType() == typeof(zAppDev.DotNet.Framework.Identity.Model.ApplicationUser) || calledBy.GetType().FullName == "ApplicationUserProxy")
                )
                )
            {
                _ApplicationUserApplicationUserProfilecount--;
            }
            if (_ApplicationUserApplicationUserProfilecount > 0)
            {
                var cs = new System.Data.ConstraintException("At least one ApplicationUser exists so Profile cannot be deleted");
                cs.Data["Entity"]       = "ApplicationUser";
                cs.Data["PropertyName"] = "Profile";
                cs.Data["Multiplicity"] = "0..1";
                throw cs;
            }
            if (!doNotCallDeleteForThis)
            {
                Delete <zAppDev.DotNet.Framework.Identity.Model.Profile>(profile, isCascaded);
            }
        }