Exemplo n.º 1
0
    public void AddArtist(NewArtist c)
    {
        Artist artist = new Artist();

        artist.ArtistName        = c.ArtistName;
        artist.ArtistEmail       = c.ArtistEmail;
        artist.ArtistKey         = c.ArtistKey;
        artist.ArtistWebPage     = c.ArtistWebPage;
        artist.ArtistDateEntered = DateTime.Now;

        db.Artists.Add(artist);
        db.SaveChanges();
    }
Exemplo n.º 2
0
        public async Task AddArtist_Given_NewArtist_ModelState_Not_Valid_Return_400_BadRequestObjectResult()
        {
            var artist = new NewArtist()
            {
                Name = "",
                ProfilePictureURL = "",
                BeatportUrl       = "",
                SoundCloudUrl     = ""
            };

            var retval = await _artistController.AddArtistAsync(artist);

            Assert.IsInstanceOfType(retval, typeof(BadRequestObjectResult));
        }
Exemplo n.º 3
0
        public async Task <string> InsertArtistAsync(NewArtist newArtist)
        {
            var artist = new Artist()
            {
                Name = newArtist.Name,
                ProfilePictureURL = newArtist.ProfilePictureURL,
                BeatportUrl       = newArtist.BeatportUrl,
                SoundCloudUrl     = newArtist.SoundCloudUrl
            };

            var artistId = await mongoDBPersistance.InsertOneArtistAsync(artist);

            return(artistId);
        }
Exemplo n.º 4
0
        public ValidationMessage ValidateNewArtistModel(NewArtist newArtist)
        {
            if (newArtist == null)
            {
                return new ValidationMessage()
                {
                    resultValid = false,
                    message = "Artist Model not provided!"
                };

            }

            return new ValidationMessage()
            {
                resultValid = true,
            };

        }
Exemplo n.º 5
0
        /// <summary>
        /// Insert a new artist in the database, or return its ID if it already exists.
        /// </summary>
        /// <param name="artist">The artist to insert.</param>
        /// <returns>The ID of the new artist inserted, or the existing ID if it is a duplicate.</returns>
        public async Task <long> CreateArtist(NewArtist artist)
        {
            //var existingArtist = await GetArtistByName(artist.Name);
            //if (existingArtist != null)
            //{
            //    return existingArtist.Id;
            //}

            using (var connection = new SqlConnection(_connectionString))
            {
                var cmd = new CommandDefinition(SqlStatements.InsertArtist, new { name = artist.Name, country = artist.Country });
                await connection.OpenAsync();

                var artistId = await connection.ExecuteScalarAsync <long>(cmd);

                return(artistId);
            }
        }
Exemplo n.º 6
0
        public async Task AddArtistAsync_Given_NewArtist_Should_Return_Id()
        {
            var artist = new NewArtist()
            {
                Name = "Primal Nature",
                ProfilePictureURL = "http://www.primalnature.com/artist.png",
                BeatportUrl       = "http://www.beatport.com/primalnature/",
                SoundCloudUrl     = "http://www.soundcloud.com/primalnature/"
            };

            string id = Guid.NewGuid().ToString();

            artistManager
            .Setup(s => s.InsertArtistAsync(It.IsAny <NewArtist>()))
            .Returns(Task.FromResult(id));

            var retval = await _artistController.AddArtistAsync(artist) as CreatedResult;

            Assert.AreEqual(id, retval.Value);
        }
Exemplo n.º 7
0
        public async Task AddArtist_Given_NewArtist_Not_Added_Return_400_BadRequestObjectResult()
        {
            var artist = new NewArtist()
            {
                Name = "Primal Nature",
                ProfilePictureURL = "http://www.primalnature.com/artist.png",
                BeatportUrl       = "http://www.beatport.com/primalnature/",
                SoundCloudUrl     = "http://www.soundcloud.com/primalnature/"
            };

            var id = Guid.NewGuid().ToString();

            artistManager
            .Setup(s => s.InsertArtistAsync(It.IsAny <NewArtist>()))
            .Returns(Task.FromResult((string)null));

            var retval = await _artistController.AddArtistAsync(artist);

            Assert.IsInstanceOfType(retval, typeof(BadRequestObjectResult));
        }
Exemplo n.º 8
0
        public void InsertArtistAsync_Given_Artist_Should_Return_Guid_Id()
        {
            var artist = new NewArtist()
            {
                Name = "Primal Nature",
                ProfilePictureURL = "http://www.primalnature.com/artist.png",
                BeatportUrl       = "http://www.beatport.com/primalnature/",
                SoundCloudUrl     = "http://www.soundcloud.com/primalnature/"
            };

            var id = Guid.NewGuid().ToString();

            mongoDBPersistance
            .Setup(s => s.InsertOneArtistAsync(It.IsAny <Artist>()))
            .Returns(Task.FromResult(id));

            var retval = _artistManager.InsertArtistAsync(artist);

            Assert.IsTrue(Guid.TryParse(id, out _));
        }
Exemplo n.º 9
0
        // [Authorize]
        public async Task <IActionResult> AddArtistAsync(NewArtist newArtist)
        {
            logger.LogInformation($"AddArtist Body: {newArtist} - Resource Requested.");

            var validateArtist = validation.ValidateNewArtistModel(newArtist);

            if (validateArtist.resultValid)
            {
                if (ModelState.IsValid)
                {
                    var id = await artistManager.InsertArtistAsync(newArtist);

                    if (id != null)
                    {
                        return(Created(id, id));
                    }
                }
                else
                {
                    return(BadRequest(ModelState));
                }
            }
            return(BadRequest(validateArtist.message));
        }