public void MyCouponJsonSerializeAndDeserialize_Test()
        {
            IRepository repo = new Repository();

            var coupons = repo.Query<CouponView>(x => x.UserID == 443);

            if (coupons != null && coupons.Count > 0)
            {
                var couponDtos = coupons.MapToList<CouponView, CouponDto>().ToList();

                var jsonSerializer = new JavaScriptSerializer();

                var json = jsonSerializer.Serialize(couponDtos);

                if (!string.IsNullOrEmpty(json))
                {
                    couponDtos = jsonSerializer.Deserialize<List<CouponDto>>(json);

                    Assert.IsInstanceOfType(couponDtos[0], typeof(CouponDto));
                }

                var myCouponDto = new MyCouponDto
                {
                    Coupons = couponDtos
                };

                json = jsonSerializer.Serialize(myCouponDto);

                Assert.IsTrue(!string.IsNullOrEmpty(json));
            }
        }
Exemple #2
0
        public void MyCouponJsonSerializeAndDeserialize_Test()
        {
            IRepository repo = new Repository();

            var coupons = repo.Query <CouponView>(x => x.UserID == 443);

            if (coupons != null && coupons.Count > 0)
            {
                var couponDtos = coupons.MapToList <CouponView, CouponDto>().ToList();

                var jsonSerializer = new JavaScriptSerializer();

                var json = jsonSerializer.Serialize(couponDtos);

                if (!string.IsNullOrEmpty(json))
                {
                    couponDtos = jsonSerializer.Deserialize <List <CouponDto> >(json);

                    Assert.IsInstanceOfType(couponDtos[0], typeof(CouponDto));
                }

                var myCouponDto = new MyCouponDto
                {
                    Coupons = couponDtos
                };

                json = jsonSerializer.Serialize(myCouponDto);

                Assert.IsTrue(!string.IsNullOrEmpty(json));
            }
        }
Exemple #3
0
        public JsonResult MyCoupon(MyCouponDto model)
        {
            if (model != null && model.Coupons.Any())
            {
                foreach (var c in model.Coupons)
                {
                    try
                    {
                        if (c.MatchGuid != Guid.Empty && c.BetResultHome.HasValue && c.BetResultAway.HasValue)
                        {
                            var bet = new Bet
                            {
                                UserID   = AcnID,
                                UserName = User.Identity.Name
                            };

                            bet.Place(c.MatchGuid, c.BetResultHome.Value, c.BetResultAway.Value);

                            //投注成功
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            // 不管保存结果,直接返回success后,客户端刷新页面
            return(Json(new { result = "success" }));
        }
Exemple #4
0
        // 比分投注单
        // GET: /Casino/MyCoupon

        public ActionResult MyCoupon()
        {
            var model = new MyCouponDto();

            var days = ConfigGlobal_AcnCasino.CasinoValidDays;

            var query = _repo.Query <MatchView>(
                x => x.PlayTime > DateTime.Now && x.PlayTime < DateTime.Now.AddDays(days))
                        .FindAll(x => !x.ResultHome.HasValue && !x.ResultAway.HasValue)
                        .OrderBy(x => x.PlayTime)
                        .Many <MatchView, ChoiceOption, Guid>(t => t.CasinoItem.ID);

            var mapper = MatchDto.ConfigMapper().CreateMapper();

            var mList = mapper.Map <IEnumerable <MatchDto> >(query.AsEnumerable());

            mapper = new MapperConfiguration(cfg => cfg.CreateMap <MatchDto, CouponDto>()
                                             .ForMember(d => d.MatchGuid, opt => opt.MapFrom(s => s.ID))).CreateMapper();

            var list = mapper.Map <IEnumerable <CouponDto> >(mList).ToList();

            if (list.Count > 0)
            {
                // 查找当前用户的比分投注项
                var coupons = _repo.Query <CouponView>(x => x.UserID == AcnID);

                if (coupons.Count > 0)
                {
                    mapper = CouponDto.ConfigMapper().CreateMapper();

                    foreach (var c in coupons)
                    {
                        var i = list.FindIndex(x => x.MatchGuid.Equals(c.MatchGuid));

                        if (i >= 0)
                        {
                            list[i] = mapper.Map <CouponDto>(c);
                        }
                    }
                }
            }

            model.Coupons            = list;
            model.CasinoValidDays    = days;
            model.IsShowSubmitButton = list.Count > 0 && list.Any(x => !x.BetResultHome.HasValue && !x.BetResultAway.HasValue);

            return(View(model));
        }
        public JsonResult MyCoupon(MyCouponDto model)
        {
            if (model != null && model.Coupons.Any())
            {
                foreach (var c in model.Coupons)
                {
                    try
                    {
                        if (c.MatchGuid != Guid.Empty && c.BetResultHome.HasValue && c.BetResultAway.HasValue)
                        {
                            var bet = new Bet
                            {
                                UserID = AcnID,
                                UserName = User.Identity.Name
                            };

                            bet.Place(c.MatchGuid, c.BetResultHome.Value, c.BetResultAway.Value);

                            //投注成功
                        }
                    }
                    catch
                    {
                        // ignored
                    }
                }
            }

            // 不管保存结果,直接返回success后,客户端刷新页面
            return Json(new { result = "success" });
        }
        // 比分投注单
        // GET: /Casino/MyCoupon
        public ActionResult MyCoupon()
        {
            var model = new MyCouponDto();

            var days = ConfigGlobal_AcnCasino.CasinoValidDays;

            var query = _repo.Query<MatchView>(
                x => x.PlayTime > DateTime.Now && x.PlayTime < DateTime.Now.AddDays(days))
                .FindAll(x => !x.ResultHome.HasValue && !x.ResultAway.HasValue)
                .OrderBy(x => x.PlayTime)
                .Many<MatchView, ChoiceOption, Guid>(t => t.CasinoItem.ID);

            var mapper = MatchDto.ConfigMapper().CreateMapper();

            var mList = mapper.Map<IEnumerable<MatchDto>>(query.AsEnumerable());

            mapper = new MapperConfiguration(cfg => cfg.CreateMap<MatchDto, CouponDto>()
                .ForMember(d => d.MatchGuid, opt => opt.MapFrom(s => s.ID))).CreateMapper();

            var list = mapper.Map<IEnumerable<CouponDto>>(mList).ToList();

            if (list.Count > 0)
            {
                // 查找当前用户的比分投注项
                var coupons = _repo.Query<CouponView>(x => x.UserID == AcnID);

                if (coupons.Count > 0)
                {
                    mapper = CouponDto.ConfigMapper().CreateMapper();

                    foreach (var c in coupons)
                    {
                        var i = list.FindIndex(x => x.MatchGuid.Equals(c.MatchGuid));

                        if (i >= 0)
                        {
                            list[i] = mapper.Map<CouponDto>(c);
                        }
                    }
                }
            }

            model.Coupons = list;
            model.CasinoValidDays = days;
            model.IsShowSubmitButton = list.Count > 0 && list.Any(x => !x.BetResultHome.HasValue && !x.BetResultAway.HasValue);

            return View(model);
        }