示例#1
0
        public async Task <ActionResult> ClaimPrizeModal(int prizeId)
        {
            var userId = User.Identity.GetUserId <int>();
            var prize  = await PrizeReader.GetUserPrize(userId, prizeId);

            if (prize.Type != PrizeType.Crypto)
            {
                return(RedirectToAction("ViewUserPrizeModal", new { prizeId = prizeId }));
            }

            var paymentMethod = await PaymentReader.GetMethod(prize.Data);

            return(View(new ClaimPrizeModel
            {
                Id = prize.Id,
                Name = prize.Name,
                Description = prize.Description,
                Game = prize.Game,
                Points = prize.Points,
                Status = prize.Status,
                Type = prize.Type,
                X = prize.X,
                Y = prize.Y,

                Data = prize.Data,
                Data2 = prize.Data2,
                Data3 = prize.Data3,
                Data4 = prize.Data4,

                Rate = paymentMethod.Rate,
                Amount = decimal.Parse(prize.Data2)
            }));
        }
示例#2
0
        public async Task <ActionResult> ClaimPrizeModal(ClaimPrizeModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var userId = User.Identity.GetUserId <int>();
            var prize  = await PrizeReader.GetUserPrize(userId, model.Id);

            if (prize.Status != PrizeStatus.Unclaimed)
            {
                return(CloseModalSuccess());
            }

            if (model.IsPointsClaim)
            {
                var paymentMethod = await PaymentReader.GetMethod(prize.Data);

                if (paymentMethod == null)
                {
                    return(CloseModalError("Unknown Error"));
                }

                var paymentUserMethod = await PaymentReader.GetUserMethod(userId, paymentMethod.Id);

                if (paymentUserMethod == null)
                {
                    await PaymentWriter.CreateMethod(userId, paymentMethod.Id);
                }

                paymentUserMethod = await PaymentReader.GetUserMethod(userId, paymentMethod.Id);

                if (paymentUserMethod == null)
                {
                    return(CloseModalError("Unknown Error"));
                }

                model.Data3 = paymentUserMethod.Data;
            }

            if (string.IsNullOrEmpty(model.Data3))
            {
                ModelState.AddModelError("", "Invalid Crypto Address");
                return(View(model));
            }

            var result = await PrizeWriter.ClaimPrize(userId, model);

            if (!ModelState.IsWriterResultValid(result))
            {
                return(View(model));
            }

            return(CloseModalSuccess());
        }