ASP.Net C# MVC Lotto Lucky Pick Number Free Source Code

Let's play lotto lucky pick number using ASP.Net C# MVC coding... i share this code for fun and learn from it. This lotto lucky pick web application is currently used in my website www.pinoycode.com, you can visit and try to generate lotto lucky number. If you are newbies in C# MVC Web Application Developer using Microsoft Visual Studio Community Edition this sample code will help you learn basic programming logic.
Lotto Lucky Pick Generator Free Source Code

LottoData.cs (Model)

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.ComponentModel.DataAnnotations;
using System.ComponentModel.DataAnnotations.Schema;
using System.Linq;
using System.Web;
namespace sb_admin.web.Models
{
    public class play_lotto_game
    {
        [Required]
        public string gameplay { get; set; }
    }
}

PcsoController.cs (Controller)

using sb_admin.web.Context;
using sb_admin.web.Models;
using System;
using System.Collections;
using System.Collections.Generic;
using System.Data.Entity;
using System.Linq;
using System.Web;
using System.Web.Mvc;
namespace sb_admin.web.Controllers
{
    public class PcsoController : Controller
    {
        private ArrayList ArrayList_Number = new ArrayList();
        int ctr;

        // GET: Lotto Lucky Pick
        public ActionResult LottoLuckyPick()
        {
             return View();
        }

        [HttpPost]
        public ActionResult LottoLuckyPick(play_lotto_game obj)
        {
            if (ModelState.IsValid)
            {
                switch (obj.gameplay.ToString())
                {
                    case "game1":
                        ViewBag.LottoGeneratedNumber = Lotto_Generated(58);
                        break;
                    case "game2":
                        ViewBag.LottoGeneratedNumber = Lotto_Generated(55);
                        break;
                    case "game3":
                        ViewBag.LottoGeneratedNumber = Lotto_Generated(49);
                        break;
                    case "game4":
                        ViewBag.LottoGeneratedNumber = Lotto_Generated(45);
                        break;
                    case "game5":
                        ViewBag.LottoGeneratedNumber = Lotto_Generated(42);
                        break;
                    case "game6":
                        ViewBag.LottoGeneratedNumber = Digit6_Generated(9);
                        break;
                    case "game7":
                        ViewBag.LottoGeneratedNumber = Digit4_Generated(9);
                        break;
                    case "game8":
                        ViewBag.LottoGeneratedNumber = Digit3_Generated(9);
                        break;
                    case "game9":
                        ViewBag.LottoGeneratedNumber = EZ2_Generated(31);
                        break;
                }
                return View(obj);
            }
            else
            {
                return View();
            }
        }

        string Lotto_Generated(int LottoGame)
        {
            Random rand = new Random();
            int i = 0;
            int NumberPick = 0;
            string sLuckyNumber = null;
            bool bRandom = false;
            ArrayList_Number.Clear();
            while (bRandom == false)
            {
                NumberPick = rand.Next(1, LottoGame + 1);
                if (IsNotRead_Number(NumberPick) == false)
                {
                    ArrayList_Number.Add(NumberPick);
                    i += 1;
                    switch (i)
                    {
                        case 1:
                            sLuckyNumber = sLuckyNumber + NumberPick + "-";
                            break;
                        case 2:
                            sLuckyNumber = sLuckyNumber + NumberPick + "-";
                            break;
                        case 3:
                            sLuckyNumber = sLuckyNumber + NumberPick + "-";
                            break;
                        case 4:
                            sLuckyNumber = sLuckyNumber + NumberPick + "-";
                            break;
                        case 5:
                            sLuckyNumber = sLuckyNumber + NumberPick + "-";
                            break;
                        case 6:
                            sLuckyNumber = sLuckyNumber + NumberPick;
                            break;
                    }
                }
                if (i == 6)
                {
                    bRandom = true;
                }
            }
            return sLuckyNumber;
        }

        string Digit6_Generated(int LottoGame)
        {
            Random rand = new Random();
            int i = 0;
            int NumberPick = 0;
            string sLuckyNumber = null;
            bool bRandom = false;
            ArrayList_Number.Clear();
            while (bRandom == false)
            {
                NumberPick = rand.Next(0, LottoGame + 1);
                i += 1;
                switch (i)
                {
                    case 1:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 2:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 3:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 4:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 5:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 6:
                        sLuckyNumber = sLuckyNumber + NumberPick;
                        break;
                }
                if (i == 6)
                {
                    bRandom = true;
                }
            }
            return sLuckyNumber;
        }

        string Digit4_Generated(int LottoGame)
        {
            Random rand = new Random();
            int i = 0;
            int NumberPick = 0;
            string sLuckyNumber = null;
            bool bRandom = false;
            ArrayList_Number.Clear();
            while (bRandom == false)
            {
                NumberPick = rand.Next(0, LottoGame + 1);
                i += 1;
                switch (i)
                {
                    case 1:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 2:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 3:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 4:
                        sLuckyNumber = sLuckyNumber + NumberPick;
                        break;
                }
                if (i == 4)
                {
                    bRandom = true;
                }
            }
            return sLuckyNumber;
        }

        string Digit3_Generated(int LottoGame)
        {
            Random rand = new Random();
            int i = 0;
            int NumberPick = 0;
            string sLuckyNumber = null;
            bool bRandom = false;
            ArrayList_Number.Clear();
            while (bRandom == false)
            {
                NumberPick = rand.Next(0, LottoGame + 1);
                i += 1;
                switch (i)
                {
                    case 1:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 2:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 3:
                        sLuckyNumber = sLuckyNumber + NumberPick;
                        break;
                }
                if (i == 3)
                {
                    bRandom = true;
                }
            }
            return sLuckyNumber;
        }

        string EZ2_Generated(int LottoGame)
        {
            Random rand = new Random();
            int i = 0;
            int NumberPick = 0;
            string sLuckyNumber = null;
            bool bRandom = false;
            ArrayList_Number.Clear();
            while (bRandom == false)
            {
                NumberPick = rand.Next(1, LottoGame + 1);
                i += 1;
                switch (i)
                {
                    case 1:
                        sLuckyNumber = sLuckyNumber + NumberPick + "-";
                        break;
                    case 2:
                        sLuckyNumber = sLuckyNumber + NumberPick;
                        break;
                }
                if (i == 2)
                {
                    bRandom = true;
                }
            }
            return sLuckyNumber;
        }

        public bool IsNotRead_Number(int ID_No)
        {
            int num = 0;
            bool bFound = false;
            foreach (int num_loopVariable in ArrayList_Number)
            {
                num = num_loopVariable;
                if (num == ID_No)
                {
                    bFound = true;
                    break; 
                }
            }
            if (bFound == true)
            {
                return true;
            }
            else
            {
                return false;
            }
        }
    }
}

LottoLuckyPick.cshtml (View)

@model sb_admin.web.Models.play_lotto_game
@{
    ViewBag.Title = "Lotto Lucky Pick Number";
    Layout = "~/Views/Shared/_Layout.cshtml";
}
@section metatags {
    <title>Lotto Lucky Pick Number (6/58, 6/55, 6/49, 6/45, 6/42, EZ2, 6D, 4D, 3D)</title>
}
<div class="container-fluid">
    <div class="row">
        <div class="col-md-11">
            <div class="col-md-7" style="padding:0px">
                <h1><small><i class="fa fa-tags"></i> <a href="~/pcso/lotto-lucky-pick-number/">@ViewBag.Title</a></small></h1>
                @using (Html.BeginForm(FormMethod.Post))
                {
                    <label><i class="fa fa-hand-o-right"></i> SELECT LOTTO GAME</label>
                    @Html.DropDownList("gameplay", new List<SelectListItem>
                        { new SelectListItem {Text = "Ultra Lotto 6/58", Value = "game1" },
                            new SelectListItem {Text = "Grand Lotto 6/55", Value = "game2" },
                            new SelectListItem {Text = "Super Lotto 6/49", Value = "game3" },
                            new SelectListItem {Text = "Mega Lotto 6/45", Value = "game4" },
                            new SelectListItem {Text = "Lotto 6/42", Value = "game5" },
                            new SelectListItem {Text = "6 Digit Game (6D)", Value = "game6" },
                            new SelectListItem {Text = "4 Digit Game (4D)", Value = "game7" },
                            new SelectListItem {Text = "Suertres Lotto (3D)", Value = "game8" },
                            new SelectListItem {Text = "EZ2 Lotto (2D)", Value = "game9" }
                        }, "", new { @class = "form-control" })
                    @Html.ValidationMessageFor(model => model.gameplay, "", new { @class = "text-danger" })
                    <textarea style="text-align:center; padding:30px;font-size:x-large" class="form-control" rows="2" new { placeholder="Your Lucky Number" }>@ViewBag.LottoGeneratedNumber</textarea>
                    <input type="submit" id="submit" value="GET LUCKY NUMBER" class="btn btn-info col-lg-12" />
                }
            </div>
            <div class="col-md-5" style="text-align:center">
		<p>ads.....</p>
            </div>
        </div>
    </div>
</div>

Good Luck!!! ( Please Share... Thanks.)