Пример #1
0
        /// <summary>
        /// 新增房源
        /// </summary>
        /// <param name="house"></param>
        /// <returns></returns>
        public long AddNew(HouseAddNewDTO house)
        {
            HouseEntity houseEntity = new HouseEntity();

            houseEntity.Address = house.Address;
            houseEntity.Area    = house.Area;
            using (ZSZDbContext ctx = new Service.ZSZDbContext())
            {
                BaseService <AttachmentEntity> attBs = new Service.BaseService <Entities.AttachmentEntity>(ctx);
                //获取house.AttachmentIds为主键的房屋配套设施
                var atts = attBs.GetAll().Where(a => house.AttachmentIds.Contains(a.Id));
                foreach (var att in atts)
                {
                    houseEntity.Attachments.Add(att);
                }
                houseEntity.CheckInDateTime  = house.CheckInDateTime;
                houseEntity.CommunityId      = house.CommunityId;
                houseEntity.DecorateStatusId = house.DecorateStatusId;
                houseEntity.Description      = house.Description;
                houseEntity.Direction        = house.Direction;
                houseEntity.FloorIndex       = house.FloorIndex;
                //houseEntity.HousePics 新增后再单独添加
                houseEntity.LookableDateTime = house.LookableDateTime;
                houseEntity.MonthRent        = house.MonthRent;
                houseEntity.OwnerName        = house.OwnerName;
                houseEntity.OwnerPhoneNum    = house.OwnerPhoneNum;
                houseEntity.RoomTypeId       = house.RoomTypeId;
                houseEntity.StatusId         = house.StatusId;
                houseEntity.TotalFloorCount  = house.TotalFloorCount;
                houseEntity.TypeId           = house.TypeId;
                ctx.Houses.Add(houseEntity);
                ctx.SaveChanges();
                return(houseEntity.Id);
            }
        }
Пример #2
0
 public AttachmentDTO[] GetAll()
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <AttachmentEntity> bs = new Service.BaseService <Entities.AttachmentEntity>(ctx);
         return(bs.GetAll().ToList().Select(a => ToDTO(a)).ToArray());
     }
 }
Пример #3
0
 /// <summary>
 /// 求CityId这个所在城市下区域信息
 /// </summary>
 /// <param name="cityId"></param>
 /// <returns></returns>
 public RegionDTO[] GetAll(long cityId)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <RegionEntity> bs = new Service.BaseService <Entities.RegionEntity>(ctx);
         return(bs.GetAll().Include(r => r.City).Where(r => r.CityId == cityId).ToList().Select(r => ToDTO(r)).ToArray());
     }
 }
Пример #4
0
 public PermissionDTO[] GetAll()
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <PermissionEntity> perms = new Service.BaseService <Entities.PermissionEntity>(ctx);
         return(perms.GetAll().ToList().Select(p => ToDTO(p)).ToArray());
     }
 }
Пример #5
0
 public void MarkDeleted(long id)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <PermissionEntity> bs = new Service.BaseService <Entities.PermissionEntity>(ctx);
         bs.MarkDeleted(id);
     }
 }
Пример #6
0
 public HouseAppointmentDTO GetById(long id)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <HouseAppointmentEntity> bs = new Service.BaseService <Entities.HouseAppointmentEntity>(ctx);
         var houseApp = bs.GetAll().Include(a => a.House).Include(nameof(HouseAppointmentEntity.House) + "." + nameof(HouseEntity.Community)).Include(a => a.FollowAdminUser).Include
                        //Include("House.Community.Region")
                            (nameof(HouseAppointmentEntity.House) + "." + nameof(HouseEntity.Community) + "." + nameof(CommunityEntity.Region)).AsNoTracking().SingleOrDefault(a => a.Id == id);
         if (houseApp == null)
         {
             return(null);
         }
         return(ToDTO(houseApp));
     }
 }
Пример #7
0
 public HousePicDTO[] GetPics(long houseId)
 {
     using (ZSZDbContext ctx = new ZSZDbContext())
     {
         BaseService <HousePicEntity> bs = new Service.BaseService <Entities.HousePicEntity>(ctx);
         var housePics           = bs.GetAll().Where(h => h.HouseId == houseId);
         List <HousePicDTO> list = new List <HousePicDTO>();
         foreach (var housePic in housePics)
         {
             HousePicDTO dto = new HousePicDTO();
             dto.Url      = housePic.Url;
             dto.ThumbUrl = housePic.Url;
             dto.Id       = housePic.Id;
             list.Add(dto);
         }
         return(list.ToArray());
     }
 }
Пример #8
0
 /// <summary>
 /// 为roleId增加权限,新增权限
 /// </summary>
 /// <param name="roleId"></param>
 /// <param name="permIds"></param>
 public void AddPermIds(long roleId, long[] permIds)
 {
     using (ZSZDbContext ctx = new Service.ZSZDbContext())
     {
         BaseService <RoleEntity> roleBs = new Service.BaseService <Entities.RoleEntity>(ctx);
         var role = roleBs.GetById(roleId);
         if (role == null)
         {
             throw new ArgumentException("角色不存在" + roleId);
         }
         BaseService <PermissionEntity> perm = new Service.BaseService <Entities.PermissionEntity>(ctx);
         var perms = perm.GetAll().ToList().Where(p => permIds.Contains(p.Id));
         foreach (var p in perms)
         {
             role.Permissions.Add(p);
         }
         ctx.SaveChanges();
     }
 }
Пример #9
0
        /// <summary>
        /// 抢单
        /// </summary>
        /// <param name="adminUserId"></param>
        /// <param name="houseAppointmentId"></param>
        /// <returns></returns>
        public bool Follow(long adminUserId, long houseAppointmentId)
        {
            using (ZSZDbContext ctx = new Service.ZSZDbContext())
            {
                BaseService <HouseAppointmentEntity> bs = new Service.BaseService <HouseAppointmentEntity>(ctx);
                var app = bs.GetById(houseAppointmentId);
                if (app == null)
                {
                    throw new ArgumentException("不存在的订单Id");
                }
                //FollowAdminUserId不为null,要么已经自己抢过,要么早早被别人抢了
                if (app.FollowAdminUserId != null)
                {
                    return(app.FollowAdminUserId == adminUserId);

                    /* if (app.FollowAdminUserId==adminUserId)
                     * {
                     *   return true;
                     * }
                     * else
                     * {
                     *   return false;
                     * }
                     */
                }
                //如果为null,说明有抢的机会
                app.FollowAdminUserId = adminUserId;
                try
                {
                    ctx.SaveChanges();
                    return(true);
                }
                //如果抛出DbUpdateConcurrencyException这个异常说明抢单失败
                catch (DbUpdateConcurrencyException)
                {
                    return(false);
                }
            }
        }
Пример #10
0
        public void SetValue(string name, string value)
        {
            using (ZSZDbContext ctx = new Service.ZSZDbContext())
            {
                BaseService <SettingEntity> bs = new Service.BaseService <SettingEntity>(ctx);

                /*
                 * bool exsits = GetAll().Any(s => s.Name == name);
                 * SettingEntity setting = new Entities.SettingEntity();
                 * if (exsits)
                 * {
                 *   setting.Value = value;
                 * }
                 * else
                 * {
                 *   setting.Name = name;
                 *   setting.Value = value;
                 * }
                 * ctx.SaveChanges();
                 */
                var setting = bs.GetAll().SingleOrDefault(s => s.Name == name);
                if (setting != null)
                {
                    ctx.Settings.Add(new SettingEntity()
                    {
                        Value = value
                    });
                }
                else
                {
                    ctx.Settings.Add(new SettingEntity {
                        Value = value, Name = name
                    });
                }
                ctx.SaveChanges();
            }
        }