public async Task Create(SongInputModel model, string userId) { Song song = model.To <Song>(); song.UserId = userId; await this.context.Songs.AddAsync(song); await this.context.SaveChangesAsync(); }
public async Task <IActionResult> Post(SongInputModel model) { if (!this.ModelState.IsValid) { return(this.BadRequest()); } var userId = this.userManager.GetUserId(this.User); await this.songService.Create(model, userId); return(this.StatusCode(StatusCodes.Status201Created)); }
public int CreateNewSong(SongInputModel song) { var entity = new Song { Name = song.Name, Duration = song.Duration, CreatedDate = DateTime.Now, ModifiedDate = DateTime.Now }; _dbContext.Songs.Add(entity); _dbContext.SaveChanges(); return(entity.Id); }
public ActionResult AddSong(SongInputModel model) { if (!this.ModelState.IsValid) { return(this.View(model)); } var artistId = this.users.UserIdByUsername(this.User.Identity.GetName()); var song = new Song() { Name = model.Name, ArtistId = artistId }; var newSong = this.songs.Add(song); this.TempData["Notification"] = $"You added the song {newSong.Name} successfully!"; return(this.RedirectToAction("Index", "Home", new { area = string.Empty })); }
public ActionResult AddSong(SongInputModel model) { if (!this.ModelState.IsValid) { return this.View(model); } var artistId = this.users.UserIdByUsername(this.User.Identity.GetName()); var song = new Song() { Name = model.Name, ArtistId = artistId }; var newSong = this.songs.Add(song); this.TempData["Notification"] = $"You added the song {newSong.Name} successfully!"; return this.RedirectToAction("Index", "Home", new { area = string.Empty }); }
public int CreateNewSong(SongInputModel song) { return(_songRepository.CreateNewSong(song)); }
public IActionResult CreateNewSong([FromBody] SongInputModel song) { var newId = _songService.CreateNewSong(song); return(CreatedAtRoute("GetSongById", new { id = newId }, null)); }