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)); }
public void AddMusic(MusicDto music) { _musicRepository.AddMusic(new Music { UserId = music.UserId, UrlVideo = music.UrlVideo }); }
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(); }
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")); } }
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")); } }
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)); }
public async Task DeleteMusic([FromBody] MusicDto musicDto) { await _deleteMusicCommandHandler.Handler(musicDto.MusicId); }
public async Task AddMusic([FromBody] MusicDto musicDto) { await _addMusicCommandHandler.Handler(musicDto); }
public async Task Handler(MusicDto music) { _addMusicBusiness.AddMusic(music); await _musicRepository.UnitOfWork.Save(); }