Exemplo n.º 1
0
        public IActionResult Index()
        {
            // Check if Karaoke is accepting requests
            using (var db = new SongDBContext())
            {
                try
                {
                    Configuration state = db.Configurations.Where(
                        s => s.key == Constants.KARAOKE_STATE_FLAG).FirstOrDefault();
                    if (state == null || state.value == Constants.STOPPED_FLAG)
                    {
                        return(View("NotStarted"));
                    }
                }
                catch (InvalidOperationException)
                {
                    return(View("NotStarted"));
                }
                catch (IndexOutOfRangeException)
                {
                    return(View("NotStarted"));
                }
            }

            String singerNameCookie = Request.Cookies[SINGERNAME_COOKIE];

            SongRequest songRequest = new SongRequest();

            songRequest.singerName = singerNameCookie;
            songRequest.songId     = 1;

            return(View("Index", songRequest));
        }
Exemplo n.º 2
0
        public ActionResult SubmitBtn(SongRequest songRequest)
        {
            if (ModelState.IsValid)
            {
                string singerName = songRequest.singerName;
                using (var db = new SongDBContext())
                {
                    try
                    {
                        string[] fields = songRequest.title.Trim().Split(" par ");
                        String   query  = fields[0] + fields[1];
                        Artist   artist = (Artist)db.KaraokeArtists.Where(a => a.Name == fields[1]).First();
                        Song     song   = (Song)db.KaraokeSongs.Where(s => s.Title == fields[0] && s.ArtistId == artist.Id).First();
                        if (song != null)
                        {
                            Request request = new Request();
                            request.SingerName  = singerName;
                            request.SongId      = song.Id;
                            request.Notes       = songRequest.notes;
                            request.RequestTime = DateTime.Now;
                            db.KaraokeRequests.Add(request);
                            db.SaveChanges();
                        }
                    }
                    catch (IndexOutOfRangeException)
                    {
                        ViewData["SubmitSong"] = "La chanson demandée n'existe pas";
                        return(View("Index", songRequest));
                    }
                    catch (InvalidOperationException)
                    {
                        ViewData["SubmitSong"] = "La chanson demandée n'existe pas";
                        return(View("Index", songRequest));
                    }
                    catch (ArgumentNullException)
                    {
                        ViewData["SubmitSong"] = "La chanson demandée n'existe pas";
                        return(View("Index", songRequest));
                    }

                    ModelState.Clear();

                    ViewData["SubmitSong"] = "Demande effectuée avec succès à " + String.Format("{0:HH:mm:ss}", DateTime.Now);
                    CookieOptions cookieOption = new CookieOptions();

                    cookieOption.Expires = DateTime.Now.AddDays(30);
                    Response.Cookies.Append(SINGERNAME_COOKIE, singerName, cookieOption);
                }

                SongRequest newRequest = new SongRequest();
                newRequest.singerName = singerName;

                return(View("Index", newRequest));
            }

            return(View("Index"));
        }
Exemplo n.º 3
0
 public SongController(UserManager <ApplicationUser> userManager, SongDBContext songContext, MySongsDBContext mySongContext)
 {
     _Context        = songContext;
     _MySongsContext = mySongContext;
     _user           = userManager;
 }