public void UpdateFlaggedBook(FlaggedBook currentEntity)
        {
            EvaluateAndSetIsFlaggedToRead(currentEntity);
            FlaggedBook originalEntity = this.ChangeSet.GetOriginal(currentEntity);

            this.DbContext.FlaggedBooks.AttachAsModified(currentEntity, originalEntity, this.DbContext);
        }
 private static void EvaluateAndSetIsFlaggedToRead(FlaggedBook entity)
 {
     // Determine IsFlaggedToRead based on Rating
     if (entity.Rating == 0)
     {
         entity.IsFlaggedToRead = 1;
     }
     else
     {
         entity.IsFlaggedToRead = 0;
     }
 }
Example #3
0
 public void InsertFlaggedBook(FlaggedBook flaggedBook)
 {
     if (flaggedBook != null)
     {
         if (flaggedBook.EntityState != EntityState.Detached)
         {
             this.ObjectContext.ObjectStateManager.ChangeObjectState(flaggedBook, EntityState.Added);
         }
         else
         {
             this.ObjectContext.FlaggedBooks.AddObject(flaggedBook);
         }
     }
 }
        public void DeleteFlaggedBook(FlaggedBook entity)
        {
            DbEntityEntry <FlaggedBook> entityEntry = this.DbContext.Entry(entity);

            if (entityEntry.State != EntityState.Deleted)
            {
                entityEntry.State = EntityState.Deleted;
            }
            else
            {
                this.DbContext.FlaggedBooks.Attach(entity);
                this.DbContext.FlaggedBooks.Remove(entity);
            }
        }
Example #5
0
 public void DeleteFlaggedBook(FlaggedBook flaggedBook)
 {
     if (flaggedBook != null)
     {
         if (flaggedBook.EntityState != EntityState.Detached)
         {
             this.ObjectContext.ObjectStateManager.ChangeObjectState(flaggedBook, EntityState.Deleted);
         }
         else
         {
             this.ObjectContext.FlaggedBooks.Attach(flaggedBook);
             this.ObjectContext.FlaggedBooks.DeleteObject(flaggedBook);
         }
     }
 }
        public void InsertFlaggedBook(FlaggedBook entity)
        {
            EvaluateAndSetIsFlaggedToRead(entity);

            DbEntityEntry <FlaggedBook> entityEntry = this.DbContext.Entry(entity);

            if (entityEntry.State != EntityState.Detached)
            {
                entityEntry.State = EntityState.Added;
            }
            else
            {
                this.DbContext.FlaggedBooks.Add(entity);
            }
        }
Example #7
0
        public void UpdateBook(BookViewModel bookViewModel)
        {
            FlaggedBook flaggedBook = this.GetFlaggedBooksForUser().FirstOrDefault(b => b.BookId == bookViewModel.Id);

            if (flaggedBook == null)
            {
                flaggedBook                 = new FlaggedBook();
                flaggedBook.ProfileId       = 1;
                flaggedBook.BookId          = bookViewModel.Id;
                flaggedBook.Rating          = bookViewModel.Rating;
                flaggedBook.IsFlaggedToRead = bookViewModel.Rating == 0 ? 1 : 0;
                DbContext.FlaggedBooks.Add(flaggedBook);
            }
            else
            {
                flaggedBook.Rating          = bookViewModel.Rating;
                flaggedBook.IsFlaggedToRead = bookViewModel.Rating == 0 ? 1 : 0;
            }
            DbContext.SaveChanges();
            FlaggedBooksForUser = null;
        }
Example #8
0
 public void UpdateFlaggedBook(FlaggedBook currentFlaggedBook)
 {
     this.ObjectContext.FlaggedBooks.AttachAsModified(currentFlaggedBook, this.ChangeSet.GetOriginal(currentFlaggedBook));
 }
 public BookViewModel()
 {
     Book        = new Book();
     FlaggedBook = new FlaggedBook();
 }