public async Task <List <Community> > GetListAsync(CommunityDto dto, CancellationToken token = default)
 {
     using (var db = new GuoGuoCommunityContext())
     {
         return(await db.Communities.Where(x => x.IsDeleted == false && x.StreetOfficeId.ToString() == dto.StreetOfficeId).ToListAsync(token));
     }
 }
        private async Task <bool> OnDelete(GuoGuoCommunityContext db, CommunityDto dto, CancellationToken token = default)
        {
            //小区
            if (await db.SmallDistricts.Where(x => x.IsDeleted == false && x.CommunityId.ToString() == dto.Id).FirstOrDefaultAsync(token) != null)
            {
                return(true);
            }

            //公告
            if (await db.Announcements.Where(x => x.IsDeleted == false && x.CommunityId == dto.Id).FirstOrDefaultAsync(token) != null)
            {
                return(true);
            }

            //投诉
            if (await db.Votes.Where(x => x.IsDeleted == false && x.CommunityId == dto.Id).FirstOrDefaultAsync(token) != null)
            {
                return(true);
            }

            //用户
            if (await db.Users.Where(x => x.CommunityId == dto.Id.ToString() && x.IsDeleted == false).FirstOrDefaultAsync(token) != null)
            {
                return(true);
            }

            return(false);
        }
        public async Task DeleteAsync(CommunityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                if (!Guid.TryParse(dto.Id, out var uid))
                {
                    throw new NotImplementedException("社区信息不正确!");
                }
                var community = await db.Communities.Where(x => x.Id == uid && x.IsDeleted == false).FirstOrDefaultAsync(token);

                if (community == null)
                {
                    throw new NotImplementedException("该社区不存在!");
                }

                if (await OnDelete(db, dto, token))
                {
                    throw new NotImplementedException("该社区下存在下级小区数据");
                }

                community.LastOperationTime   = dto.OperationTime;
                community.LastOperationUserId = dto.OperationUserId;
                community.DeletedTime         = dto.OperationTime;
                community.IsDeleted           = true;
                await db.SaveChangesAsync(token);
            }
        }
        public async Task <List <Community> > GetAllIncludeAsync(CommunityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                var list = await db.Communities.Include(x => x.StreetOffice).Where(x => x.IsDeleted == false).ToListAsync(token);

                if (!string.IsNullOrWhiteSpace(dto.State))
                {
                    list = list.Where(x => x.State == dto.State).ToList();
                }
                if (!string.IsNullOrWhiteSpace(dto.City))
                {
                    list = list.Where(x => x.City == dto.City).ToList();
                }
                if (!string.IsNullOrWhiteSpace(dto.Region))
                {
                    list = list.Where(x => x.Region == dto.Region).ToList();
                }
                if (!string.IsNullOrWhiteSpace(dto.StreetOfficeId))
                {
                    list = list.Where(x => x.StreetOfficeId.ToString() == dto.StreetOfficeId).ToList();
                }
                if (!string.IsNullOrWhiteSpace(dto.Name))
                {
                    list = list.Where(x => x.Name.Contains(dto.Name)).ToList();
                }

                return(list);
            }
        }
        public async Task UpdateAsync(CommunityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                if (!Guid.TryParse(dto.Id, out var uid))
                {
                    throw new NotImplementedException("社区信息不正确!");
                }
                var community = await db.Communities.Where(x => x.Id == uid).FirstOrDefaultAsync(token);

                if (community == null)
                {
                    throw new NotImplementedException("该社区不存在!");
                }

                if (await db.Communities.Where(x => x.Name == dto.Name && x.IsDeleted == false && x.StreetOfficeId == community.StreetOfficeId && x.Id != uid).FirstOrDefaultAsync(token) != null)
                {
                    throw new NotImplementedException("该社区名称已存在!");
                }
                community.Name = dto.Name;
                community.LastOperationTime   = dto.OperationTime;
                community.LastOperationUserId = dto.OperationUserId;
                await OnUpdate(db, community, token);

                await db.SaveChangesAsync(token);
            }
        }
Example #6
0
 /// <summary>
 ///
 /// </summary>
 /// <param name="community"></param>
 /// <returns></returns>
 internal IDbQuery QueryInsertCommunity(CommunityDto community)
 {
     return(DbFluent.InsertQuery(Table("Community"), true)
            .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate"),
                                     JoinCondition <DbCommunity, DbRegionalDirectorate>("community", null))));
     //.WithFields(p => Fields_InsertCommunity(p, community));
 }
Example #7
0
        /// <summary>
        /// 更新
        /// </summary>
        /// <param name="input"></param>
        /// <returns></returns>
        public async Task UpdateAsync(CommunityDto input)
        {
            var entity = await _communityRepository.GetAsync(input.Id);

            var community = input.MapTo(entity);

            await _communityRepository.UpdateAsync(community);
        }
Example #8
0
 public Community TransformToCommunityEntity(CommunityDto communityDto)
 {
     if (communityDto == null)
     {
         return(null);
     }
     return(new Community
     {
         Id = communityDto.Id,
         Email = communityDto.Email,
         Name = communityDto.Name
     });
 }
Example #9
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="code"></param>
        /// <param name="isPartialUpdate"></param>
        /// <param name="community"></param>
        /// <returns></returns>
        internal IDbQuery QueryUpdateCommunity(string code, bool isPartialUpdate, CommunityDto community)
        {
            var query = DbFluent.UpdateQuery(Table <DbCommunity>("community"))
                        .From(
                DbFluent.TableAsJoin(DbQueryJoinKind.Left, Table("RegionalDirectorate", "directorate"),
                                     JoinCondition("Community_RegionalDirectorate")));

            if (!isPartialUpdate || community?.Code?.Length > 0)
            {
                query.AddField(p => DbFluent.FieldAsParameter(nameof(DbCommunity.Code), p.UseParameter("code", nameof(DbCommunity.Code))));
            }

            return(query);
        }
Example #10
0
        public async Task <Community> AddAsync(CommunityDto dto, CancellationToken token = default)
        {
            using (var db = new GuoGuoCommunityContext())
            {
                if (!Guid.TryParse(dto.StreetOfficeId, out var streetOfficeId))
                {
                    throw new NotImplementedException("街道办信息不正确!");
                }
                var streetOffice = await db.StreetOffices.Where(x => x.Id == streetOfficeId && x.IsDeleted == false).FirstOrDefaultAsync(token);

                if (streetOffice == null)
                {
                    throw new NotImplementedException("街道办信息不存在!");
                }

                var community = await db.Communities.Where(x => x.Name == dto.Name && x.IsDeleted == false && x.StreetOfficeId == streetOfficeId).FirstOrDefaultAsync(token);

                if (community != null)
                {
                    throw new NotImplementedException("该社区已存在!");
                }
                var entity = db.Communities.Add(new Community
                {
                    Name   = dto.Name,
                    City   = dto.City,
                    Region = dto.Region,
                    State  = dto.State,
                    CreateOperationTime   = dto.OperationTime,
                    CreateOperationUserId = dto.OperationUserId,
                    LastOperationTime     = dto.OperationTime,
                    LastOperationUserId   = dto.OperationUserId,
                    StreetOfficeId        = streetOfficeId,
                    //StreetOfficeName = streetOffice.Name
                });
                await db.SaveChangesAsync(token);

                return(entity);
            }
        }
Example #11
0
 public Task <List <Community> > GetListIncludeAsync(CommunityDto dto, CancellationToken token = default)
 {
     throw new NotImplementedException();
 }