Example #1
0
        public List<User> GetUsers()
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    return context.Users.ToList();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
      public List<Publisher> GetPublisheres()
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    return context.Publisher.ToList();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
Example #3
0
        public List<BorrowInfo> GetBorrowInfoes()
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Configuration.ProxyCreationEnabled = false;
                    return context.BorrowInfoes.ToList();
                }
            }
            catch (Exception)
            {

                throw;
            }
        }
Example #4
0
        public Book GetBookById(int _id)
        {
            try
            {
                using (var contex = new LibrarySystemEntities())
                {
                    contex.Configuration.ProxyCreationEnabled = false;
                    contex.Configuration.LazyLoadingEnabled = false;
                    Book book = contex.Books.FirstOrDefault(c => c.BookId == _id);

                    return book;
                }


            }
            catch (Exception)
            {

                throw;
            }
        }
        public Publisher GetPublisherById(int _id)
        {
            try
            {
                using (var contex = new LibrarySystemEntities())
                {
                    contex.Configuration.ProxyCreationEnabled = false;
                    contex.Configuration.LazyLoadingEnabled = false;
                    Publisher publisher = contex.Publisher.FirstOrDefault(c => c.PublisherId == _id);

                    return publisher;
                }


            }
            catch (Exception)
            {

                throw;
            }
        }
Example #6
0
        public User GetUserById(int _id)
        {
            try
            {
                using (var contex = new LibrarySystemEntities())
                {

                    contex.Configuration.LazyLoadingEnabled = false;
                    User user = contex.Users.FirstOrDefault(c => c.UserId == _id);

                    return user;
                }


            }
            catch (Exception)
            {

                throw;
            }
        }
        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;
            }
        }
Example #8
0
        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 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;
            }
        }
Example #10
0
        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;
            }
        }
Example #11
0
        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;
            }
        }
Example #12
0
        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;
            }
        }
Example #13
0
        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 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;
            }
        }
Example #15
0
        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;
            }
        }
Example #16
0
        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;
            }

        }
Example #17
0
        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;
            }
        }
Example #18
0
        public User AddUser(User _user)
        {
            try
            {
                using (var context = new LibrarySystemEntities())
                {
                    context.Users.Add(_user);

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

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

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

                throw;
            }
        }