コード例 #1
0
        public IActionResult AllBands()
        {
            MyPostView bigChungus = new MyPostView();

            bigChungus.bands = _context.Bands.Where(x => x.BandId > 0).OrderBy(x => x.BandId).Include(x => x.City).ToList();

            bigChungus.bands = parseBandDisplayNames(bigChungus.bands);

            return(View("AllBands", bigChungus));
        }
コード例 #2
0
        public IActionResult ShowBand(int id)
        {
            System.Console.WriteLine("Displaying band with id: " + id);
            MyPostView bigChungus = new MyPostView();

            bigChungus.band = _context.Bands.Include(x => x.City).FirstOrDefault(x => x.BandId == id);
            if (bigChungus.band == null)
            {
                bigChungus.band = _context.Bands.Include(x => x.City).FirstOrDefault(x => x.BandId == 0);
            }

            bigChungus.band.NiceRecords = _context.Records.Where(x => x.BandId == id).OrderBy(x => x.Year).ToList();

            return(View("ShowBand", bigChungus));
        }
コード例 #3
0
        public IActionResult ShowRecord(int id)
        {
            System.Console.WriteLine("Displaying record with id: " + id);
            MyPostView bigChungus = new MyPostView();

            bigChungus.record = _context.Records.Include(x => x.Songs).Include(x => x.Band).FirstOrDefault(x => x.RecordId == id);
            if (bigChungus.record == null)
            {
                bigChungus.record = _context.Records.Include(x => x.Songs).FirstOrDefault(x => x.RecordId == 0);
            }
            if (bigChungus.record.DisplayName == null)
            {
                bigChungus.record.DisplayName = bigChungus.record.Name;
            }
            if (bigChungus.record.Band.Name == null)
            {
                bigChungus.record.Band.DisplayName = bigChungus.record.Band.Name;
            }

            return(View("ShowRecord", bigChungus));
        }
コード例 #4
0
        public JsonResult UpdateRecord(int id, [FromBody] MyPostView body)
        {
            MyResponseView results = new MyResponseView();

            try
            {
                System.Console.WriteLine("Updating band where id is " + id);

                Record record = _context.Records.FirstOrDefault(x => x.RecordId == id);

                // If band is null, no band with id exists. Otherwise continues
                if (record == null)
                {
                    results.Success     = false;
                    results.RowsUpdated = 0;
                    System.Console.WriteLine("Failure! No record with id " + id + " exists! No records updated!");
                    results.Message = "Failure! No record with id " + id + " exists! No records updated!";
                    return(Json(results));
                }

                // If record is null, no record with id exists. Otherwise continues
                if (body.record == null)
                {
                    results.Success     = false;
                    results.RowsUpdated = 0;
                    System.Console.WriteLine("Failure! Modelstate Invalid! No records updated!");
                    results.Message = "Failure! Modelstate Invalid! No records updated!";
                    return(Json(results));
                }

                // If any of these fields exist in the body, overwrite them
                // Name, BandId, Year, LabelId, Zeitgeist, Certification, DisplayName
                if (body.record.Name != null)
                {
                    record.Name = body.record.Name;
                }
                if (body.record.DisplayName != null)
                {
                    record.DisplayName = body.record.DisplayName;
                }
                if (body.record.Year != 0)
                {
                    record.Year = body.record.Year;
                }
                if (body.record.Zeitgeist != 0)
                {
                    record.Zeitgeist = body.record.Zeitgeist;
                }
                if (body.record.Certification != null)
                {
                    record.Certification = body.record.Certification;
                }

                if (body.record.BandId != 0)
                {
                    if (_context.Bands.FirstOrDefault(x => x.BandId == body.record.BandId) != null)
                    {
                        record.BandId = body.record.BandId;
                    }
                }

                // Resets UpdatedAt timestamp
                record.UpdatedAt = DateTime.Now;

                _context.Update(record);
                _context.SaveChanges();

                results.Success     = true;
                results.RowsUpdated = 1;
                results.Message     = "Success! Record " + record.Name + " updated";

                return(Json(results));
            }
            catch (System.Exception)
            {
                // results.Songs = _context.Songs.ToList();
                results.Success     = false;
                results.RowsUpdated = 0;
                System.Console.WriteLine("Failure! An unknown error occured! No records updated!");
                results.Message = "Failure! An unknown error occured! No records updated!";
                return(Json(results));

                throw;
            }
        }
コード例 #5
0
        public JsonResult UpdateBand(int id, [FromBody] MyPostView body)
        {
            MyResponseView results = new MyResponseView();

            try
            {
                System.Console.WriteLine("Updating band where id is " + id);

                Band band = _context.Bands.FirstOrDefault(x => x.BandId == id);

                // If band is null, no band with id exists. Otherwise continues
                if (band == null)
                {
                    results.Success     = false;
                    results.RowsUpdated = 0;
                    System.Console.WriteLine("Failure! No band with id " + id + " exists! No bands updated!");
                    results.Message = "Failure! No band with id " + id + " exists! No bands updated!";
                    return(Json(results));
                }

                // If band is null, no band with id exists. Otherwise continues
                if (body.band == null)
                {
                    results.Success     = false;
                    results.RowsUpdated = 0;
                    System.Console.WriteLine("Failure! Modelstate Invalid! No Bands updated!");
                    results.Message = "Failure! Modelstate Invalid! No bands updated!";
                    return(Json(results));
                }

                // If any of these fields exist in the body, overwrite them
                if (body.band.Name != null)
                {
                    band.Name = body.band.Name;
                }
                if (body.band.DisplayName != null)
                {
                    band.DisplayName = body.band.DisplayName;
                }
                if (body.band.CityId != 0)
                {
                    band.CityId = body.band.CityId;
                }
                band.UpdatedAt = DateTime.Now;

                _context.Update(band);
                _context.SaveChanges();

                results.Success     = true;
                results.RowsUpdated = 1;
                results.Message     = "Success! Band " + band.Name + " updated";

                return(Json(results));
            }
            catch (System.Exception)
            {
                // results.Songs = _context.Songs.ToList();
                results.Success     = false;
                results.RowsUpdated = 0;
                System.Console.WriteLine("Failure! An unknown error occured! No bands updated!");
                results.Message = "Failure! An unknown error occured! No bands updated!";
                return(Json(results));

                throw;
            }
        }
コード例 #6
0
        public JsonResult UpdateSong(int id, [FromBody] MyPostView body)
        {
            MyResponseView results = new MyResponseView();

            try
            {
                System.Console.WriteLine("Updating song where id is " + id);

                Song song = _context.Songs.FirstOrDefault(x => x.SongId == id);

                // If song is null, no song with id exists. Otherwise continues
                if (song == null)
                {
                    results.Success     = false;
                    results.RowsUpdated = 0;
                    System.Console.WriteLine("Failure! No song with id " + id + " exists! No songs updated!");
                    results.Message = "Failure! No song with id " + id + " exists! No songs updated!";
                    return(Json(results));
                }

                // If body.song is null, model is invalid. Otherwise continues
                if (body.song == null)
                {
                    results.Success     = false;
                    results.RowsUpdated = 0;
                    System.Console.WriteLine("Failure! Modelstate Invalid! No songs updated!");
                    results.Message = "Failure! Modelstate Invalid! No songs updated!";
                    return(Json(results));
                }

                // If any of these fields exist in the body, overwrite them
                // Name, BandId, Year, LabelId, Zeitgeist, Certification, DisplayName
                if (body.song.Name != null)
                {
                    song.Name = body.song.Name;
                }
                if (body.song.TrackListing != 0)
                {
                    song.TrackListing = body.song.TrackListing;
                }
                if (body.song.Score != 0)
                {
                    song.Score = body.song.Score;
                }

                if (body.song.RecordId != 0)
                {
                    // If given record ID corresponds to an existing record, reassign record id
                    if (_context.Records.FirstOrDefault(x => x.RecordId == body.song.RecordId) != null)
                    {
                        song.RecordId = body.song.RecordId;
                    }
                }

                // Resets UpdatedAt timestamp
                song.UpdatedAt = DateTime.Now;

                _context.Update(song);
                _context.SaveChanges();

                results.Success     = true;
                results.RowsUpdated = 1;
                results.Message     = "Success! Song " + song.Name + " updated";

                return(Json(results));
            }
            catch (System.Exception e)
            {
                // results.Songs = _context.Songs.ToList();
                results.Success     = false;
                results.RowsUpdated = 0;
                System.Console.WriteLine("Failure! An unknown error occured! No songs updated!");
                System.Console.WriteLine(e);
                results.Message = "Failure! An unknown error occured! No songs updated!";
                return(Json(results));

                throw;
            }
        }