public async Task VoteContest([FromBody] ContestVoteModel model) { var userId = userManager.GetUserId(User); var result = model.VoteType switch { 1 => await voteService.UpvoteContestAsync(userId, model.ContestId), 2 => await voteService.DownvoteContestAsync(userId, model.ContestId), _ => false }; if (!result) { throw new BadRequestException("评价失败"); } }
public static async Task <ContestVoteResults> SaveContestVote(ContestVote vote) { APIService srv = new APIService(); ContestVoteModel model = new ContestVoteModel(); Dictionary <string, string> p = new Dictionary <string, string>(); p.Add("obj", JsonConvert.SerializeObject(vote)); model.CommandModel.SessionToken = await App.GetUsersSession(); model.CommandModel.ServiceName = "ContestVote"; model.CommandModel.Action = "Save"; model.CommandModel.Parameters = p; return(await srv.SaveContestVote(model.CommandModel)); }
private static async Task <ContestVoteResults> GetContestVote(string contestId, string contactId) { APIService srv = new APIService(); ContestVoteModel model = new ContestVoteModel(); Dictionary <string, string> p = new Dictionary <string, string>(); p.Add("contestId", string.Format("'{0}'", contestId)); p.Add("contactId", string.Format("'{0}'", contactId)); model.CommandModel.SessionToken = await App.GetUsersSession(); model.CommandModel.ServiceName = "ContestVote"; model.CommandModel.Action = "GetContestVoteForUser"; model.CommandModel.Parameters = p; return(await srv.GetContestVoteForContact(model.CommandModel)); }