public async Task <SongCreateModel> SaveSong(SongCreateModel model) { Songs song = new Songs { AlbumId = model.AlbumId, Duration = model.Duration, SongName = model.SongName, SongThumb = model.SongThumb }; _context.Add(song); _context.SaveChanges(); var songsDetail = model.SongDetails.Select(x => new SongsDetail { ArtistId = x.ArtistId, ArtistType = x.ArtistType, SongId = song.SongId }); _context.AddRange(songsDetail); await _context.SaveChangesAsync(); model.SongId = song.SongId; return(model); }
public async Task <SongCreateModel> GetSongById(Int64 id) { SongCreateModel songViewModel = null; var song = await _context.Songs.FindAsync(id); if (song != null) { var songDetail = _context.SongsDetail.Where(x => x.SongId == id).Select(x => new SongDetailCreateModel { ArtistId = x.ArtistId, ArtistType = x.ArtistType, SongId = x.SongId, SongsDetailId = x.SongDetailId }).ToList(); songViewModel = new SongCreateModel { AlbumId = song.AlbumId, Duration = song.Duration, SongId = song.SongId, SongName = song.SongName, SongThumb = song.SongThumb, SongDetails = songDetail }; } return(songViewModel); }
public async Task AddSong(SongCreateModel songModel) { var json = JsonSerializer.Serialize <SongCreateModel>(songModel); Console.WriteLine(json); var content = new StringContent(json, Encoding.UTF8, "application/json-patch+json"); await HttpClient.PutAsync("api/v1/song/", content); }
public async Task <IActionResult> Post([FromBody] SongCreateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var song = await _songService.SaveSong(model); return(CreatedAtAction("Get", new { id = song.SongId }, model)); }
public IHttpActionResult Post(SongCreateModel model) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var songService = new SongService(Guid.Parse(User.Identity.GetUserId())); return(Ok(songService.CreateSong(model))); }
/// <summary> /// Creates song, example URL call can be found in test folder. /// </summary> /// <param name="model">Created songs details.</param> /// <returns>Message describing the action result.</returns> public async Task <string> Post([FromBody] SongCreateModel model) { if (!ModelState.IsValid) { throw new HttpResponseException(HttpStatusCode.BadRequest); } var songId = await SongFacade.CreateSongWithAlbumNameAsync(model.Song, model.AlbumName); if (songId.Equals(Guid.Empty)) { throw new HttpResponseException(HttpStatusCode.BadRequest); } return($"Created song with id: {songId}, within {model.AlbumName} album."); }
public ActionResult Create(SongCreateModel model) { if (!ModelState.IsValid) { return(View(model)); } if (!CreateSongService().CreateSong(model)) { ModelState.AddModelError("", "Unable to create note"); return(View(model)); } TempData["SaveResult"] = "Your note was created"; return(RedirectToAction("Index")); }
public bool CreateSong(SongCreateModel model) { var entity = new SongEntity() { OwnerId = _userId, Title = model.Title, Content = model.Content, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Song.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(SongCreateModel model) { if (!ModelState.IsValid) { return(View(model)); } var service = CreateSongService(); if (service.CreateSong(model)) { TempData["SaveResult"] = "Your Song was successfully created!"; return(RedirectToAction("Index")); } ModelState.AddModelError("", "Your Song could not be created."); return(View(model)); }
public bool CreateSong(SongCreateModel model) //Method CreateSong is using SongCreateModel from RMS.Models and making a new model from that. { var entity = //SongEntity is created and stored within entity new SongEntity() { OwnerId = _userId, Title = model.Title, Content = model.Content, CreatedUtc = DateTimeOffset.Now, Link = model.Link }; using (var ctx = new ApplicationDbContext()) { ctx .Songs .Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create() { var model = new SongCreateModel(); return(View(model)); }