示例#1
0
        /// <summary>
        /// 删除绑定的小区
        /// </summary>
        /// <param name="id">小区ID</param>
        /// <returns></returns>
        public JsonResult DelPlace(int id)
        {
            JsonModel jm = new JsonModel();

            try
            {
                var owner = GetCurrentUser();
                IPropertyPlaceBLL placeBll = BLLFactory <IPropertyPlaceBLL> .GetBLL("PropertyPlaceBLL");

                var place = placeBll.GetEntity(p => p.Id == id && p.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

                //如果该用户要删除的小区不存在
                if (place == null || owner.UserPlaces.Count(up => up.PropertyPlaceId == place.Id) <= 0)
                {
                    jm.Msg = "该用户未绑定该小区";
                }
                else
                {
                    //删除拥有小区的验证
                    IPropertyIdentityVerificationBLL identityVerificationBll = BLLFactory <IPropertyIdentityVerificationBLL> .GetBLL("PropertyIdentityVerificationBLL");

                    if (place.PlaceType == ConstantParam.PLACE_TYPE_HOUSE)
                    {
                        var identityVerification = identityVerificationBll.GetEntity(v => v.AppUserId == owner.Id && v.DoorId != null && v.BuildDoor.BuildUnit.Build.PropertyPlaceId == place.Id);
                        if (identityVerification != null)
                        {
                            identityVerificationBll.Delete(identityVerification);
                        }
                    }
                    else
                    {
                        var identityVerification = identityVerificationBll.GetEntity(v => v.AppUserId == owner.Id && v.BuildCompanyId != null && v.BuildCompany.PropertyPlaceId == place.Id);
                        if (identityVerification != null)
                        {
                            identityVerificationBll.Delete(identityVerification);
                        }
                    }
                    //删除拥有的小区
                    IUserBLL ownerBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

                    ownerBll.ExecuteSql("delete from R_UserPlace where UserId=" + owner.Id + " and PropertyPlaceId=" + id);
                }
            }
            catch
            {
                jm.Msg = "删除发生异常";
            }

            return(Json(jm, JsonRequestBehavior.AllowGet));
        }
        public ApiResultModel CancelCollectedTopic(CollectTopicModel model)
        {
            ApiResultModel resultModel = new ApiResultModel();

            try
            {
                //根据用户ID查找业主
                IUserBLL userBll = BLLFactory <IUserBLL> .GetBLL("UserBLL");

                T_User user = userBll.GetEntity(u => u.Id == model.UserId && u.DelFlag == ConstantParam.DEL_FLAG_DEFAULT);

                if (user != null)
                {
                    //如果验证Token不通过或已过期
                    if (DateTime.Now > user.TokenInvalidTime || model.Token != user.Token)
                    {
                        resultModel.Msg = APIMessage.TOKEN_INVALID;
                        return(resultModel);
                    }

                    //更新最近登录时间和Token失效时间
                    user.LatelyLoginTime  = DateTime.Now;
                    user.TokenInvalidTime = DateTime.Now.AddDays(Convert.ToInt32(PropertyUtils.GetConfigParamValue("TokenInvalid")));

                    userBll.Update(user);
                    //如果有收藏主题,取消收藏
                    var userPostBarTopic = user.UserPostBarTopics.FirstOrDefault(m => m.PostBarTopicId == model.TopicId && m.UserId == model.UserId);

                    if (userPostBarTopic != null)
                    {
                        userBll.ExecuteSql(string.Format("delete from R_UserPostBarTopic where userid={0} and postbartopicid={1}", model.UserId, model.TopicId));
                    }
                }
                else
                {
                    resultModel.Msg = APIMessage.NO_USER;
                }
            }
            catch
            {
                resultModel.Msg = APIMessage.REQUEST_EXCEPTION;
            }

            return(resultModel);
        }