public IActionResult AddPictureAuthor(AddPictureAuthorViewModel addPictureAuthorViewModel) { if (ModelState.IsValid) { string _stackID = addPictureAuthorViewModel.StackID; int authorID = addPictureAuthorViewModel.AuthorID; List <int> pictureIDs = addPictureAuthorViewModel.PictureIDs; foreach (var pictureID in pictureIDs) { PictureAuthor pictureAuthor = new PictureAuthor() { PictureID = pictureID, AuthorID = authorID }; context.PictureAuthors.Add(pictureAuthor); } context.SaveChanges(); return(Redirect(string.Format("/Picture/AddPIctureAuthor?StackID={0}", _stackID))); } return(View(addPictureAuthorViewModel)); }
public IActionResult AddPictureAuthor(string stackID, string sortOrder) { ViewBag.Sorting = sortOrder; var selectAllPicturesWithoutAuthor = provider.SelectAllPicturesWhithoutAuthor(); var slectAllPictureWithoutAuthorNotYetClassified = selectAllPicturesWithoutAuthor .Where(p => p.PictureStackIsClassified == false) .AsQueryable(); if (stackID != null) { var selectAllPictureOfAStackWithoutAuthor = Sorting(sortOrder, slectAllPictureWithoutAuthorNotYetClassified) .Where(p => p.PictureStackID == int.Parse(stackID)) .AsQueryable(); string _stackID = stackID; var authors = context.Authors.ToList(); var pictureIDs = selectAllPictureOfAStackWithoutAuthor.Select(p => p.PictureID).ToList(); AddPictureAuthorViewModel addPictureAuthorViewModel = new AddPictureAuthorViewModel ( selectAllPictureOfAStackWithoutAuthor.ToList(), authors, pictureIDs, _stackID ); return(View(addPictureAuthorViewModel)); } else { var selectAllPictureOfAStackWithoutAuthor = Sorting(sortOrder, slectAllPictureWithoutAuthorNotYetClassified) .AsQueryable(); string _stackID = stackID; var authors = context.Authors.ToList(); var pictureIDs = selectAllPictureOfAStackWithoutAuthor.Select(p => p.PictureID).ToList(); AddPictureAuthorViewModel addPictureAuthorViewModel = new AddPictureAuthorViewModel ( selectAllPictureOfAStackWithoutAuthor.ToList(), authors, pictureIDs, _stackID ); return(View(addPictureAuthorViewModel)); } }