예제 #1
0
        partial void OnCreated(object sender, BusinessRulesEventArgs <KstProxyUser> e)
        {
            var contextRequest = e.ContextRequest;


            var user = new secUser()
            {
                GuidUser = e.Item.GuidUser
            };

            e.ContextRequest.PreventInterceptors = true;
            var role = SFS.Core.Security.BR.secRolesBR.Instance.GetBy(p => p.GuidRole == e.Item.GuidRole, e.ContextRequest).FirstOrDefault();

            Guid?guidCompany     = contextRequest.Company.GuidCompany;
            var  module          = SFS.Core.Cache.Caching.SystemObjects.GetModuleByKey("KSTime");
            Guid?guidModule      = module.GuidModule;
            var  userCompanyRole = SFS.Core.Security.BR.secUserCompaniesBR.Instance.GetBy(p => p.GuidUser == user.GuidUser && p.GuidCompany == guidCompany && p.GuidModule == guidModule).FirstOrDefault();

            userCompanyRole             = new SFS.Core.Security.BusinessObjects.secUserCompany();
            userCompanyRole.GuidUser    = user.GuidUser;
            userCompanyRole.GuidRole    = role.GuidRole;
            userCompanyRole.GuidModule  = guidModule;
            userCompanyRole.GuidCompany = guidCompany.Value;

            userCompanyRole = SFS.Core.Security.BR.secUserCompaniesBR.Instance.Create(userCompanyRole, contextRequest);



            this.NotifyUserAsync(new secUser()
            {
                GuidUser = e.Item.GuidUser, Email = e.Item.Email, FirstName = e.Item.FirstName, LastName = e.Item.LastName
            }, role.RoleName, contextRequest);
        }
예제 #2
0
        private void Updating(KstProxyUser user, ContextRequest contextRequest)
        {
            Guid?guidUser = user.GuidUser;
            var  sysUser  = SFS.Core.Security.BR.secUsersBR.Instance.GetBy(p => p.GuidUser == guidUser, contextRequest).FirstOrDefault();

            if (sysUser != null)
            {
                List <string> props = new List <string>();
                sysUser.UserName = user.Username;
                if (contextRequest.CustomQuery.SpecificProperties.Contains(KstProxyUser.PropertyNames.Username))
                {
                    props.Add("UserName");
                }
                sysUser.FirstName = user.FirstName;
                if (contextRequest.CustomQuery.SpecificProperties.Contains(KstProxyUser.PropertyNames.FirstName))
                {
                    props.Add("FirstName");
                }
                sysUser.LastName = user.LastName;
                if (contextRequest.CustomQuery.SpecificProperties.Contains(KstProxyUser.PropertyNames.LastName))
                {
                    props.Add("LastName");
                }

                if (!string.IsNullOrEmpty(user.Password))
                {
                    if (contextRequest.CustomQuery.SpecificProperties.Contains(KstProxyUser.PropertyNames.Password))
                    {
                        props.Add("Password");
                    }
                    sysUser.Password = SFS.Core.Globals.Security.EncryptString(user.Password);
                    user.Password    = null;
                }
                sysUser.Email = user.Email;
                if (contextRequest.CustomQuery.SpecificProperties.Contains(KstProxyUser.PropertyNames.Email))
                {
                    props.Add("Email");
                }
                SFS.Core.Security.BR.secUsersBR.Instance.UpdateAgile(sysUser, contextRequest.CopySafe(), props.ToArray());
            }



            if (user.GuidRole != null)
            {
                Guid?guidCompany     = contextRequest.Company.GuidCompany;
                var  module          = SFS.Core.Cache.Caching.SystemObjects.GetModuleByKey("KSTime");
                Guid?guidModule      = module.GuidModule;
                var  userCompanyRole = SFS.Core.Security.BR.secUserCompaniesBR.Instance.GetBy(p => p.GuidUser == guidUser && p.GuidCompany == guidCompany && p.GuidModule == guidModule).FirstOrDefault();

                if (userCompanyRole != null)
                {
                    userCompanyRole.GuidRole = user.GuidRole;
                    SFS.Core.Security.BR.secUserCompaniesBR.Instance.UpdateAgile(userCompanyRole, contextRequest.CopySafe(), "GuidRole");
                }
                else
                {
                    userCompanyRole             = new SFS.Core.Security.BusinessObjects.secUserCompany();
                    userCompanyRole.GuidUser    = guidUser;
                    userCompanyRole.GuidRole    = user.GuidRole;
                    userCompanyRole.GuidModule  = guidModule;
                    userCompanyRole.GuidCompany = guidCompany.Value;

                    userCompanyRole = SFS.Core.Security.BR.secUserCompaniesBR.Instance.Create(userCompanyRole, contextRequest);
                }
            }
        }