public void AddBookTagBook(Int32 bookTag_Id, Int32 book_Id)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         db.AddBookTagBook(bookTag_Id, book_Id);
     }
 }
 public void AddBookAuthor(Int32 book_Id, Int32 author_Id)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         db.AddBookAuthor(book_Id, author_Id);
     }
 }
 public void AddPublisherBook(Int32 publisher_Id, Int32 book_Id)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         db.AddPublisherBook(publisher_Id, book_Id);
     }
 }
 public void Edit(BookVariableInfo bookVariableInfo)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         db.EditBookVariableInfo(bookVariableInfo.Id,
             bookVariableInfo.ProductCount, bookVariableInfo.Price);
     }
 }
 public void Edit(UserProfile newUserProfile)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         db.EditUserProfile(newUserProfile.UserId, newUserProfile.UserName,
             newUserProfile.IndividualId);
     }
 }
 public object FindIndividualByUserProfileName(string userProfileName)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         var items = db.FindIndividualByUserProfileName(userProfileName);
         var item = items.FirstOrDefault();
         return item;
     }
 }
 //BookVariableInfo и Book связь 1:1
 public BookVariableInfo FindByBookId(Int32 id)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         var items = db.FindBookVariableInfoByBookId(id);
         var item = items.FirstOrDefault<BookVariableInfo>();
         return item;
     }
 }
 public object FindById(Int32 id)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         var items = db.FindAuthorById(id);
         var item = items.FirstOrDefault();
         return item;
     }
 }
        //BasketItem basketItem)
        public void Delete(Int32 basketItemId)
        {
            BasketItem oldBasketItem;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.DeleteBasketItem(basketItemId);
            }
        }
 public Publisher FindByName(string name)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         var items = db.FindPublisherByName(name);
         var item = items.FirstOrDefault<Publisher>();
         return item;
     }
 }
        public object Add(object item)
        {
            Publisher publisher = (Publisher)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddPublisher(publisher.Name);
            }
            return GetAll().publishers.Last();
        }
 public void Edit(W1Payment newW1Payment)
 {
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         db.EditW1Payment(newW1Payment.WMI_PAYMENT_NO,
             newW1Payment.WMI_MERCHANT_ID, newW1Payment.WMI_CURRENCY_ID,
             newW1Payment.WMI_DESCRIPTION, newW1Payment.WMI_EXPIRED_DATE,
             newW1Payment.WMI_PAYMENT_AMOUNT, newW1Payment.WMI_SIGNATURE);
     }
 }
        public object Add(object item)
        {
            Language language = (Language)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddLanguage(language.Name);
            }
            return GetAll().languages.Last();
        }
 public object FindById(Int32 id)
 {
     //var item = this._db.WebMoneys.Find(id);
     using (BookMarketDbContext db = new BookMarketDbContext())
     {
         var items = db.FindWebmoneyById(id);
         var item = items.FirstOrDefault();
         return item;
     }
 }
        public object Add(object item)
        {
            Author author = (Author)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddAuthor(author.LastName, author.FirstName);
            }
            return GetAll().authors.Last();
        }
        //oldPayment и newPayment указывают на один и тот же экземпляр, но
        //для надежности оставлю обмен значений полей
        public void Edit(Payment newPayment)
        {
            Payment oldPayment;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.EditPayment(newPayment.Id, newPayment.isPayed,
                    newPayment.ShopId, newPayment.IndividualId);
            }
        }
        public object Add(object item)
        {
            City city = (City)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddCity(city.Name);
            }

            return GetAll().cities.Last();
        }
        public void Edit(BasketItem newBasketItem)
        {
            BasketItem oldBasketItem;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.EditBasketItem(newBasketItem.Id, newBasketItem.Amount,
                    newBasketItem.ItemCount, newBasketItem.BookVariableInfoId,
                    newBasketItem.BasketId, newBasketItem.PaymentId);
            }
        }
        public object Add(object item)
        {
            BookTag bookTag = (BookTag)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddBookTag(bookTag.Name, bookTag.BookTypeId);
            }

            return GetAll().bookTags.Last();
        }
        public object Add(object item)
        {
            Book book = (Book)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                var ret = db.AddBook(book.Name, book.Year, book.PageCount, book.ImageName,
                    book.Description, book.LanguageId);
            }
            return GetAll().books.Last();
        }
        public UserProfile FindByUserName(string userName)
        {
            UserProfile item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                var items = db.FindUserProfileByUserName(userName).ToList();
                item = items.FirstOrDefault<UserProfile>();
                return item;
            }
        }
        public object Add(object item)
        {
            BookVariableInfo bookVariableInfo = (BookVariableInfo)item;

            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddBookVariableInfo(bookVariableInfo.Id,
                    bookVariableInfo.ProductCount, bookVariableInfo.Price);
            }
            return GetAll().bookVariableInfoes.Last();
        }
        public object Add(object item)
        {
            WebMoney webmoney = (WebMoney)item;

            /*this._db.WebMoneys.Add(webmoney);
            this._db.SaveChanges();*/
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                db.AddWebMoney(webmoney.WMR, webmoney.IndividualId);
            }
            return GetAll().webmoneys.Last();
        }
        public IList<Author> FindAllAuthorsByBook(Int32 bookId)
        {
            IList<Author> books;

            books = new List<Author>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.FindAllAuthorsByBook(bookId))
                    books.Add(entry);
            }
            return books;
        }
        public IList<BookTag> FindBookTagsByBook(Int32 bookId)
        {
            List<BookTag> bookTags;

            bookTags = new List<BookTag>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.FindBookTagsByBook(bookId))
                    bookTags.Add(entry);
            }
            return bookTags;
        }
        public IList<Publisher> FindAllByBook(Int32 bookId)
        {
            IList<Publisher> items;

            items = new List<Publisher>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.FindPublishersByBook(bookId))
                    items.Add(entry);
            }
            return items;
        }
        //Так как связь City и Address 1:1, то ищем адрес по Id Shop
        public IList<Shop> FindAllByCity(Int32 cityId)
        {
            IList<Shop> items;

            items = new List<Shop>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.FindAllShopsByCity(cityId))
                    items.Add(entry);
            }
            return items;
        }
        public IList<string> GetNames()
        {
            List<string> names;

            names = new List<string>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.GetShopNames())
                    names.Add(entry);
            }
            return names;
        }
        public IList<BasketItem> FindBasketItemsByPayment(Int32 paymentId)
        {
            IList<BasketItem> items;

            items = new List<BasketItem>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.FindBasketItemsByPayment(paymentId))
                    items.Add(entry);
            }

            return items;
        }
        public ModelToModel GetAll()
        {
            ModelToModel mm;

            mm = new ModelToModel();
            mm.authors = new List<Author>();
            using (BookMarketDbContext db = new BookMarketDbContext())
            {
                foreach (var entry in db.GetAllAuthors())
                    mm.authors.Add(entry);
            }
            return mm;
        }