public void Execute(object book) { Book bookModel = Mapper.Instance.Map <Book>(book); bookModel.Id = Guid.NewGuid(); ContextTracker.AttackBookRelatedEntries(bookModel); ApplicationDbContext.Instance.Entry(bookModel).State = EntityState.Added; ApplicationDbContext.Instance.SaveChanges(); ApplicationDbContext.Instance.ChangeTracker.Clear(); }
public void Execute(object book) { Book bookModel = Mapper.Instance.Map <Book>(book); ContextTracker.AttackBookRelatedEntries(bookModel); var bookFromDb = ApplicationDbContext.Instance.Books .Include(a => a.Authors) .Include(a => a.Categories) .Include(a => a.PublishingHouse) .Include(a => a.Series) .Include(a => a.StoragePlace) .Single(a => a.Id == bookModel.Id); Mapper.Instance.Map(bookModel, bookFromDb); ApplicationDbContext.Instance.SaveChanges(); }