public void AddBook(IBookModule bookOp)
        {
            Console.Clear();
            Console.Write(StringLiterals.BookNameLabel);
            string name = Console.ReadLine();

            Console.Write(StringLiterals.DeptNameLabel);
            string dept = Console.ReadLine();

            Console.Write(StringLiterals.AuthorNameLabel);
            string author = Console.ReadLine();

            if (name == StringLiterals.nullLabel && dept == StringLiterals.nullLabel && author == StringLiterals.nullLabel)
            {
                Console.WriteLine(StringLiterals.ValidationsErrorMsg);
            }
            else
            {
                Console.WriteLine(bookOp.AddBook(new BookModel()
                {
                    Name = name, Department = dept, AuthorName = author, IsAvailable = true, IsActive = true
                }));
            }
        }
Beispiel #2
0
        /// <summary>
        /// Exectution starts from here
        /// </summary>
        /// <param name="args"></param>
        static void Main(string[] args)
        {
            IAuthentication obj = BALFactory.GetAuthenticationObject();

            Console.BackgroundColor = ConsoleColor.Black;
            Console.Clear();
            Console.ForegroundColor = ConsoleColor.Green;
AuthenticationPage:

            Console.WriteLine("Enter Admin Mail id");
            string adminid = Console.ReadLine();


            Console.WriteLine("Enter Admin Password");
            string pwd = Console.ReadLine();



            bool result = obj.Authenticate(new AuthModel
            {
                Email    = adminid,
                Password = pwd
            });

            if (result)
            {
                IUserModule uobj = BALFactory.GetUserModuleObject();
                IBookModule bobj = BALFactory.GetBookModuleObject();
                Console.WriteLine("\nLogin Sucessfull");
                bool logout = false;
                do
                {
                    Console.WriteLine("\n--------MENU--------");
                    Console.WriteLine("\n1) To Logout\n" + "\n2)Add Book\n" + "\n3)Get All Books\n" + "\n4)Lists NotActive Books\n" + "\n5)Make a Book Disable\n" +
                                      "\n6)Enable Book\n" + "\n7)Issue a Book\n" + "\n8)Return Book\n" +
                                      "\n9)Lists Available Books in BookHistoryDateBase\n" + "\n10)Add users\n" + "\n11)To Exit from the Application\n"
                                      + "\n12)Lists The all Users Details\n" + "\n13)Check Availabliity of Books");
                    Console.WriteLine("\nEnter your choice");
                    int choice = Convert.ToInt32(Console.ReadLine());
                    switch (choice)
                    {
                    case 1:
                    {
                        Console.WriteLine("Logout Sucessfully");
                        logout = true;
                        //To Login Again
                        goto AuthenticationPage;
                    }

                    case 2:
                    {
                        Console.WriteLine("\nEnter Book Name");
                        string bookname = Console.ReadLine();
                        Console.WriteLine("\nEnter Author Name");
                        string authorname = Console.ReadLine();
                        Console.WriteLine("\nEntet Department");
                        string dept       = Console.ReadLine();
                        int    lastBookId = bobj.LastBookId();
                        lastBookId += 1;
                        Console.WriteLine("\nEntet Number of copies to add");
                        int bookcount = Convert.ToInt32(Console.ReadLine());
                        for (int i = 0; i < bookcount; i++, lastBookId++)
                        {
                            bobj.AddBook(new BookModel
                                {
                                    BookID     = lastBookId,
                                    Name       = bookname,
                                    AuthorName = authorname,
                                    Department = dept,
                                    IsActive   = true
                                });
                        }
                        Console.WriteLine(+bookcount + "Added Sucessfully");
                        break;
                    }

                    case 3:
                    {
                        IEnumerable <BookModel> GetAllBooks = bobj.GetAllBooks(true);
                        Console.WriteLine("\n------Entire Books in Library are -------\n");
                        foreach (BookModel item in GetAllBooks)
                        {
                            Console.WriteLine("\nBookId \t:{0}\nBook Name\t:{1}\nAuthor Name\t:{2}\nDepartment\t:{3}", item.BookID, item.Name, item.AuthorName, item.Department);
                        }
                        break;
                    }

                    case 4:
                    {
                        IEnumerable <BookModel> listsbooks = bobj.ListDisableBooks(false);
                        Console.WriteLine("\n------NotActive Books in Library are -------\n");
                        foreach (BookModel item in listsbooks)
                        {
                            Console.WriteLine("\nBookId \t:{0}\nBook Name\t:{1}\nAuthor Name\t:{2}\nDepartment\t:{3}", item.BookID, item.Name, item.AuthorName, item.Department);
                        }
                        break;
                    }

                    case 5:
                    {
                        Console.WriteLine("Enter BookId to diable");
                        int bookId = Convert.ToInt32(Console.ReadLine());
                        bobj.DisableBook(bookId);
                        break;
                    }

                    case 6:
                    {
                        Console.WriteLine("Enter BookId to Enable");
                        int bookid = Convert.ToInt32(Console.ReadLine());
                        bobj.EnableBook(bookid);
                        break;
                    }

                    case 7:
                    {
                        Console.WriteLine("Enter BookId to Issue");
                        int bookid = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Enter userId");
                        int userid = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Enter AdminId at present who is issuing the books to the users");
                        int      adminId  = Convert.ToInt32(Console.ReadLine());
                        DateTime?returnat = null;
                        Console.WriteLine("\nEnter Any remarks");
                        string remarks = Console.ReadLine();

                        bobj.IssueBook(new BookHistoryModel
                            {
                                BookID = bookid,
                                UserID = userid,
                                OperationPerofrmedAt = DateTime.Now,
                                ReturnedAt           = returnat,
                                PerformedByID        = adminId,
                                Remarks    = remarks,
                                IsAvilable = false
                            });
                        break;
                    }

                    case 8:
                    {
                        Console.WriteLine("Enter Userid who is returning the book");
                        int userId = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Enter bookId");
                        int bookId = Convert.ToInt32(Console.ReadLine());
                        //DateTime? returnat = null;
                        Console.WriteLine("\nDid you found remarks");
                        string remarks = Console.ReadLine();
                        bobj.ReturnBook(userId, bookId);



                        break;
                    }

                    case 9:
                    {
                        IEnumerable <BookHistoryModel> history = bobj.EntireHistory();
                        foreach (BookHistoryModel item in history)
                        {
                            Console.WriteLine("\nBookID \t:{0}\nUserId \t:{1}\nAdmin ID{2}\nBook Returned\t:{3}\nAvailability\t:{4}\nAny Remarks\t:{5}"
                                              , item.BookID, item.UserID, item.PerformedByID, item.ReturnedAt, item.IsAvilable, item.Remarks);
                        }
                        break;
                    }

                    case 10:
                    {
                        Console.WriteLine("Enter New userid");        //UserID=1, Name="User1", Email="Author1", IsActive=true, Password="******", IsAdmin=true
                        int userId = Convert.ToInt32(Console.ReadLine());
                        Console.WriteLine("Enter name for user");
                        string name = Console.ReadLine();
                        Console.WriteLine("Enter New Email Id");
                        string email = Console.ReadLine();
                        Console.WriteLine("Enter some password to new user");
                        string password = Console.ReadLine();
                        Console.WriteLine("Did you want to make user as admin or not");
                        string admin = Console.ReadLine();
                        uobj.AddUser(new UserModel
                            {
                                UserID   = userId,
                                Name     = name,
                                Email    = email,
                                IsActive = true,
                                Password = "******",
                                IsAdmin  = true
                            });
                        break;
                    }

                    case 11:
                    {
                        //this.close();
                        Environment.Exit(0);
                        break;
                    }

                    //UserID=1, Name="User1", Email="Author1", IsActive=true, Password="******", IsAdmin=true
                    case 12:
                    {
                        Console.WriteLine("Entire User Details are");
                        IEnumerable <UserModel> userlist = uobj.GetAllUserDetails(true || false);
                        foreach (UserModel item in userlist)
                        {
                            Console.WriteLine("\nUserID\t:{0}\nName\t:{1}\nEmail\t:{2}\nIsActive\t:{3}\nPassword\t:{4}\nIsAdmin" +
                                              item.UserID, item.Name, item.Email, item.IsActive, item.Password, item.IsAdmin);
                        }
                        break;
                    }

                    case 13:
                    {
                        Console.WriteLine("Enter Book name to check");
                        string bookname = Console.ReadLine();
                        var    count    = bobj.CheckBookAvailability(bookname);
                        if (count > 0)
                        {
                            Console.WriteLine(" \n{0} Books are Available", count);
                        }
                        else
                        {
                            Console.WriteLine("No Book Found");
                        }

                        break;
                    }
                    }
                }while (!logout);
                Console.WriteLine("You are Logged out Sucessfully");
            }
        }
        public static int AdminChoiceSelect()
        {
            IBookModule BookChoice = BALFactory.GetBookModuleObject();
            int         choice;

            Console.WriteLine(StringLiterals.Welcome);
            Console.WriteLine(StringLiterals.AdminChoice);
            Console.Write(StringLiterals.ChoiceEntry);
            choice = Int32.Parse(Console.ReadLine());
            switch (choice)
            {
            case 1:
                Console.Clear();
                Console.WriteLine(StringLiterals.EnterBookDetails);
                Console.Write(StringLiterals.BookName);
                string _bookName = Console.ReadLine();
                Console.Write(StringLiterals.BookAuthor);
                string _bookAuthor = Console.ReadLine();
                Console.Write(StringLiterals.BookDepartment);
                string _bookDept = Console.ReadLine();
                Console.Write(StringLiterals.Remarks);
                string _bookRemarks = Console.ReadLine();
                Console.Write(StringLiterals.NumberofBooks);
                int _bookCount = Int32.Parse(Console.ReadLine());
                for (int _loopAdd = 0; _loopAdd < _bookCount; _loopAdd++)
                {
                    BookChoice.AddBook(new BookModel {
                        Name       = _bookName,
                        AuthorName = _bookAuthor,
                        Department = _bookDept,
                        Remarks    = _bookRemarks,
                        IsActive   = true
                    });
                }
                break;

            case 2:
                Console.Clear();
                BookHistoryModel issueInfo = new BookHistoryModel();
                Console.WriteLine(StringLiterals.IssuingDetails);
                Console.Write(StringLiterals.BookID);
                issueInfo.BookID = Int32.Parse(Console.ReadLine());
                Console.Write(StringLiterals.UserID);
                issueInfo.UserID = Int32.Parse(Console.ReadLine());
                Console.Write(StringLiterals.IssueTime);
                issueInfo.OperationPerformedAt = DateTime.Now;
                Console.WriteLine(issueInfo.OperationPerformedAt);
                Console.Write(StringLiterals.Validity);
                issueInfo.ReturnedAt = DateTime.Now.AddDays(30);
                Console.WriteLine(issueInfo.ReturnedAt);
                Console.Write(StringLiterals.Remarks);
                issueInfo.Remarks = Console.ReadLine();
                Console.Write(StringLiterals.AuthorityID);
                issueInfo.PerformedByID = Int32.Parse(Console.ReadLine());
                string _issuemsg = BookChoice.IssueBook(issueInfo);
                Console.WriteLine(_issuemsg);
                break;

            case 3:
                Console.Clear();
                Console.WriteLine(StringLiterals.EnterBookDetails);
                Console.Write(StringLiterals.BookID);
                int    _returnID = Int32.Parse(Console.ReadLine());
                string _retMsg   = BookChoice.ReturnBook(_returnID);
                Console.WriteLine(_retMsg);
                break;

            case 4:
                Console.Clear();
                Console.WriteLine(StringLiterals.BookID);
                int    _removeID  = Int32.Parse(Console.ReadLine());
                string _removemsg = BookChoice.RemoveBook(_removeID);
                Console.WriteLine(_removemsg);
                break;

            case 5:
                Console.Clear();
                int _getList = 0;
                Console.WriteLine(StringLiterals.BookListChoice);
                int _listChoice = Int32.Parse(Console.ReadLine());
                Console.Clear();
                if (_listChoice == 1)
                {
                    _getList = 1;
                }
                else if (_listChoice == 2)
                {
                    _getList = 2;
                }
                else if (_listChoice == 3)
                {
                    _getList = 3;
                }
                else
                {
                    Console.WriteLine(StringLiterals.InvalidEntry);
                }
                DataTable BookList = BookChoice.GetAllBooks(_getList);
                foreach (DataRow item in BookList.Rows)
                {
                    Console.WriteLine(StringLiterals.BookListOut, item[0], item[1], item[3], item[2]);
                }
                Console.Write(StringLiterals.PressContinue);
                Console.ReadKey();
                Console.Clear();
                break;

            case 6:
                historylabel :       Console.Clear();
                Console.WriteLine(StringLiterals.BookHistoryChoice);
                _listChoice = Int32.Parse(Console.ReadLine());
                DataTable histList = BookChoice.HistoryOfBook(_listChoice);
                if (_listChoice == 1)
                {
                    foreach (DataRow item in histList.Rows)
                    {
                        Console.WriteLine(StringLiterals.IssueOut, item[0], item[1], item[2], item[7]);
                    }
                }

                else if (_listChoice == 2)
                {
                    foreach (DataRow item in histList.Rows)
                    {
                        Console.WriteLine(StringLiterals.ReturnOut, item[0], item[1], item[3], item[7]);
                    }
                }
                else if (_listChoice == 3)
                {
                    foreach (DataRow item in histList.Rows)
                    {
                        Console.WriteLine(StringLiterals.AllLog, item[0], item[1], item[2], item[3], item[7]);
                    }
                }
                else
                {
                    Console.Write(StringLiterals.InvalidEntry); goto historylabel;
                }
                Console.ReadKey();
                Console.Clear();
                break;

            case 7:
                Console.Clear();
                Console.WriteLine(StringLiterals.BookName);
                string    _searcharg = Console.ReadLine();
                DataTable _srchList  = BookChoice.SearchBook(_searcharg);
                foreach (DataRow item in _srchList.Rows)
                {
                    Console.WriteLine(StringLiterals.SearchResult, item[0], item[1], item[3], item[2]);
                }
                Console.WriteLine(StringLiterals.PressContinue);
                Console.ReadKey();
                Console.Clear();
                break;

            case 8:
                Console.Clear();
                IAuthentication _userEntry = BALFactory.GetAuthenticationObject();
                UserModel       _newuser   = new UserModel();
                Console.WriteLine(StringLiterals.UserEntry);
                Console.Write(StringLiterals.UserName);
                _newuser.Name = Console.ReadLine();
                Console.Write(StringLiterals.UserEmail);
                _newuser.Email = Console.ReadLine();
                Console.WriteLine(_userEntry.Register(_newuser));
                break;

            case 9:
                Console.WriteLine(StringLiterals.SignOut);
                return(1);
            }
            return(0);
        }