コード例 #1
0
ファイル: ChariDb.cs プロジェクト: ichari/ichari
 /// <summary>
 /// 用于向 Drawings EntitySet 添加新对象的方法,已弃用。请考虑改用关联的 ObjectSet&lt;T&gt; 属性的 .Add 方法。
 /// </summary>
 public void AddToDrawings(Drawings drawings)
 {
     base.AddObject("Drawings", drawings);
 }
コード例 #2
0
ファイル: CharityController.cs プロジェクト: ichari/ichari
        public string FlashGame(string var)
        {
            //Session[SessionKey.DrawId] = 1;
            //Session[SessionKey.PrizeId] = 1;
            //Session[SessionKey.User] = _uow.UserInfoService.Get(o => o.Id == 8);
            //return "{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"xx\", \"angle\" : 60, \"url\" : \"win\" }";
                                
            //check if request generated from ChariDraw page
            if (Session["ChariGame"] == null)
                return "{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"已超时,请重新刷新。\", \"url\" : \"exp\" }";
            if (Session["ChariGame"].ToString() == DataEncryption.HashString("chari.game"))
            {
                //直接输入捐赠号
                UserInfo usr = (UserInfo)Session[SessionKey.User];
                string DonationId = (string)Session[SessionKey.DonationId];
                decimal DonationAmt = 0;
                if (Session[SessionKey.DonationAmt] != null)
                    DonationAmt = (decimal)Session[SessionKey.DonationAmt];
                
                #region User Logged In
                if (usr != null)
                {
                    //user logged in
                    UserInfo dbusr = _uow.UserInfoService.Get(o => o.Id == usr.Id);
                    if (dbusr != null && usr.Password == dbusr.Password && usr.UserName == dbusr.UserName)
                    {
                        //user valid, get user's donations
                        //List<LoveChange> donations = _uow.LoveChangeService.GetQueryList(o => o.UserId == dbusr.Id  && o.IsGame != true).OrderBy(o => o.CreateTime).ToList();
                        var donation = _uow.LoveChangeService.GetQueryList(o => o.UserId == dbusr.Id && o.IsGame != true).OrderBy(o => o.CreateTime).FirstOrDefault();

                        //int dtype = (int)OrderType.Donation;
                        //List<Order> orderList = _uow.OrderService.GetQueryList(o => o.UserId == dbusr.Id && o.IsGame != true && o.OrderType == dtype && o.Status == 10).OrderBy(o => o.PayTime).ToList();
                        var donationOrder = _uow.OrderService.GetQueryList(t => t.UserId == dbusr.Id
                                                && t.IsGame == false
                                                && t.OrderType == (int)OrderType.Donation
                                                && t.Status >= (int)OrderState.Paid).OrderBy(t => t.PayTime).FirstOrDefault();

                        #region 愛心零錢 UnionPay
                        //if (donations.Count > 0)
                        if (donation != null)
                        {
                            //愛心零錢 available for drawings, select earliest and create drawing entry
                            Drawings NewDraw = new Drawings();
                            NewDraw.Source = (int)GameSource.ChangeOfCare;
                            NewDraw.UserId = dbusr.Id;
                            NewDraw.OrderNo = donation.UnionOrder;
                            
                            //get available prizes
                            List<Prize> przList = _uow.PrizeService.SelectPrizeList(true);
                            if (przList.Count > 0)
                            {
                                //prize available, calculate winning result
                                bool DrawResult = DataEncryption.GetDrawingResult();
                                NewDraw.IsWinner = DrawResult;

                                if (DrawResult)
                                {
                                    //user won a prize, selects a random prize from the list
                                    Prize wPrize = _uow.PrizeService.SelectWinningPrize(przList);
                                    NewDraw.PrizeId = wPrize.Id;
                                    //increase used prize count
                                    wPrize.UsedCount += 1;
                                    NewDraw.CreateTime = DateTime.Now;
                                    donation.GameTime = NewDraw.CreateTime;
                                    donation.IsGame = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    
                                    int ang = wPrize.Angle + 720;
                                    return "{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"" + wPrize.Name + "\", \"angle\" : " + ang.ToString() + ", \"url\" : \"usr\" }";
                                }
                                else
                                {
                                    //user did not win
                                    NewDraw.CreateTime = DateTime.Now;
                                    donation.GameTime = NewDraw.CreateTime;
                                    NewDraw.IsConfirrmed = true;
                                    donation.IsGame = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    return "{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }";
                                }
                            }
                            else
                            {
                                //no prize available, user set to not win
                                NewDraw.CreateTime = DateTime.Now;
                                donation.GameTime = NewDraw.CreateTime;
                                NewDraw.IsConfirrmed = true;
                                donation.IsGame = true;
                                _uow.DrawingsService.Add(NewDraw);
                                _uow.Commit();
                                return "{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }";
                            }
                        }
                        #endregion
                        #region 愛心捐贈 ichari
                        else if (donationOrder != null)
                        {
                            //愛心捐贈 available for drawings, select earliest and create drawing entry
                            Drawings NewDraw = new Drawings();
                            NewDraw.Source = (int)GameSource.IchariDonation;
                            NewDraw.UserId = dbusr.Id;
                            NewDraw.OrderNo = donationOrder.TradeNo;

                            //get available prizes
                            List<Prize> przList = _uow.PrizeService.SelectRandomPrizeList(11, true);
                            if (przList.Count > 0)
                            {
                                //prize available, calculate winning result
                                bool DrawResult = DataEncryption.GetDrawingResult();
                                NewDraw.IsWinner = DrawResult;
                                if (DrawResult)
                                {
                                    //user won a prize, selects a random prize from the list
                                    Prize wPrize = _uow.PrizeService.SelectWinningPrize(przList);
                                    //end prize selection
                                    NewDraw.PrizeId = wPrize.Id;
                                    //increase used prize count
                                    wPrize.UsedCount += 1;
                                    NewDraw.CreateTime = DateTime.Now;                                    
                                    _uow.DrawingsService.Add(NewDraw);
                                    //更新捐赠订单
                                    donationOrder.UpdateTime = NewDraw.CreateTime;
                                    donationOrder.IsGame = true;

                                    _uow.Commit();
                                    
                                    int ang = wPrize.Angle + 720;
                                    return "{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"" + wPrize.Name + "\", \"angle\" : " + ang.ToString() + ", \"url\" : \"usr\" }";
                                }
                                else
                                {
                                    //user did not win
                                    NewDraw.CreateTime = DateTime.Now;                                    
                                    NewDraw.IsConfirrmed = true;
                                    //更新捐赠订单
                                    donationOrder.UpdateTime = NewDraw.CreateTime;
                                    donationOrder.IsGame = true;
                                    _uow.DrawingsService.Add(NewDraw);

                                    _uow.Commit();
                                    
                                    return "{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }";
                                }
                            }
                            else
                            {
                                //no prize available, user set to not win
                                NewDraw.CreateTime = DateTime.Now;
                                donationOrder.UpdateTime = NewDraw.CreateTime;
                                NewDraw.IsConfirrmed = true;
                                donationOrder.IsGame = true;
                                _uow.DrawingsService.Add(NewDraw);
                                _uow.Commit();
                                return "{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"usr\" }";
                            }
                        }
                        #endregion
                        else
                        {
                            _log.Info("user is logon,but not exist donation order");
                            //no donations available for drawing
                            return "{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"对不起,您已经没有抽奖机会了\" }";
                        }
                    }
                }
                #endregion
                #region Donation Entered or from UPOP
                else if (!string.IsNullOrWhiteSpace(DonationId) && DonationAmt > 0)
                {
                    //donation entered
                    LoveChange lc = _uow.LoveChangeService.Get(o => o.UnionOrder == DonationId & o.Amount == DonationAmt);
                    if (lc != null && lc.Amount == DonationAmt && lc.UnionOrder == DonationId)
                    {
                        //donation valid, 
                        if (lc.IsGame != true)
                        {
                            //check if prize available, create drawing entry
                            Drawings NewDraw = new Drawings();
                            NewDraw.OrderNo = DonationId;
                            NewDraw.Source = (int)GameSource.ChangeOfCare;
                            List<Prize> przList = _uow.PrizeService.SelectRandomPrizeList(11, true);
                            if (przList.Count > 0)
                            {
                                //prize available, get drawing result
                                bool drawResult = DataEncryption.GetDrawingResult();
                                NewDraw.IsWinner = drawResult;
                                if (drawResult)
                                {
                                    //user won, randomly selects a prize
                                    Prize wPrize = _uow.PrizeService.SelectWinningPrize(przList);
                                    NewDraw.PrizeId = wPrize.Id;
                                    //increase used count
                                    wPrize.UsedCount += 1;
                                    NewDraw.CreateTime = DateTime.Now;
                                    lc.GameTime = NewDraw.CreateTime;
                                    lc.IsGame = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    Session[SessionKey.DrawId] = _uow.DrawingsService.Get(o => o.PrizeId == NewDraw.PrizeId && o.OrderNo == NewDraw.OrderNo).Id;
                                    
                                    
                                    int ang = wPrize.Angle + 720;
                                    return "{ \"type\" : \"checkLogin\", \"status\" : 1, \"massage\" : \"" + wPrize.Name + "\", \"angle\" : " + ang.ToString() + ", \"url\" : \"win\" }";
                                }
                                else
                                {
                                    //user did not win
                                    NewDraw.CreateTime = DateTime.Now;
                                    lc.GameTime = NewDraw.CreateTime;
                                    NewDraw.IsConfirrmed = true;
                                    lc.IsGame = true;
                                    _uow.DrawingsService.Add(NewDraw);
                                    _uow.Commit();
                                    return "{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"lose\" }";
                                }
                            }
                            else
                            {
                                //prize not available, user set to lost
                                NewDraw.CreateTime = DateTime.Now;
                                lc.GameTime = NewDraw.CreateTime;
                                NewDraw.IsConfirrmed = true;
                                lc.IsGame = true;
                                _uow.DrawingsService.Add(NewDraw);
                                _uow.Commit();
                                return "{ \"type\" : \"checkLogin\", \"status\" : 2, \"massage\" : \"感谢您对慈善事业的大力支持,谢谢参与。\", \"angle\" : 1050, \"url\" : \"lose\" }";
                            }
                        }
                        else
                        {
                            //game played
                            return "{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"此捐赠单已抽奖,请登录查询中奖记录。\" }";
                        }
                    }
                    else
                    {
                        //donation invalid
                        return "{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"请重新确认您的捐赠单号。(或凭证号)。\" }";
                    }
                }
                #endregion
                else
                {
                    //user not logged in and no donation entered, disable flash
                    return "{ \"type\" : \"checkLogin\", \"status\" : 0, \"massage\" : \"《请登陆用户》 或 《填写捐赠单》\", \"url\" : \"login\" }";
                }
            }
            
            return "";
        }
コード例 #3
0
ファイル: ChariDb.cs プロジェクト: ichari/ichari
 /// <summary>
 /// 创建新的 Drawings 对象。
 /// </summary>
 /// <param name="id">Id 属性的初始值。</param>
 /// <param name="isWinner">IsWinner 属性的初始值。</param>
 /// <param name="createTime">CreateTime 属性的初始值。</param>
 /// <param name="source">Source 属性的初始值。</param>
 public static Drawings CreateDrawings(global::System.Int64 id, global::System.Boolean isWinner, global::System.DateTime createTime, global::System.Int32 source)
 {
     Drawings drawings = new Drawings();
     drawings.Id = id;
     drawings.IsWinner = isWinner;
     drawings.CreateTime = createTime;
     drawings.Source = source;
     return drawings;
 }