Exemplo n.º 1
0
        /// <summary>
        /// 判断用户是否收藏.
        /// </summary>
        /// <param name="query">.</param>
        /// <returns>.</returns>
        public async Task <BaseResult <IsCollectDTO> > IsCollect(IsCollectDTO query)
        {
            StringBuilder sb = new StringBuilder();

            sb.AppendFormat(@"SELECT * FROM dbo.tbUserCollect WHERE userId = {0} AND objId = {1} AND type={2}", query.userId, query.objId, query.type);
            var result = new BaseResult <IsCollectDTO>();

            try
            {
                var i = await DetailBy(sb.ToString());

                if (i != null)
                {
                    query.isCollect = true;
                }
                else
                {
                    query.isCollect = false;
                }
                result.code = ResultKey.RETURN_SUCCESS_CODE;
                result.data = new PageData <IsCollectDTO> {
                    list = new List <IsCollectDTO>()
                    {
                        query
                    }, total = 1
                };
                result.desc = ResultKey.RETURN_SUCCESS_DESC;
            }
            catch (Exception ex)
            {
                NlogHelper.InfoLog(ex.Message);
                throw new Exception(ex.Message);
            }
            return(result);
        }
Exemplo n.º 2
0
 public async Task <BaseResult <IsCollectDTO> > IsCollect(IsCollectDTO query)
 {
     if (query.userId == 0 || query.objId == 0 || query.type == 3)
     {
         throw new Exception("参数接受错误");
     }
     return(await userCollectRepository.IsCollect(query));
 }
Exemplo n.º 3
0
        public async Task <BaseResult <UserCollectEntity> > Collect(UserCollectEntity entity)
        {
            IsCollectDTO query = new IsCollectDTO()
            {
                objId  = entity.objId,
                userId = entity.userId,
                type   = entity.type,
            };
            var isCollect = await userCollectRepository.IsCollect(query);

            if (isCollect.code == "0")
            {
                if (isCollect.data.list[0].isCollect == true)
                {
                    throw new Exception("该对象已经被收藏");
                }
            }
            return(await userCollectRepository.Add(entity));
        }