/// <summary> /// 创建一个被投票项目 /// </summary> /// <param name="item"></param> public EnumCampaignCreatePictureVoteItemResult CreatePictureVoteItem(Campaign_PictureVoteItemEntity args) { if (args == null) { Debug.Assert(false, "args == null"); return(EnumCampaignCreatePictureVoteItemResult.Failed); } //是否允许多发布 Campaign_PictureVoteEntity campaign_PictureVote = GetPictureVote(args.CampaignId); if (campaign_PictureVote == null) { return(EnumCampaignCreatePictureVoteItemResult.Failed); } //参与通道是否还打开 if (campaign_PictureVote.AllowedNewItem == false) { return(EnumCampaignCreatePictureVoteItemResult.NewItemClosed); } //如果是会员发布,判断是否发过了及是否可多发布 if (args.Member.HasValue && args.Member.Value != Guid.Empty) { List <CommandParameter> parameterList = new List <CommandParameter>(); parameterList.Add(new CommandParameter("@campaignId", args.CampaignId)); parameterList.Add(new CommandParameter("@memberId", args.Member.Value)); int intCount = 0; _campaignManager.DataBase.ExecuteScalar <int>( "SELECT Count(1) FROM [Campaign_PictureVoteItem] WHERE [CampaignId] = @campaignId AND [Member] = @memberId", parameterList, (scalarValue) => { intCount = scalarValue; }); if (intCount >= campaign_PictureVote.MaxPublishTimes) { return(EnumCampaignCreatePictureVoteItemResult.AlreadyPublished); } } int?serialNumber = _campaignManager.DomainManager.GetSerialNumber("PictureVote"); if (serialNumber.HasValue == false) { return(EnumCampaignCreatePictureVoteItemResult.Failed); } args.SerialNumber = serialNumber.Value.ToString(); _campaignManager.DataBase.Insert(args); return(EnumCampaignCreatePictureVoteItemResult.Successful); }
/// <summary> /// 我要投票中显示的已投票详情 /// </summary> /// <returns></returns> public ActionResult PictureVoteItemDetail() { string strId = Request.QueryString["itemId"]; string strCampaignId = Request.QueryString["campaignId"]; if (String.IsNullOrEmpty(strId)) { //兼容旧链接 strId = Request.QueryString["id"]; if (String.IsNullOrEmpty(strId)) { return(RespondResult(false, "参数无效。")); } else { return(RedirectToAction("PictureVoteItemDetail", new { domainId = DomainContext.Domain.Id, itemId = strId, campaignId = strCampaignId })); } } Guid id = Guid.Parse(strId); Guid campaignId = Guid.Parse(strCampaignId); Campaign_PictureVoteItemEntity pictureVoteItem = _campaignManager.PictureVote.GetPictureVoteItem(id); if (pictureVoteItem == null || pictureVoteItem.Member != MemberContext.Member.Id) { return(RedirectToAction("PictureVote", new { domainId = DomainContext.Domain.Id, campaignId = strCampaignId })); } PictureVoteItemDetailViewModel model = new PictureVoteItemDetailViewModel(); model.PictureVoteItem = pictureVoteItem; model.Campaign = _campaignManager.GetCampaign(model.PictureVoteItem.CampaignId); if (model.Campaign == null) { //重定向到错误页面 return(new RedirectResult(String.Format( "~/Home/ErrorView/?message={0}", "td8"))); } model.JsApiConfig = DomainContext.GetJsApiConfig(HttpContext.Request.Url.ToString()); model.JsApiConfig.JsApiList.Add("onMenuShareTimeline"); model.JsApiConfig.JsApiList.Add("onMenuShareAppMessage"); model.ShareUrl = String.Format( "http://{0}/Campaign/PictureVote/{1}?campaignId={2}", Request.Url.Host, DomainContext.Domain.Id, strCampaignId); return(View(model)); }
/// <summary> /// 提交投票项目 /// </summary> /// <returns></returns> public ActionResult CreatePictureVoteItem() { CreatePictureVoteItemArgs args = RequestArgs <CreatePictureVoteItemArgs>(); if (args == null) { return(RespondResult(false, "参数无效。")); } if (String.IsNullOrEmpty(args.ImageServerId)) { return(RespondResult(false, "参数无效。")); } //判断参与人数是否达到限制 if (_campaignManager.PictureVote.PictureVoteIsFullParticipant(args.CampaignId)) { return(RespondResult(false, "该活动已达最大允许参与人数。")); } //调用文件服务器进行代理下载,把上传到微信后台的文件下载下来 FileDownloadAgentWithMediaIdArgs downloadArgs = new FileDownloadAgentWithMediaIdArgs(); downloadArgs.Domain = DomainContext.Domain.Id; downloadArgs.MediaId = args.ImageServerId; FileDownloadAgentWithMediaIdResult downloadResult = _fileService.DownloadAgentWithMediaId(downloadArgs); string imageUrl; if (downloadResult.Success) { _log.Write("下载媒体文件返回:", JsonConvert.SerializeObject(downloadResult), TraceEventType.Verbose); imageUrl = _fileService.FileServiceUri + downloadResult.OutputFile; } else { return(RespondResult(false, "照片上传失败:" + downloadResult.Message)); } Campaign_PictureVoteItemEntity item = new Campaign_PictureVoteItemEntity(); item.Domain = DomainContext.Domain.Id; item.CampaignId = args.CampaignId; item.Member = MemberContext.Member.Id; item.Title = args.Title; item.Description = args.Description; item.Url = imageUrl; item.UploadTime = DateTime.Now; EnumCampaignCreatePictureVoteItemResult result = _campaignManager.PictureVote.CreatePictureVoteItem(item); return(RespondDataResult(result)); }
public ActionResult GetPictureVoteItem() { string itemId = Request.QueryString["itemId"]; if (String.IsNullOrEmpty(itemId)) { return(RespondResult(false, "参数无效。")); } Campaign_PictureVoteItemEntity item = _campaignManager.PictureVote.GetPictureVoteItem(Guid.Parse(itemId)); return(RespondDataResult(item)); }
public ActionResult PictureVoteItemDetail() { string strItemId = Request.QueryString["itemId"]; string strCampaignId = Request.QueryString["campaignId"]; Guid itemId = Guid.Parse(strItemId); Guid campaignId = Guid.Parse(strCampaignId); Campaign_PictureVoteItemEntity pictureVoteItem = _campaignManager.PictureVote.GetPictureVoteItem(itemId); if (pictureVoteItem == null) { return(RedirectToAction("PictureVoteItemList", new { domainId = DomainContext.Domain.Id, campaignId = strCampaignId })); } PictureVoteItemDetailViewModel model = new PictureVoteItemDetailViewModel(); model.PictureVoteItem = pictureVoteItem; return(View(model)); }
public Campaign_PictureVoteItemEntity GetPictureVoteItem(Guid id) { Campaign_PictureVoteItemEntity item = new Campaign_PictureVoteItemEntity(); item.Id = id; if (_campaignManager.DataBase.Fill <Campaign_PictureVoteItemEntity>(item)) { if (item.Member.HasValue) { MemberEntity member = _campaignManager.MemberManager.GetMember(item.Member.Value); if (member != null) { item.MemberEntity = member; } } return(item); } else { return(null); } }
/// <summary> /// 投票 /// </summary> /// <param name="args"></param> public EnumCampaignPictureVoteResult PictureVote(Campaign_PictureVoteArgs args) { if (args == null) { Debug.Assert(false, "args == null"); return(EnumCampaignPictureVoteResult.Failed); } CampaignEntity campaign = _campaignManager.GetCampaign(args.CampaignId); if (campaign == null) { return(EnumCampaignPictureVoteResult.Failed); } //状态是否进行中 switch (campaign.Status) { case EnumCampaignStatus.Preparatory: return(EnumCampaignPictureVoteResult.NotStarted); case EnumCampaignStatus.End: return(EnumCampaignPictureVoteResult.AlreadyEnded); } //判断要投的项目是否已被锁定 Campaign_PictureVoteItemEntity item = GetPictureVoteItem(args.ItemId); if (item == null) { return(EnumCampaignPictureVoteResult.Failed); } if (item.Lock) { return(EnumCampaignPictureVoteResult.Lock); } Campaign_PictureVoteEntity campaign_PictureVote = GetPictureVote(args.CampaignId); if (campaign_PictureVote == null) { return(EnumCampaignPictureVoteResult.Failed); } //是否允许非会员投票 if (campaign_PictureVote.AllowedNoAttentionVote == false && args.Member == null) { return(EnumCampaignPictureVoteResult.OnlyMember); } //查出当前在此活动下的投票记录 List <CommandParameter> parameterList = new List <CommandParameter>(); parameterList.Add(new CommandParameter("@campaignId", args.CampaignId)); parameterList.Add(new CommandParameter("@openId", args.OpenId)); //根据投票方式判断是否按天投 if (campaign_PictureVote.VoteType == EnumCampaignPictureVoteVoteType.Day) { List <Campaign_PictureVoteLogEntity> logList = _campaignManager.DataBase.Select <Campaign_PictureVoteLogEntity>( @"SELECT * FROM [Campaign_PictureVoteLog] WHERE [CampaignId] = @campaignId AND [OpenId] = @openId AND Convert(varchar(10),[VoteTime],120) = Convert(varchar(10),CONVERT(datetime,'" + DateTime.Now.ToShortDateString() + "'),120)", parameterList); //是否达到最大投票数 if (logList.Count >= campaign_PictureVote.MaxVoteTimes) { return(EnumCampaignPictureVoteResult.OverVoteTimesByDay); } if (logList.Count > 0) { //是否给同一个项目投过票 if ((from c in logList where c.ItemId == args.ItemId select c).Count() > 0) { return(EnumCampaignPictureVoteResult.VotedByDay); } } } else //NoRepetition { List <Campaign_PictureVoteLogEntity> logList = _campaignManager.DataBase.Select <Campaign_PictureVoteLogEntity>( "SELECT * FROM [Campaign_PictureVoteLog] WHERE [CampaignId] = @campaignId AND [OpenId] = @openId", parameterList); //是否达到最大投票数 if (logList.Count >= campaign_PictureVote.MaxVoteTimes) { return(EnumCampaignPictureVoteResult.OverVoteTimes); } if (logList.Count > 0) { //是否给同一个项目投过票 if ((from c in logList where c.ItemId == args.ItemId select c).Count() > 0) { return(EnumCampaignPictureVoteResult.Voted); } } } //投票 Campaign_PictureVoteLogEntity log = new Campaign_PictureVoteLogEntity(); log.CampaignId = args.CampaignId; log.Domain = args.DomainId; log.ItemId = args.ItemId; log.OpenId = args.OpenId; log.Member = args.Member; log.VoteTime = DateTime.Now; _campaignManager.DataBase.Insert(log); parameterList = new List <CommandParameter>(); parameterList.Add(new CommandParameter("@itemId", args.ItemId)); _campaignManager.DataBase.ExecuteNonQuery("UPDATE [Campaign_PictureVoteItem] SET [VoteQuantity] = [VoteQuantity] + 1 WHERE [Id] = @itemId", parameterList); return(EnumCampaignPictureVoteResult.Successful); }