public void Vote(Guid planId, Guid targetId, string userKey) { using (var defalutContent = new DefaultContext()) { var plan = defalutContent.TrackPlans.SingleOrDefault(x => x.ID == planId); if (plan.Null() || plan.BeginTime > DateTime.Now || plan.EndTime < DateTime.Now) { return; } var trackRecord = new TrackRecord(); trackRecord.ID = Guid.NewGuid(); trackRecord.AllKey = userKey; trackRecord.CreateTime = DateTime.Now; trackRecord.PlanId = planId; trackRecord.TargetId = targetId; Flag = true; } }
#pragma warning disable CS1998 // Async method lacks 'await' operators and will run synchronously private async Task VoteTarget(string userKey, Guid targetId) #pragma warning restore CS1998 // Async method lacks 'await' operators and will run synchronously { using (var defaultContext = new DefaultContext()) { var target = defaultContext.TrackTargets.FirstOrDefault(x => x.ID == targetId); if (target.Null()) { LogUtility.SendError("错误投票!!"); } var trackPlan = defaultContext.TrackPlans.FirstOrDefault(x => x.ID == target.PlanId); if (trackPlan.Null() || trackPlan.BeginTime > DateTime.Now || trackPlan.EndTime < DateTime.Now) { LogUtility.SendError("投票活动失败!!"); } var trackRecord = new TrackRecord(); trackRecord.ID = Guid.NewGuid(); trackRecord.AllKey = userKey; trackRecord.CreateTime = DateTime.Now; trackRecord.PlanId = target.PlanId; trackRecord.TargetId = targetId; defaultContext.TrackRecords.Add(trackRecord); defaultContext.SaveChanges(); } }