コード例 #1
0
        public JsonResult SaveWheelHistory(int priceId = -1)
        {
            int serverValidatorPrice = (int?)Session["CurrentPrice"] ?? -1;
            int defaultPoint         = int.Parse(ConfigurationManager.AppSettings["PointPerWheel"]);

            if (priceId == serverValidatorPrice)
            {
                var user       = _userService.ReadByGeneralUserId(User.Identity.GetUserId());
                var sumOfPoint = user.Point - defaultPoint;
                if (UserExternalService.IsUnluckyItem(priceId))
                {
                    _userService.UpdatePointUser(user.GeneralUserId, sumOfPoint);
                    return(Json(new { message = "Chúc bạn may mắn lần sau !", point = sumOfPoint, unLucky = true }, JsonRequestBehavior.AllowGet));
                }
                var desc = UserExternalService.GetDescriptonWheelItem(priceId);

                LuckyWheelHistoryDto h = new LuckyWheelHistoryDto()
                {
                    CreatedDate = DateTime.Now,
                    NameDisplay = user.NameDisplay,
                    UserId      = user.Id,
                    Result      = desc
                };

                var result = _userService.CreateLuckyHistory(h);
                if (result != null)
                {
                    _userService.UpdatePointUser(user.GeneralUserId, sumOfPoint);
                }
                return(Json(new { message = "Chúc mừng bạn đã trúng " + desc + ". Vui lòng inbox fanpage, Cám ơn bạn.", point = sumOfPoint }, JsonRequestBehavior.AllowGet));
            }

            return(Json(new { status = "error", message = "Xảy ra lỗi khi cập nhật thông tin, vui lòng quay số lại." }, JsonRequestBehavior.AllowGet));
        }
コード例 #2
0
        public LuckyWheelHistoryDto CreateLuckyHistory(LuckyWheelHistoryDto data)
        {
            var entity = Mapper.Map <LuckyWheelHistory>(data);

            entity.CreatedDate = DateTime.Now;
            entity.UserId      = data.UserId;

            var result = _luckyWheelHistoryRepositories.Create(entity);

            if (_luckyWheelHistoryRepositories.SaveChanges() > 0)
            {
                return(Mapper.Map <LuckyWheelHistoryDto>(result));
            }

            return(null);
        }