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 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();
        }
Exemplo n.º 3
0
 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;
     }
 }