Example #1
0
        public ActionResult <SongRead> CreateSong(SongCreate newSong)
        {
            Request.Headers.TryGetValue("email", out var emailValue);
            Request.Headers.TryGetValue("UserName", out var userID);

            if (_repository.GetUserById(userID) == null)
            {
                if (userID != "")
                {
                    var user = new UserCreate();
                    user.name  = userID;
                    user.email = emailValue;
                    var userModel = _mapper.Map <UserData>(user);
                    _repository.CreateUser(userModel);
                    _repository.SaveChanges();
                }
                else
                {
                    return(Unauthorized("Invalid user"));
                }
            }

            var songModel = _mapper.Map <SongData>(newSong);

            _repository.CreateSong(songModel);
            _repository.SaveChanges();
            var songRead = _mapper.Map <SongRead>(songModel);

            return(Ok(songRead));
        }
Example #2
0
        public bool CreateSong(SongCreate model)
        {
            var entity = new Song()
            {
                OwnerId  = _userId,
                Title    = model.Title,
                ArtistId = model.ArtistId,
                GenreId  = model.GenreId,
                //AlbumId = model.AlbumId,
                Date = model.Date,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                var artistEntity = ctx.Artists.Find(model.ArtistId);
                var genreEntity  = ctx.Genres.Find(model.GenreId);
                //var albumEntity = ctx.Albums.Find(model.AlbumId);

                artistEntity.SongsByArtist.Add(entity);
                genreEntity.SongsInGenre.Add(entity);
                //albumEntity.SongsInAlbum.Add(entity);

                return(ctx.SaveChanges() == 1);
            }
        }
Example #3
0
        public ActionResult <SongResult> Post(Guid songbookId, [FromBody] SongCreate song)
        {
            if (song == null)
            {
                return(BadRequest());
            }

            _logger.LogDebug("SongController.Post called to create new song for songbook {@songbookId}: {@songbook}", songbookId, song);
            var songbook = _repository.GetById(songbookId);

            if (songbook == null)
            {
                _logger.LogWarning("Songbook.Post failed to add song {@song} to songbook {@songbookId}. Songbook was not found.", song, songbookId);
                return(NotFound());
            }

            var dto     = _mapper.Map <SongDto>(song);
            var newSong = Song.From(dto);

            //Perform validation
            if (!newSong.IsValid)
            {
                newSong.Validate().AddToModelState(ModelState, null);
                _logger.LogWarning("{method} failed model validation (ModelState: {@modelState}), returning Unprocessable Entity", nameof(Post), ModelState.Values.SelectMany(v => v.Errors));
                return(InvalidModelStateResponseFactory.GenerateResponseForInvalidModelState(ModelState, HttpContext));
            }

            songbook.Songs.Add(newSong);

            _repository.Save(songbook);

            return(CreatedAtRoute("GetSong", new { songbookId = newSong.SongbookId, id = newSong.Id }, newSong));
        }
Example #4
0
        public async Task <int> CreateSongCreateAsync(SongCreate songCreate)
        {
            await _context.SongCreates.AddAsync(songCreate);

            await _context.SaveChangesAsync();

            return(songCreate.Id);
        }
Example #5
0
        //CREATE
        public bool AddSong(SongCreate model)
        {
            var entity = new Song
            {
                AlbumId = model.AlbumId,
                Title   = model.Title,
            };

            _context.Songs.Add(entity);
            return(_context.SaveChanges() == 1);
        }
Example #6
0
        public bool CreateSong(SongCreate model)
        {
            var entity =
                new Song()
            {
                AlbumID = model.AlbumID
                          //SongName = model.SongName,
            };

            using (var db = new ApplicationDbContext())
            {
                db.Songs.Add(entity);
                return(db.SaveChanges() == 1);
            }
        }
Example #7
0
        //CREATE
        public bool CreateSong(SongCreate model)
        {
            var entity =
                new Song()
            {
                OwnerId  = _userId,
                SongName = model.SongName,
                AlbumId  = model.AlbumId,
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #8
0
        public async Task <int> UpdateSongCreateClassDetailsAsync(SongCreate songCreate)
        {
            var songCreateFromDb = await _context.SongCreates.FirstOrDefaultAsync(s => s.Id == songCreate.Id);

            songCreateFromDb.HymnTune            = songCreate.HymnTune;
            songCreateFromDb.Meter               = songCreate.Meter;
            songCreateFromDb.TextSourceScripture = songCreate.TextSourceScripture;
            songCreateFromDb.Title               = songCreate.Title;
            songCreateFromDb.CopyrightYear       = songCreate.CopyrightYear;
            songCreateFromDb.IsPublic            = songCreate.IsPublic;
            songCreateFromDb.SongCreateCanceled  = songCreate.SongCreateCanceled;
            songCreateFromDb.DateLastModified    = DateTime.Now;
            songCreateFromDb.LastModifiedById    = songCreate.LastModifiedById;

            return(await _context.SaveChangesAsync());
        }
Example #9
0
        /// <summary>
        /// Creates a new Song
        /// </summary>
        /// <param name="song"></param>
        /// <returns></returns>
        public IHttpActionResult Post(SongCreate song)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var service = CreateSongService();

            if (!service.CreateSong(song))
            {
                return(InternalServerError());
            }

            return(Ok());
        }
        public ActionResult Create(SongCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = new SongService();

            if (service.CreateSong(model))
            {
                TempData["SaveResult"] = "Song has been added";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Song was not added");
            return(View(model));
        }
        public bool CreateSong(SongCreate model)
        {
            var entity =
                new Song()
            {
                SongName      = model.SongName,
                GenreId       = model.GenreId,
                Album         = model.Album,
                Artist        = model.Artist,
                ChildFriendly = model.ChildFriendly
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #12
0
        public bool CreateSong(SongCreate model)
        {
            var entity =
                new Song()
            {
                OwnerId = _userId,
                Title   = model.Title,
                Length  = model.Length,
                AlbumId = model.AlbumId,
                GenreId = model.GenreId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
        public ActionResult Create(SongCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var service = CreateSongService();

            if (service.CreateSong(model))
            {
                TempData["SaveResult"] = "Your song was created.";
                return(RedirectToAction("Index"));
            }
            ;
            ModelState.AddModelError("", "Song could not be created.");
            return(View(model));
        }
        //CreateSong
        public bool CreateSong(SongCreate model)
        {
            var song = new Song()
            {
                Title    = model.Title,
                Genre    = model.Genre,
                ArtistID = model.ArtistID,
                AlbumID  = model.AlbumID,
                Runtime  = model.Runtime,
                Language = model.Language
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(song);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #15
0
        public bool CreateSong(SongCreate model)
        {
            var entity = new Song()
            {
                Id          = _userId,
                SongName    = model.SongName,
                SongArtist  = model.SongArtist,
                SongAlbum   = model.SongAlbum,
                ReleaseYear = model.ReleaseYear,
                CreatedUTC  = DateTimeOffset.Now,
                PlaylistId  = model.PlaylistId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #16
0
        public async Task <int> CreateSongAsync(SongCreate songCreate, string userId, int churchId)
        {
            var song = new Song()
            {
                Title = songCreate.Title,
                TextSourceScripture = songCreate.TextSourceScripture,
                HymnTune            = songCreate.HymnTune,
                Meter             = songCreate.Meter,
                CopyrightYear     = songCreate.CopyrightYear,
                MakePublic        = songCreate.IsPublic,
                CreatedById       = userId,
                LastModifiedById  = userId,
                CreatedByChurchId = churchId,
                DateCreated       = DateTime.Now,
                DateLastModified  = DateTime.Now
            };

            return(await _songRepository.CreateSongAsync(song));
        }
        public bool CreateSong(SongCreate model)
        {
            var entity =
                new Song()
            {
                SongId     = model.SongId,
                SongName   = model.SongName,
                AlbumName  = model.AlbumName,
                SongLength = model.SongLength,
                ArtistName = model.ArtistName,
                SongGenre  = model.SongGenre
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #18
0
        public ActionResult Create(SongCreate model)
        {
            if (!ModelState.IsValid)
            {
                PopulateAlbums();
                return(View(model));
            }

            var context = new ApplicationDbContext();

            foreach (var songName in model.Songs)
            {
                Song newSong = new Song {
                    AlbumID = model.AlbumID, SongName = songName
                };
                context.Songs.Add(newSong);
            }

            context.SaveChanges();

            return(RedirectToAction("Details", "Album", new { id = model.AlbumID }));
        }
Example #19
0
        //private readonly HttpClient _client = new HttpClient();
        //private readonly string baseUrl = "https://"

        //static async Task RunAsync()
        //{
        //    HttpClient client = new HttpClient();
        //    client.BaseAddress = new Uri("api.genius.com/");
        //    client.DefaultRequestHeaders.Authorization.Parameter("Vmh_ponNylhxlYbfhWLOUf2wMkdSCAxysqztJJJfj8-sLL02NcIwxZ3Bjd1Wo48D");

        //}

        public bool CreateSong(SongCreate model)
        {
            var entity =
                new Song()
            {
                AlbumID    = model.AlbumID,
                Title      = model.Title,
                Lyrics     = model.Lyrics,
                IsExplicit = model.IsExplicit,

                AlbumName = model.AlbumName,
                ProfileId = model.ProfileId

                            // PlaylistId = model.PlaylistId
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Songs.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Example #20
0
 public async Task <int> UpdateSongCreateClassDetailsAsync(SongCreate songCreate)
 {
     return(await _songRepository.UpdateSongCreateClassDetailsAsync(songCreate));
 }
Example #21
0
 /// <summary>
 /// Creates a new SongCreate object in the database.
 /// </summary>
 /// <param name="songCreate"></param>
 /// <returns>The Id that the database generated for the new SongCreate</returns>
 public async Task <int> CreateSongCreateAsync(SongCreate songCreate)
 {
     return(await _songRepository.CreateSongCreateAsync(songCreate));
 }