public void CreateBook(BookWithAuthorsShort book) { //book.Tags = new List<TagBusinessModel>(); //var autlist = book.AuthorsId.Split(',').Select(int.Parse).ToList(); //var newTagsId = book.TagsId.Split(',').Select(int.Parse).ToList(); var mapper = new BookWithAuthorsShortMapper(); var bookNew = mapper.Map(book); foreach (var aut in book.Authors) { var author = this.uow.Authors.GetById(aut.id); bookNew.Authors.Add(author); } foreach (var tag in book.Tags) { var t = this.uow.Tags.GetById(tag.id); bookNew.Tags.Add(t); } this.uow.Items.Add(bookNew); this.uow.Commit(); book.Id = bookNew.Id; // updates the book.Id to Id value from DB }
public ActionResult Add([FromJson] BookWithAuthorsShort viewModel) { if (ModelState.IsValid) { this.bookInfoManager.CreateBookWithAuthors(viewModel); return(RedirectToAction("Index", new { viewModel.Id })); } return(View(viewModel)); }
public ActionResult Edit([FromJson] BookWithAuthorsShort viewModel) { if (ModelState.IsValid) { this.bookInfoManager.UpdateBookWithAuthors(viewModel); return(RedirectToAction("Details", new { id = viewModel.Id })); } return(View(viewModel)); }
public ActionResult Add([FromJson] BookWithAuthorsShort viewModel) { if (ModelState.IsValid) { this.bookInfoManager.CreateBookWithAuthors(viewModel); this.recommendationManager.RecalculateItemTagScoresAsync(viewModel.Id); return(this.RedirectToAction("IndexWithWidgets")); } return(this.PartialView("_AddBook", viewModel)); }
public ActionResult Edit([FromJson] BookWithAuthorsShort viewModel) { if (ModelState.IsValid) { this.bookInfoManager.UpdateBookWithAuthors(viewModel); this.recommendationManager.RecalculateItemTagScoresAsync(viewModel.Id); return(this.RedirectToAction("Details", new { id = viewModel.Id })); } return(this.View("_EditBook", viewModel)); }
public virtual ActionResult LoadPartial(string value) { switch (value) { case "book": var model1 = new BookWithAuthorsShort(); return(this.PartialView("_AddBook", model1)); case "disk": var model2 = new DiskBusinessModel(); return(this.PartialView("_AddDisk", model2)); case "magazine": var model3 = new MagazineBusinessModel(); return(this.PartialView("_AddMagazine", model3)); default: return(null); } }
public void UpdateBook(BookWithAuthorsShort book) { //book.Tags = new List<TagBusinessModel>(); var mapper = new BookWithAuthorsShortMapper(); //var autlist = book.AuthorsId.Split(',').Select(int.Parse).ToList(); //var newTagsId = book.TagsId.Split(',').Select(int.Parse).ToList(); var bookOld = this.uow.Items.GetById(book.Id) as Book; bookOld.Authors.Clear(); bookOld.Tags.Clear(); var bookMapped = mapper.Map(book); foreach (var aut in book.Authors) { var author = this.uow.Authors.GetById(aut.id); bookOld.Authors.Add(author); } foreach (var tag in book.Tags) { var t = this.uow.Tags.GetById(tag.id); bookOld.Tags.Add(t); } bookOld.Name = bookMapped.Name; bookOld.PageCount = bookMapped.PageCount; bookOld.Publisher = bookMapped.Publisher; bookOld.Year = bookMapped.Year; this.uow.Items.Update(bookOld); this.uow.Commit(); }
public void RemoveBookWithAuthors(BookWithAuthorsShort book) { this.bookWithAuthorsShortFacade.RemoveById(book.Id); }
public void CreateBookWithAuthors(BookWithAuthorsShort book) { this.bookWithAuthorsShortFacade.CreateBook(book); }
public void UpdateBookWithAuthors(BookWithAuthorsShort book) { this.bookWithAuthorsShortFacade.UpdateBook(book); }