Ejemplo n.º 1
0
        public virtual async Task <_ <OrgMemberEntity> > AddMember(OrgMemberEntity model)
        {
            model.Should().NotBeNull();
            model.OrgUID.Should().NotBeNullOrEmpty();
            model.UserUID.Should().NotBeNullOrEmpty();

            var org = await this._orgRepo.GetFirstAsNoTrackAsync(x => x.UID == model.OrgUID);

            org.Should().NotBeNull();

            if (org.MemeberCount >= 3000)
            {
                return(new _ <OrgMemberEntity>().SetErrorMsg("成员数达到上限"));
            }

            await this._orgMemberRepo.DeleteWhereAsync(x => x.UserUID == model.UserUID && x.OrgUID == model.OrgUID);

            var res = await this._orgMemberRepo.AddEntity_(model);

            {
                //更新数量
                await this.UpdateOrgMemberCount(model.OrgUID);
            }

            return(res);
        }
Ejemplo n.º 2
0
        public async Task <_ <OrgMemberEntity> > AddMember(OrgMemberEntity model)
        {
            var org = await this.QueryOneAsync(x => x.Id == model.OrgUID);

            org.Should().NotBeNull();

            if (org.MemeberCount >= 3000)
            {
                return(new _ <OrgMemberEntity>().SetErrorMsg("成员数达到上限"));
            }

            var db = this.Database;

            var org_member_set = db.Set <OrgMemberEntity>();

            org_member_set.RemoveRange(org_member_set.Where(x => x.UserUID == model.UserUID && x.OrgUID == model.OrgUID));
            org_member_set.Add(model);

            await db.SaveChangesAsync();

            {
                //更新数量
                await this.UpdateOrgMemberCount(model.OrgUID);
            }

            return(new _ <OrgMemberEntity>().SetSuccessData(model));
        }
Ejemplo n.º 3
0
        public async Task <IActionResult> AddAdminMember(string phone, string org_uid)
        {
            var org = await this._orgService.GetOrgByUID(org_uid);

            org.Should().NotBeNull();

            var map = new UserEntity()
            {
                UserName = phone + "@" + org.OrgName,
                PassWord = "******"
            };
            var reg_res = await this._userLogin.AddAccount(map);

            reg_res.ThrowIfNotSuccess();
            var user          = reg_res.Data;
            var map_orgmember = new OrgMemberEntity()
            {
                OrgUID         = org_uid,
                UserUID        = user.UID,
                IsOwner        = 1,
                MemberApproved = 1,
            };
            var res = await this._orgService.AddMember(map_orgmember);

            res.ThrowIfNotSuccess();

            return(SuccessJson());
        }
Ejemplo n.º 4
0
        public virtual async Task <_ <OrgMemberEntity> > AddMember(OrgMemberEntity model)
        {
            model.Should().NotBeNull();
            model.OrgUID.Should().NotBeNullOrEmpty();
            model.UserUID.Should().NotBeNullOrEmpty();

            var res = await this._orgRepo.AddMember(model);

            return(res);
        }
Ejemplo n.º 5
0
        public static IServiceProvider InitOrgInfo(this IServiceProvider app)
        {
            using (var s = app.CreateScope())
            {
                var db             = s.ServiceProvider.Resolve_ <IMSRepository <UserEntity> >().Database;
                var org_set        = db.Set <OrgEntity>();
                var org_member_set = db.Set <OrgMemberEntity>();
                //如果组织为空就创建假数据
                if (!org_set.Any(x => x.UID == default_org_uid))
                {
                    //创建组织
                    var org = new OrgEntity()
                    {
                        OrgName = "体验水司",
                        UserUID = admin_uid,
                    }.InitSelf();

                    org.UID = default_org_uid;

                    org_set.Add(org);
                    //新建默认租户
                    db.SaveChanges();
                }
                if (!org_member_set.Any(x => x.OrgUID == default_org_uid && x.UserUID == admin_uid))
                {
                    var map = new OrgMemberEntity()
                    {
                        IsOwner        = 1,
                        OrgUID         = default_org_uid,
                        UserUID        = admin_uid,
                        MemberApproved = 1,
                        Flag           = (int)MemberRoleEnum.管理员
                    }.InitSelf("auto-mb");
                    org_member_set.Add(map);
                    db.SaveChanges();
                }
            }
            return(app);
        }