Пример #1
0
        /// <summary>
        /// Overload: Gets the next random entry. Refills depending on passed LotteryMode.
        /// </summary>
        /// <param name="mode">The mode to determine how to behave, when copied list is empty.</param>
        /// <returns>Returns next entry or default(T), depending on mode.</returns>
        public T DrawNext(LotteryMode mode)
        {
            if (IsEmtpy())
            {
                switch (mode)
                {
                case LotteryMode.RefillOnEmpty:
                    CopyEntries();
                    break;

                case LotteryMode.RemoveOnEmpty:
                    LotteryManager <T> .Remove(Collection);

                    return(default(T));

                case LotteryMode.None:
                    return(default(T));
                }
            }
            var id   = UnityEngine.Random.Range(0, CollectionCopy.Count);
            var temp = CollectionCopy[id];

            CollectionCopy.Remove(CollectionCopy[id]);
            return(temp);
        }
Пример #2
0
        public IActionResult Create()
        {
            var vm = new LotteryMode {
                IsNew = true, PlayableNumber = 1, AwardedNumber = 1
            }; LoadLocalSelectList(vm);

            return(View("ModelForm", vm));
        }
Пример #3
0
        public async Task <IActionResult> SaveModel(long id, LotteryMode vm)
        {
            if (vm.AwardedNumber > 3 || vm.AwardedNumber < 1)
            {
                ModelState.AddModelError(string.Empty, "Error en la cantidad de numeros premiables");
            }
            if (vm.PlayableNumber > 8 || vm.PlayableNumber < 1)
            {
                ModelState.AddModelError(string.Empty, "Error en la cantidad de numeros jugables");
            }

            if (!ModelState.IsValid)
            {
                LoadLocalSelectList(vm);
                return(View("ModelForm", vm));
            }

            //var model = new LotteryMode();
            //vm.Transfer(ref model, null, false);

            if (vm.IsNew)
            {
                Context.Add(vm);
                await Context.SaveChangesAsync();

                var avails = await Context.Lotteries.ToListAsync();

                //LotteryAvailable avail;
                //foreach (var item in avails)
                //{
                //    avail = new LotteryAvailable { LotteryId = item.Id, LotteryModeId = vm.Id };
                //    Context.Add(avail);
                //}
            }
            else
            {
                if (id != vm.Id)
                {
                    return(NotFound());
                }

                var currentModel = await Context.LotteryModes.FindAsync(vm.Id);

                //Only Update the Neccesary fields
                vm.Transfer(ref currentModel, null, false);

                Context.Update(currentModel);
            }

            await Context.SaveChangesAsync();

            return(RedirectToAction(nameof(Details), new { id = vm.Id }));
        }
Пример #4
0
 private void LoadLocalSelectList(LotteryMode model)
 {
     //ViewData["Currencies"] = new SelectList(Context.Set<LotteryPrizes>(), "Id", "Name", model.CurrencyId);
     //ViewData["Periodicities"] = new SelectList(Context.Set<Periodicity>(), "Id", "Name", model.PeriodicityId);
 }