public Publisher UpdatePublisher(Publisher _publisher)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    Publisher oldpublisher = context.Publisher.FirstOrDefault(c => c.PublisherId == _publisher.PublisherId);
                    if (oldpublisher != null)
                    {
                        oldpublisher.PublisherName = _publisher.PublisherName;

                        oldpublisher.PublisherId = _publisher.PublisherId;
                        oldpublisher.IsActive = _publisher.IsActive;
                        
                        

                        context.SaveChanges();
                        return oldpublisher;
                    }
                    return null;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public Publisher DeletePublisher(int _id)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    Publisher publisher = context.Publisher.FirstOrDefault(cstm => cstm.PublisherId == _id);

                    context.Publisher.Remove(publisher);

                    int i = context.SaveChanges();

                    //return i > 0;
                    return publisher;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public User DeleteUser(int _id)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    User user = context.Users.FirstOrDefault(cstm => cstm.UserId == _id);

                    context.Users.Remove(user);

                    int i = context.SaveChanges();

                    return user;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public Publisher AddPublisher(Publisher _publisher)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    context.Publisher.Add(_publisher);

                    context.SaveChanges();
                    return _publisher;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public User AddUser(User _user)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Users.Add(_user);

                    context.SaveChanges();
                    return _user;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public User UpdateUser(User _user)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    User olduser = context.Users.FirstOrDefault(c => c.UserId == _user.UserId);
                    if (olduser != null)
                    {
                        olduser.FirstName = _user.FirstName;
                        olduser.LastName = _user.LastName;
                        olduser.Password = _user.Password;
                        

                        context.SaveChanges();
                        return olduser;
                    }
                    return null;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public Book UpdateBook(Book _book)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    Book oldbook = context.Books.FirstOrDefault(c => c.BookId == _book.BookId);
                    if (oldbook != null)
                    {
                        oldbook.BookName = _book.BookName;
                        oldbook.BookPages = _book.BookPages;
                        oldbook.BookPrice = _book.BookPrice;
                        oldbook.CategoryId = _book.CategoryId;

                        context.SaveChanges();
                        return oldbook;
                    }
                    return null;
                }
            }
            catch (Exception)
            {

                throw;
            }

        }
        public Book DeleteBook(int _bookId)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    Book book = context.Books.FirstOrDefault(cstm => cstm.BookId == _bookId);

                    context.Books.Remove(book);

                    int i = context.SaveChanges();

                    
                    return book;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public Book AddBook(Book _book)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    context.Books.Add(_book);

                    context.SaveChanges();
                    return _book;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public BorrowInfo DeleteBorrow(int _id)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    BorrowInfo borrow = context.BorrowInfoes.FirstOrDefault(cstm => cstm.BorrowId == _id);

                    context.BorrowInfoes.Remove(borrow);

                    int i = context.SaveChanges();

                    //return i > 0;
                    return borrow;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public BorrowInfo UpdateBorrowInfo(BorrowInfo _borrow)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    BorrowInfo oldborrow = context.BorrowInfoes.FirstOrDefault(c => c.BorrowId == _borrow.BorrowId);
                    if (oldborrow != null)
                    {
                        oldborrow.BorrowDate = _borrow.BorrowDate;
                        oldborrow.ReturnDate = _borrow.ReturnDate;
                        oldborrow.ReaderId = _borrow.ReaderId;
                        oldborrow.IsActive = _borrow.IsActive;
                        
                        

                        context.SaveChanges();
                        return oldborrow;
                    }
                    return null;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public Reader UpdateReader(Reader _reader)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    Reader oldreader = context.Readers.FirstOrDefault(c => c.ReaderId == _reader.ReaderId);
                    if (oldreader != null)
                    {
                        oldreader.FirstName = _reader.FirstName;
                        oldreader.LastName = _reader.LastName;
                        oldreader.Phone = _reader.Phone;
                        oldreader.Mail = _reader.Mail;

                        context.SaveChanges();
                        return oldreader;
                    }
                    return null;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
        public Reader AddReader(Reader _reader)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Readers.Add(_reader);

                    context.SaveChanges();
                    return _reader;
                }
            }
            catch (Exception)
            {

                throw;
            }
        }