public async Task <IActionResult> Post([FromBody] MusicDto musicDto)
        {
            // See GetAllMusic() action method above for explanation
            var correlationToken = CorrelationTokenManager.GenerateToken();

            if (!ModelState.IsValid)
            {
                _logger.LogError(LoggingEvents.CatalogPost,
                                 $"ModelState invalid for product update. Request:{correlationToken}. Error:{ModelState.Values}");
                return(BadRequest(ModelState));
            }

            var response = await _restClient.PostAsync <MusicDto>(ServiceEnum.Catalog,
                                                                  "api/Catalog", correlationToken, musicDto);

            if (response.Data == null)
            {
                _logger.LogError(LoggingEvents.CatalogPost,
                                 $"Product not added:{response.ErrorMessage} for request:{correlationToken}");
                return(StatusCode((int)response.HttpStatusCode, response.ErrorMessage));
            }

            _logger.LogInformation(LoggingEvents.CatalogPost,
                                   $"Product added for request:{correlationToken}");

            return(new ObjectResult(response.Data));
        }
        public async Task <ActionResult <MusicDto> > GetMusic(int id)
        {
            var music = await _musicService.GetMusicById(id);

            MusicDto dto = _mapper.Map <Music, MusicDto>(music);

            return(Ok(dto));
        }
Exemplo n.º 3
0
 public void AddMusic(MusicDto music)
 {
     _musicRepository.AddMusic(new Music
     {
         UserId   = music.UserId,
         UrlVideo = music.UrlVideo
     });
 }
Exemplo n.º 4
0
        private void BtnCreate_Click(object sender, EventArgs e)
        {
            MusicDto musicsList = new MusicDto
            {
                Id          = null,
                Title       = tBTitle.Text,
                ReleaseDate = dateTimePickerSortie.Value,
                Genre       = tBGenre.Text,
                Price       = tBPrice.Text,
                Rating      = tBRating.Text
            };
            string musicJson = JsonConvert.SerializeObject(musicsList);

            Console.WriteLine(musicJson);


            // Create a request using a URL that can receive a post.
            WebRequest request = WebRequest.Create("https://mvcmusiclist.azurewebsites.net/api/MusicAPI/WinForm");

            // Set the Method property of the request to POST.
            request.Method = "POST";
            // Set the ContentType property of the WebRequest.
            request.ContentType = "application/json";

            // Create POST data and convert it to a byte array.
            string postData = musicJson;

            byte[] byteArray = Encoding.UTF8.GetBytes(postData);
            // Set the ContentLength property of the WebRequest.
            request.ContentLength = byteArray.Length;

            // Get the request stream.
            Stream dataStream = request.GetRequestStream();

            // Write the data to the request stream.
            dataStream.Write(byteArray, 0, byteArray.Length);
            // Close the Stream object.
            dataStream.Close();

            // Get the response.
            using (WebResponse response = request.GetResponse())
            {
                // Display the status.
                Console.WriteLine(((HttpWebResponse)response).StatusDescription);
                using (Stream responseStream = response.GetResponseStream())
                {
                    StreamReader rdr  = new StreamReader(responseStream, Encoding.UTF8);
                    string       Json = rdr.ReadToEnd(); // response from server
                }
                // Close the response.
                response.Close();
            }


            Close();
        }
Exemplo n.º 5
0
        public ActionResult UpdateMusic([FromBody] MusicDto obj)
        {
            try
            {
                var music = new Music(obj.Name, obj.Gender, obj.Composer, obj.ArtistId, obj.Feats, obj.BeatMaker, obj.Producer, obj.Band, obj.Lyric, obj.Id);

                _musicRepository.Update(music);

                return(StatusCode(200, "Music Updated sucessfully!!"));
            }
            catch (Exception ex)
            {
                return(StatusCode(400, "Music not Updated"));
            }
        }
Exemplo n.º 6
0
        public ActionResult AddMusic([FromBody] MusicDto obj)
        {
            try
            {
                var music = new Music(obj.Name, obj.Gender, obj.Composer, obj.ArtistId, obj.Feats, obj.BeatMaker, obj.Producer, obj.Band, obj.Lyric);

                _musicRepository.Post(music);

                return(StatusCode(201, "Music Added Sucessfuly!!"));
            }
            catch (Exception ex)
            {
                return(StatusCode(406, "Music Was not added, sorry"));
            }
        }
Exemplo n.º 7
0
        public async Task <IActionResult> Post([FromBody] MusicDto musicDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            // Generate correlationToken
            var correlationToken = CorrelationTokenManager.GenerateToken();

            var updatedAlbum = await _restClient.PostAsync <MusicDto>(ServiceEnum.Catalog,
                                                                      $"api/Catalog/?correlationToken={correlationToken}", musicDto);

            return(new ObjectResult(updatedAlbum));
        }
Exemplo n.º 8
0
 public async Task DeleteMusic([FromBody] MusicDto musicDto)
 {
     await _deleteMusicCommandHandler.Handler(musicDto.MusicId);
 }
Exemplo n.º 9
0
 public async Task AddMusic([FromBody] MusicDto musicDto)
 {
     await _addMusicCommandHandler.Handler(musicDto);
 }
Exemplo n.º 10
0
        public async Task Handler(MusicDto music)
        {
            _addMusicBusiness.AddMusic(music);

            await _musicRepository.UnitOfWork.Save();
        }