示例#1
0
        public bool AddOrUpdateWinningRule(ViewModels.LuckyGameWinningRuleViewModel rule, string group)
        {
            var res = context.AddOrUpdateWinningRule(rule, group);

            if (res)
            {
                Utils.LuckyGameUtils.WinningRulesUpdate(group);
                return(true);
            }
            return(false);
        }
示例#2
0
        private LuckyGameResponse _addOrUpdateLuckyGameWinningRule(ViewModels.LuckyGameWinningRuleViewModel rule, string group)
        {
            LuckyGameResponse response = new LuckyGameResponse();

            if (rule.AmountMatchingCards < 1)
            {
                return(new LuckyGameResponse()
                {
                    Success = false,
                    ErrorMessage = "AmountMatchingCards must be > 1"
                });
            }

            if (rule.WinFactor < 1)
            {
                return(new LuckyGameResponse()
                {
                    Success = false,
                    ErrorMessage = "WinFactor must be > 1"
                });
            }

            var ownerId = gameSettingsRepository.GetOwnerIdForGroup(group);
            var user    = userRepository.GetUserFromSignalR(Context.ConnectionId);

            if (ownerId == user.Id)
            {
                return(new LuckyGameResponse()
                {
                    Success = true,
                    ResponseData = gameSettingsRepository.AddOrUpdateWinningRule(rule, group)
                });
            }
            else
            {
                return(new LuckyGameResponse()
                {
                    Success = false,
                    ErrorMessage = "Not allowed to do this.."
                });
            }
        }
示例#3
0
        public bool AddOrUpdateWinningRule(ViewModels.LuckyGameWinningRuleViewModel rule, string group)
        {
            var service = _db.ServiceSettings.FirstOrDefault(ln => ln.ServiceUrl == group);

            if (service != null)
            {
                var game = service.LuckyGameSettings.FirstOrDefault();
                if (game != null)
                {
                    if (rule.Id == 0)
                    {
                        game.WinningRules.Add(new Models.LuckyGameWinningRule()
                        {
                            AmountMatchingCards = rule.AmountMatchingCards,
                            WinFactor           = rule.WinFactor
                        });
                    }
                    else
                    {
                        var dbrule = game.WinningRules.FirstOrDefault(ln => ln.ID == rule.Id);
                        if (dbrule == null)
                        {
                            return(false);
                        }

                        dbrule.AmountMatchingCards = rule.AmountMatchingCards;
                        dbrule.WinFactor           = rule.WinFactor;
                    }

                    _db.SaveChanges();
                    return(true);
                }
            }

            return(false);
        }
示例#4
0
 public async Task <LuckyGameResponse> addOrUpdateLuckyGameWinningRule(ViewModels.LuckyGameWinningRuleViewModel rule, string group)
 {
     return(await Task.Run(() => _addOrUpdateLuckyGameWinningRule(rule, group)));
 }