/// <summary> /// 投票 /// </summary> /// <param name="voteId"></param> public void VoteVoteThread(long voteId) { //投票人数 VoteThread voteThread = voteThreadRepository.Get(voteId); voteThread.MemberCount = voteThread.MemberCount + 1; voteThreadRepository.Update(voteThread); }
/// <summary> /// 新建实体时使用 /// </summary> //todo:需要检查成员初始化的类型是否正确 public static VoteThread New() { VoteThread voteThread = new VoteThread() { Title = string.Empty, Body = string.Empty, EndDate = DateTime.UtcNow, HiddenText = string.Empty, DateCreated = DateTime.UtcNow }; return(voteThread); }
/// <summary> /// 将数据库中的信息转换成EditModel实体 /// </summary> /// <param name="voteThread"></param> /// <returns></returns> public static VoteEditModel AsEditModel(this VoteThread voteThread) { return(new VoteEditModel { VoteId = voteThread.Id, Title = voteThread.Title, Body = voteThread.Body, VoteType = voteThread.VoteType, OptionType = voteThread.OptionType, EndDate = voteThread.EndDate, VoteResult = voteThread.VoteResult, HiddenText = voteThread.HiddenText }); }
/// <summary> /// 创建投票 /// </summary> /// <param name="voteThread">投票实体</param> /// <returns></returns> public long CreateVote(VoteThread voteThread) { if (voteThread.Body == null) { voteThread.Body = ""; } if (voteThread.HiddenText == null) { voteThread.HiddenText = ""; } long threadId = 0; long.TryParse(voteThreadRepository.Insert(voteThread).ToString(), out threadId); return(threadId); }
/// <summary> /// 设置审核设置 /// </summary> /// <param name="eventId">活动Id</param> /// <param name="isApproved">审核状态</param> public void UpdateAuditStatus(long voteId, bool isApproved) { AuditStatus auditStatus = isApproved ? AuditStatus.Success : AuditStatus.Fail; VoteThread voteThread = voteThreadRepository.Get(voteId); string operationType = isApproved ? EventOperationType.Instance().Approved() : EventOperationType.Instance().Disapproved(); if (voteThread != null && voteThread.AuditStatus != auditStatus) { AuditStatus oldAuditStatus = voteThread.AuditStatus; voteThread.AuditStatus = auditStatus; voteThreadRepository.Update(voteThread); //触发事件 EventBus <VoteThread> .Instance().OnAfter(voteThread, new CommonEventArgs(operationType)); EventBus <VoteThread, AuditEventArgs> .Instance().OnAfter(voteThread, new AuditEventArgs(oldAuditStatus, auditStatus)); } }
/// <summary> /// 删除投票 /// </summary> /// <param name="VoteId"></param> public void DeleteVoteById(long voteId) { VoteThread voteThread = voteThreadRepository.Get(voteId); if (voteThread != null) { IEnumerable <VoteRecord> voteRecord = voteRecordRepository.GetVoteRecords(voteId); IEnumerable <VoteOption> voteOption = voteOptionRepository.GetVoteOptions(voteId); foreach (var item in voteRecord) { voteRecordRepository.Delete(item); } foreach (var item in voteOption) { voteOptionRepository.Delete(item); } voteThreadRepository.Delete(voteThread); } }
/// <summary> /// 转换为投票实体 /// </summary> /// <returns></returns> public VoteThread AsVoteThread() { VoteThread voteThread = new VoteThread(); if (this.VoteId == 0) { } else { voteThread = new VoteThreadRepository().Get(this.VoteId); } voteThread.Title = this.Title; voteThread.Body = this.Body; voteThread.VoteType = this.VoteType; voteThread.OptionType = this.OptionType; voteThread.EndDate = this.EndDate; voteThread.VoteResult = this.VoteResult; voteThread.HiddenText = this.HiddenText; return(voteThread); }
/// <summary> /// 修改投票 /// </summary> /// <returns></returns> public void EditVote(VoteThread voteThread) { voteThreadRepository.Update(voteThread); }