Пример #1
0
        public ActionResult DisneyStarWars2018UpdateWinner(DisneyStarWars2018Model model)
        {
            try
            {
                if (common.Now >= endDate)
                {
                    throw new DisneyStarWars2018ServiceException("400", "이벤트가 종료되었습니다.", null);
                }
                // 당첨자 세션 check
                long?entryId = Session["DisneyStarWarsEntryId"] as long?;
                DisneyStarWars2018InstantLotteryPrizeType?prize = Session["DisneyStarWarsPrizeType"] as DisneyStarWars2018InstantLotteryPrizeType?;

                if (!entryId.HasValue || entryId.Value != model.Id)
                {
                    throw new DisneyStarWars2018ServiceException("400", "당첨자가 아닙니다.", model.Id);
                }

                if (!prize.HasValue || prize.Value != model.PrizeType)
                {
                    throw new DisneyStarWars2018ServiceException("400", "해당 경품 당첨자가 아닙니다.", model.PrizeType);
                }

                if (!ModelState.IsValid)
                {
                    var errorProp = ModelState.Values.Where(x => x.Errors.Count > 0).FirstOrDefault();
                    if (errorProp != null)
                    {
                        throw new DisneyStarWars2018ServiceException("400", errorProp.Errors[0].ErrorMessage, null);
                    }
                }


                var user   = service.GetInstantLotteryWinner(model.Id);
                var entity = mapperConfig.CreateMapper().Map <DisneyStarWars2018Model, DisneyStarWars2018InstantLottery>(model, user);
                entity.UpdateDate = common.Now;
                service.UpdateInstantLotteryWinner(entity);



                return(Json(new
                {
                    result = true
                }));
            }
            catch (Exception e)
            {
                var message = e.Message;
                if (!(e is EventServiceException))
                {
                    message = "서비스 점검중입니다. 잠시 후 시도해보시거나, 담당자에게 문의하시기 바랍니다.";
                }
                return(Json(new
                {
                    result = false,
                    message = message
                }));
            }
        }
Пример #2
0
        public void TryGetInstantLotteryWinnerSuccess()
        {
            var entry = new DisneyStarWars2018InstantLottery {
                Id         = 1,
                CreateDate = new DateTime(2018, 5, 2),
                IpAddress  = "127.0.0.1",
                Channel    = Domain.Abstract.ChannelType.PC,
                PrizeType  = DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty
            };

            repo.Setup(x => x.SingleOrDefault(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >())).Returns(entry);

            //action
            var result = service.GetInstantLotteryWinner(1);

            //assert
            Assert.NotNull(result);
            Assert.Equal(result.PrizeType, DisneyStarWars2018InstantLotteryPrizeType.KinderJoyGifty);

            repo.Verify(x => x.SingleOrDefault(It.IsAny <Expression <Func <DisneyStarWars2018InstantLottery, bool> > >()), Times.Once);
        }