Beispiel #1
0
        public IActionResult RemoveUserCollection(long houseId, string source)
        {
            var user = ((ClaimsIdentity)HttpContext.User.Identity);

            if (user == null || user.FindFirst(ClaimTypes.NameIdentifier) == null)
            {
                return(Json(new { successs = false, error = "请登录后再收藏房源." }));
            }
            var userId = user.FindFirst(ClaimTypes.NameIdentifier).Value;

            if (string.IsNullOrEmpty(userId) || userId == "0")
            {
                return(Json(new { successs = false, error = "请登录后再收藏房源." }));
            }
            var house = HouseDapper.GetHouseID(houseId, source);

            if (house == null)
            {
                return(Json(new { successs = false, error = "房源信息不存在,请刷新页面后重试." }));
            }
            var userCollection = new UserCollection();

            userCollection.UserID    = long.Parse(userId);
            userCollection.HouseID   = houseId;
            userCollection.Source    = house.Source;
            userCollection.HouseCity = house.LocationCityName;
            UserCollectionDapper.InsertUser(userCollection);
            return(Json(new { success = true, message = "收藏成功." }));;
        }
        public void AddOne(long userId, UserCollection userCollection)
        {
            var house = _houseDapper.GetHouseID(userCollection.HouseID, userCollection.Source);

            if (house == null)
            {
                throw new NotFoundException("房源信息不存在,请刷新页面后重试");
            }
            userCollection.UserID    = userId;
            userCollection.Source    = house.Source;
            userCollection.HouseCity = house.LocationCityName;
            _dapper.InsertUser(userCollection);
        }
        public IActionResult Create(long userId, [FromBody] UserCollection userCollection, [FromHeader] string token)
        {
            var userInfo = userService.GetUserInfo(userId, token);

            if (userInfo == null)
            {
                return(Ok(new { success = false, error = "用户未登陆,无法进行操作。" }));
            }
            var house = houseDapper.GetHouseID(userCollection.HouseID, userCollection.Source);

            if (house == null)
            {
                return(Ok(new { successs = false, error = "房源信息不存在,请刷新页面后重试." }));
            }
            userCollection.UserID    = userId;
            userCollection.Source    = house.Source;
            userCollection.HouseCity = house.LocationCityName;
            userCollectionDapper.InsertUser(userCollection);
            return(Ok(new { success = true, message = "收藏成功." }));;
        }
        public IActionResult AddUserCollection(long houseId, string source)
        {
            var userID = GetUserID();

            if (userID == 0)
            {
                return(Json(new { IsSuccess = false, error = "用户未登陆,无法进行操作。" }));
            }
            var house = _houseDapper.GetHouseID(houseId, source);

            if (house == null)
            {
                return(Json(new { successs = false, error = "房源信息不存在,请刷新页面后重试." }));
            }
            var userCollection = new UserCollection();

            userCollection.UserID    = userID;
            userCollection.HouseID   = houseId;
            userCollection.Source    = house.Source;
            userCollection.HouseCity = house.LocationCityName;
            _userCollectionDapper.InsertUser(userCollection);
            return(Json(new { success = true, message = "收藏成功." }));;
        }