Example #1
0
        public bool AddToFavorite(int bookId, string login)
        {
            var globalBookLikes = _repo.GlobalBookLikes.GetAll()
                                  .SingleOrDefault(
                x => x.PersonProfile.Login == login && x.GlobalBook.GlobalBookId == bookId);

            if (globalBookLikes != null)
            {
                return(false);
            }
            var personProfile = _repo.PersonProfiles.GetAll().SingleOrDefault(x => x.Login == login);

            if (personProfile == null)
            {
                return(false);
            }
            var newDbEntry = _repo.GlobalBooks.GetById(bookId);

            if (newDbEntry == null)
            {
                return(false);
            }
            var newGlobalBookLike = new GlobalBookLike(newDbEntry, personProfile);

            _repo.GlobalBookLikes.Add(newGlobalBookLike);
            _repo.Commit();
            return(true);
        }
Example #2
0
        public GlobalBook Add(GlobalBook item, string login)
        {
            if (item == null)
            {
                throw new ArgumentNullException("item");
            }
            var dbEntry = _repo.PersonProfiles.GetAll().SingleOrDefault(x => x.Login == login);

            if (dbEntry != null)
            {
                GlobalBook antiDoubleGlobalBook = _repo.GlobalBooks.GetAll().SingleOrDefault(x => x.Title == item.Title);
                if (antiDoubleGlobalBook == null)
                {
                    var newDbEntry = new GlobalBookLike(item, dbEntry);
                    dbEntry.GlobalBookLikes.Add(newDbEntry);
                    _repo.PersonProfiles.Update(dbEntry);
                    _repo.Commit();
                    return(new GlobalBook());
                }
                return(null);
            }
            return(item);
        }