Ejemplo n.º 1
0
        public async Task <ResponseMessage <bool> > GiveLike(UserInfo user, [FromRoute] string id)
        {
            ResponseMessage <bool> response = new ResponseMessage <bool>();

            if (!ModelState.IsValid)
            {
                response.Code    = ResponseCodeDefines.ModelStateInvalid;
                response.Message = ModelState.GetAllErrors();
                Logger.LogWarning($"用户{user?.UserName ?? ""}({user?.Id ?? ""})点赞(GiveLike)模型验证失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n(id){id ?? ""}");
                return(response);
            }
            try
            {
                if (!await _commentManager.ValGiveLike(user.Id, id))
                {
                    await _commentManager.CreateGiveLikeAsync(user.Id, id, HttpContext.RequestAborted);
                }
                else
                {
                    await _commentManager.CancelGiveLikeAsync(user.Id, id, HttpContext.RequestAborted);
                }
            }
            catch (Exception e)
            {
                response.Code    = ResponseCodeDefines.ServiceError;
                response.Message = e.Message;
                Logger.LogError($"用户{user?.UserName ?? ""}({user?.Id ?? ""})点赞(GiveLike)请求失败:\r\n{response.Message ?? ""},\r\n请求参数为:\r\n(id){id ?? ""}");
            }
            return(response);
        }