public ActionResult Create([Bind(Include = "ArtistName,DOB,BirthCity")]  Artist artist)
        {
            string[] DOB  = artist.DOB.Split('/');//probably more effective way to check birth days but....
            int      ay   = Int32.Parse(DOB[2]);
            int      am   = Int32.Parse(DOB[0]);
            int      ad   = Int32.Parse(DOB[1]);
            int      yyyy = DateTime.Now.Year;
            int      mm   = DateTime.Now.Month;// jan is month 0
            int      dd   = DateTime.Now.Day;

            if (ay > yyyy)
            {
                TempData["testmsg"] = "<script>alert('Birth day out of bounds ');</script>";
                return(View());
            }
            else if (ay == yyyy && am > mm)
            {
                TempData["testmsg"] = "<script>alert('Birth day out of bounds ');</script>";
                return(View());
            }
            else if (ay == yyyy && am == mm && ad > dd)
            {
                TempData["testmsg"] = "<script>alert('Birth day out of bounds ');</script>";
                return(View());
            }

            else if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
        public ActionResult Create([Bind(Include = "ArtistKey,ArtistName,BirthDate,BirthCity")] Artist artist)
        {
            //Vareables to check the date and compare for non-sencical dates.
            int toDateY = DateTime.Now.Year;
            int toDateM = DateTime.Now.Month;
            int toDateD = DateTime.Now.Day;
            // artBY => Artist birth year ect. ect.
            int artBY, artBM, artBD;

            string[] artDates = artist.BirthDate.Split('-');
            // they will only parse if valide enteries
            if (int.TryParse(artDates[0], out artBY))
            {
            }
            else
            {
                artBY = 9999;
            }
            if (int.TryParse(artDates[1], out artBM))
            {
            }
            else
            {
                artBM = 99;
            }
            if (int.TryParse(artDates[2], out artBD))
            {
            }
            else
            {
                artBD = 99;
            }


            if (artBY > toDateY)
            {
                TempData["testmsg"] = "<script>alert('This is an invalide date.');</script>";
                return(View());
            }
            else if ((artBY == toDateY) && (artBM > toDateM))
            {
                TempData["testmsg"] = "<script>alert('This is an invalide date.');</script>";
                return(View());
            }
            else if ((artBY == toDateY) && (artBM == toDateM) && (artBD > toDateD))
            {
                TempData["testtmsg"] = "<script>alert('This is an invalide date.');</script>";
                return(View());
            }
            else if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }



            return(View(artist));
        }
예제 #3
0
 public IActionResult Create(Review view)
 {
     if (ModelState.IsValid)
     {
         _context.Review.Add(view);
         _context.SaveChanges();
         return(RedirectToAction("Index", new { id = view.ArtistId }));
     }
     return(View(view));
 }
        public ActionResult Create([Bind(Include = "ArtistID,ArtistName,DOB,BirthCity")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
예제 #5
0
        public ActionResult Create([Bind(Include = "ID,Name,Age,Band")] Artist artist)
        {
            if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
예제 #6
0
        public ActionResult Create(Artist artist)
        {
            if (ModelState.IsValid)
            {
                db.Artists.Add(artist);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(artist));
        }
예제 #7
0
        public ActionResult Create([Bind(Include = "SongID,Titel,Duration,Genre")] Song song)
        {
            if (ModelState.IsValid)
            {
                db.Songs.Add(song);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            return(View(song));
        }
예제 #8
0
        public IActionResult Create([FromBody] Artist item)
        {
            if (item == null)
            {
                return(BadRequest());
            }

            _artistContext.Artists.Add(item);
            _artistContext.SaveChanges();

            return(CreatedAtRoute("GetArtist", new { id = item.Id }, item));
        }
예제 #9
0
        public ActionResult Create([Bind(Include = "ArtWorkID,Title,ArtistID")] ArtWork artWork)
        {
            if (ModelState.IsValid)
            {
                db.ArtWorks.Add(artWork);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtistID = new SelectList(db.Artists, "ArtistID", "ArtistName", artWork.ArtistID);
            return(View(artWork));
        }
예제 #10
0
        public ActionResult Create([Bind(Include = "ClassificationID,ArtWorkID,GenreID")] Classification classification)
        {
            if (ModelState.IsValid)
            {
                db.Classifications.Add(classification);
                db.SaveChanges();
                return(RedirectToAction("Index"));
            }

            ViewBag.ArtWorkID = new SelectList(db.ArtWorks, "ArtWorkID", "Title", classification.ArtWorkID);
            ViewBag.GenreID   = new SelectList(db.Genres, "GenreID", "GenreName", classification.GenreID);
            return(View(classification));
        }
        private async void appBarButtonRefresh_Click(object sender, RoutedEventArgs e)
        {
            var artistLibraryList = await ConnectionHelper.ExecuteRequest(_remote.Host, _remote.Port, _remote.User, _remote.Pass, JsonHelper.JsonCommandAudioLibraryGetArtist());

            if (artistLibraryList != "statusError" && artistLibraryList != "connectionError")
            {
                var artistList = GetInformationHelper.getAudioLibraryArtist(artistLibraryList);

                if (artistList != null)
                {
                    // clear the database
                    deleteArtist();

                    using (var db = new ArtistContext())
                    {
                        try
                        {
                            db.Artists.AddRange(artistList);
                            db.SaveChanges();
                            loadMusic();
                        }
                        catch (Exception ex)
                        {
                            Debug.WriteLine(ex.Message);
                        }
                    }
                }
            }
        }
예제 #12
0
        public ActionResult Create(FormCollection collection)
        {
            try
            {
                var newArtist = db.Artists.Create();

                newArtist.Name      = collection["Name"];
                newArtist.BirthCity = collection["BirthCity"];
                newArtist.BirthDate = collection["BirthDate"];

                db.Artists.Add(newArtist);
                db.SaveChanges();

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
        // delete all artist in database
        private void deleteArtist()
        {
            using (var db = new ArtistContext())
            {
                try
                {
                    db.Artists.RemoveRange(db.Artists.ToList());

                    db.SaveChanges();
                }
                catch (Exception ex)
                {
                    Debug.WriteLine(ex.Message);
                }
            }
        }
예제 #14
0
        public IEnumerable <Artist> GetArtistsSecret()
        {
            var Bus = RabbitHutch.CreateBus("host=localhost");
            ConcurrentStack <Artist> artistsCollection = new ConcurrentStack <Artist>();

            Bus.Receive <RabbitArtist>("artist", msg =>
            {
                Artist artist = new Artist()
                {
                    ArtistName = msg.ArtistName, LastFmRating = msg.LastFmRating
                };
                artistsCollection.Push(artist);
            });
            Thread.Sleep(5000);

            foreach (Artist a in artistsCollection)
            {
                _context.Add(a);
            }
            _context.SaveChanges();
            return(_context.Artists);
        }
예제 #15
0
        void GenerateData()
        {
            for (int i = 0; i < 30; ++i)
            {
                var tracks = new List<Track>();
                var albums = new List<Album>();
                var genre = new Genre()
                {
                    Name = "Rock"
                };

                var artist = new Artist()
                {
                    Name = "Name",
                    Genre = genre,
                    Albums = albums
                };

                albums.Add(new Album()
                {
                    Name = "Album",
                    Artist = artist,
                    Tracks = tracks
                });

                tracks.Add(new Track()
                {
                    Name = "Track",
                    Artist = artist,
                    Album = albums[0],
                    Duration = 10,
                });

                _artistContext.Add(artist);
            }
            _artistContext.SaveChanges();
        }
예제 #16
0
        public static void Initialize(IServiceProvider serviceProvider)
        {
            using (var context = new ArtistContext(
                       serviceProvider.GetRequiredService <
                           DbContextOptions <ArtistContext> >()))
            {
                Artist artist1 = new Artist()
                {
                    Name       = "Robert John Downey Jr",
                    DayOfBirth = DateTime.Parse("1965-4-4"),
                    Education  = "Santa Monica High School",
                    Hometown   = "New York"
                };

                Artist artist2 = new Artist()
                {
                    Name       = "Christopher Robert Evans",
                    DayOfBirth = DateTime.Parse("1981-6-13"),
                    Education  = "Unknown",
                    Hometown   = "Boston,Massachusetts,US"
                };

                Artist artist3 = new Artist()
                {
                    Name       = "Elizabeth Chase Olsen",
                    DayOfBirth = DateTime.Parse("1989-2-16"),
                    Education  = "New York University",
                    Hometown   = "Los Angeles,California,US"
                };


                //----------------------------------------------------

                MavelCharacter character1 = new MavelCharacter()
                {
                    Name     = "Tony stark",
                    HeroName = "Iron man",
                    Power    = "Smart,Rich,Iron man suit",
                    Artist   = artist1
                };

                MavelCharacter character2 = new MavelCharacter()
                {
                    Name     = "Steven Rogers",
                    HeroName = "Captain America",
                    Power    = "Sodier and Shield",
                    Artist   = artist2
                };

                MavelCharacter character3 = new MavelCharacter()
                {
                    Name     = "Wanda Maximoff",
                    HeroName = "Scarlet Witch",
                    Power    = "Mind Stone",
                    Artist   = artist3
                };

                //-----------------------------------------------------------

                List <Movies> movies = new List <Movies>()
                {
                    new Movies()
                    {
                        Name        = "Sherlock Holmes",
                        ReleaseYear = 2011,
                        Role        = "Sherlock Holmes",
                        Artist      = artist1
                    },
                    new Movies()
                    {
                        Name        = "Game 6",
                        ReleaseYear = 2005,
                        Role        = "Steven Schwimmer",
                        Artist      = artist1
                    },
                    new Movies()
                    {
                        Name        = "The Judge",
                        ReleaseYear = 2014,
                        Role        = "Hank Palmer",
                        Artist      = artist1
                    }
                    //--------------------------------

                    ,
                    new Movies()
                    {
                        Name        = "Fantastic Four",
                        ReleaseYear = 2005,
                        Role        = "Johnny Storm",
                        Artist      = artist2
                    },
                    new Movies()
                    {
                        Name        = "Scott Pilgrim vs the World",
                        ReleaseYear = 2010,
                        Role        = "Lucas Lee",
                        Artist      = artist2
                    },
                    new Movies()
                    {
                        Name        = "Cellular",
                        ReleaseYear = 2004,
                        Role        = "Ryan",
                        Artist      = artist2
                    }

                    //-----------------------------------

                    ,
                    new Movies()
                    {
                        Name        = "Silent House",
                        ReleaseYear = 2011,
                        Role        = "Sarah",
                        Artist      = artist3
                    },
                    new Movies()
                    {
                        Name        = "Very Good Girls",
                        ReleaseYear = 2013,
                        Role        = "Gerry Fields",
                        Artist      = artist3
                    },
                    new Movies()
                    {
                        Name        = "Oldboy",
                        ReleaseYear = 2014,
                        Role        = "Marie Sebastian",
                        Artist      = artist3
                    }
                };

                context.Artists.Add(artist1);
                context.Artists.Add(artist2);
                context.Artists.Add(artist3);


                context.MavelCharacters.Add(character1);
                context.MavelCharacters.Add(character2);
                context.MavelCharacters.Add(character3);


                foreach (var item in movies)
                {
                    context.Movies.Add(item);
                }

                context.SaveChanges();
            }
        }
예제 #17
0
        static void Main(string[] args)
        {
            var optionsBuilder = new DbContextOptionsBuilder <ArtistContext>()
                                 .UseSqlServer(@"Server=DESKTOP-5A54U6A;Database=ArtistContext;Trusted_Connection=True;MultipleActiveResultSets=true");

            using (var context = new ArtistContext(optionsBuilder.Options))
            {
                Console.WriteLine("Starting parsing of artists...");
                using (var reader = new StreamReader(@"C:\Users\dahi1\musicbrainzdata\mbdump\artist"))
                {
                    int counter = 1;
                    while (!reader.EndOfStream)
                    {
                        var line = reader.ReadLine();
                        Console.WriteLine(line);
                        var values = line.Split('\t');
                        Console.WriteLine($"Extracted {values.Length} values");
                        Artist art;
                        try
                        {
                            art = new Artist() // See order here -> https://github.com/metabrainz/musicbrainz-server/blob/master/admin/sql/CreateTables.sql#L208
                            {
                                Gid              = new Guid(values[1]),
                                Name             = values[2],
                                Sort_name        = values[3],
                                Begin_date_year  = values[4] == "\\N" ? null : (int?)int.Parse(values[4]),
                                Begin_date_month = values[5] == "\\N" ? null : (int?)int.Parse(values[5]),
                                Begin_date_day   = values[6] == "\\N" ? null : (int?)int.Parse(values[6]),
                                End_date_year    = values[7] == "\\N" ? null : (int?)int.Parse(values[7]),
                                End_date_month   = values[8] == "\\N" ? null : (int?)int.Parse(values[8]),
                                End_date_day     = values[9] == "\\N" ? null : (int?)int.Parse(values[9]),
                                Type             = values[10] == "\\N" ? null : (int?)int.Parse(values[10]),
                                Area             = values[11] == "\\N" ? null : (int?)int.Parse(values[11]),
                                Gender           = values[12] == "\\N" ? null : (int?)int.Parse(values[12]),
                                Comment          = values[13],
                                Edits_pending    = values[14] == "\\0" ? null : (int?)int.Parse(values[14]),
                                Last_updated     = values[15] == "\\N" ? null : (DateTime?)DateTime.Parse(values[15]),
                                Ended            = values[16] == "t",
                                Begin_area       = values[17] == "\\N" ? null : (int?)int.Parse(values[17]),
                                End_area         = values[18] == "\\N" ? null : (int?)int.Parse(values[18])
                            };
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Couldn't parse artist");
                            Console.WriteLine(e);
                            continue;
                        }
                        Console.WriteLine($"Successfully parsed artist {art.Name}");
                        context.Artists.Add(art);
                        if (counter >= 100)
                        {
                            try
                            {
                                Console.WriteLine("Saving batch of artists to DB...");
                                var result = context.SaveChanges();
                                Console.WriteLine($"Saved {result} artists !");
                                counter = 0;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Couldn't save artists to database");
                                Console.WriteLine(e);
                                return;
                            }
                        }
                        counter++;
                    }
                }
                try
                {
                    Console.WriteLine("Finished parsing artists, saving to database...");
                    var result = context.SaveChanges();
                    Console.WriteLine($"Saved {result} artists !");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Couldn't save artists to database");
                    Console.WriteLine(e);
                    return;
                }



                Console.WriteLine("Starting parsing of releases...");
                using (var reader = new StreamReader(@"C:\Users\dahi1\musicbrainzdata\mbdump\release"))
                {
                    int counter = 1;
                    while (!reader.EndOfStream)
                    {
                        var line = reader.ReadLine();
                        Console.WriteLine(line);
                        var values = line.Split('\t');
                        Console.WriteLine($"Extracted {values.Length} values");
                        Release rel;
                        try
                        {
                            rel = new Release() // See order here -> https://github.com/metabrainz/musicbrainz-server/blob/master/admin/sql/CreateTables.sql#L208
                            {
                                Gid           = new Guid(values[1]),
                                Name          = values[2],
                                Artist_credit = int.Parse(values[3]),
                                Release_group = int.Parse(values[4]),
                                Status        = values[5] == "\\N" ? null : (int?)int.Parse(values[5]),
                                Packaging     = values[6] == "\\N" ? null : (int?)int.Parse(values[6]),
                                Language      = values[7] == "\\N" ? null : (int?)int.Parse(values[7]),
                                Script        = values[8] == "\\N" ? null : (int?)int.Parse(values[8]),
                                Barcode       = values[9],
                                Comment       = values[10],
                                Edits_pending = values[11] == "\\0" ? null : (int?)int.Parse(values[11]),
                                Quality       = values[12] == "\\-1" ? null : (int?)int.Parse(values[12]),
                                Last_updated  = values[13] == "\\N" ? null : (DateTime?)DateTime.Parse(values[13])
                            };
                        }
                        catch (Exception e)
                        {
                            Console.WriteLine("Couldn't parse release");
                            Console.WriteLine(e);
                            continue;
                        }
                        Console.WriteLine($"Successfully parsed release {rel.Name}");
                        context.Releases.Add(rel);
                        if (counter >= 100)
                        {
                            try
                            {
                                Console.WriteLine("Saving batch of releases to DB...");
                                var result = context.SaveChanges();
                                Console.WriteLine($"Saved {result} releases !");
                                counter = 0;
                            }
                            catch (Exception e)
                            {
                                Console.WriteLine("Couldn't save releases to database");
                                Console.WriteLine(e);
                                return;
                            }
                        }
                        counter++;
                    }
                }
                try
                {
                    Console.WriteLine("Finished parsing releases, saving to database...");
                    var result = context.SaveChanges();
                    Console.WriteLine($"Saved {result} releases !");
                }
                catch (Exception e)
                {
                    Console.WriteLine("Couldn't save releases to database");
                    Console.WriteLine(e);
                    return;
                }
            }
        }
예제 #18
0
 public void SaveChanges()
 {
     Context.SaveChanges();
 }