public ActionResult RegisteredStudent(Regestration studentRegestration)
        {
            if (ModelState.IsValid)
            {
                CardDAO Card_DAO = new CardDAO();
                if (Card_DAO.ISExsistCardDate(studentRegestration.CardNumber))
                {
                    RegestrationDAO Registrator = new RegestrationDAO();
                    if (Registrator.IsCardUnsoldAndUnRegisteredWhileRegitered(studentRegestration.CardNumber))
                    {
                        Registrator.RegisterStudent(studentRegestration);
                        return View(studentRegestration);

                    }
                    else
                    {
                        ModelState.AddModelError("", "The Card is already sold or the card number is invalid.");
                        return View("RegisterStudent");
                    }

                }
                else
                {
                    ModelState.AddModelError("", "There is no card with this card number.Please give a valid card number");
                    return View("RegisterStudent");
                }

            }
            else
            {
                ModelState.AddModelError("", "It seems it's lacking required information");
                return View("RegisterStudent");
            }
        }
        public ActionResult ViewCards(CardInput cardInput)
        {
            if (ModelState.IsValid)
            {
                CardGenerator cardGenerator = new CardGenerator(cardInput.GeneratingDate, cardInput.NumberOfCards);
                List<Card> CardList = cardGenerator.GetCardsList();
                CardDAO cardDAO = new CardDAO();
                if (!cardDAO.ISExsistCardDate(CardList[0].CardNumber))
                {
                    GridView gridView = new GridView();
                    gridView.DataSource = CardList;
                    gridView.DataBind();
                    Session["CardsListEXCEL"] = gridView;
                    Session["CardsList"] = CardList;

                    return View(CardList);
                }
                else
                {
                    ModelState.AddModelError("", "You have already generated cards on this date, so choose aonther date. ");
                    return View("ShowCards");

                }

            }
            else
            {
                ModelState.AddModelError("", "Card List is not available");
                return View("ShowCards");
            }
        }
        public ActionResult RefreshParticularCard(SearchStudent active_CardNumber)
        {
            if (ModelState.IsValid)
            {
                CardDAO Card_DAO = new CardDAO();
                if (Card_DAO.ISExsistCardDate(active_CardNumber.CardNumber))
                {
                    RegestrationDAO Registrator = new RegestrationDAO();
                    if (Registrator.IsValidCardInDataBase(active_CardNumber.CardNumber))
                    {
                        ActiveUserDAO ActiveUser_DAO = new ActiveUserDAO();
                        if (ActiveUser_DAO.IsActive(active_CardNumber.CardNumber))
                        {

                            ActiveUser_DAO.RefreshActiveUserListForParticularCard(active_CardNumber.CardNumber);
                            return View();

                        }
                        else
                        {
                            ModelState.AddModelError("", "The Card is not active yet .So there is no reason for removing it from the active user list");
                            return View("ShowParticularCard");
                        }

                    }
                    else
                    {
                        ModelState.AddModelError("", "The Card Number is not sold yet,so there is no student registerd with this card number");
                        return View("ShowParticularCard");

                    }
                }
                else
                {

                    ModelState.AddModelError("", "There is no card with this card number.Please give a valid card number");
                    return View("ShowParticularCard");
                }

            }
            else
            {
                ModelState.AddModelError("", "Active user not found");
                return View("ShowParticularCard");

            }
        }
        public ActionResult AddCard(SearchStudent studentCardNumber)
        {
            if (ModelState.IsValid)
            {
                if (Session["StudentId"] != null)
                {

                    CardDAO Card_DAO = new CardDAO();
                    if (Card_DAO.ISExsistCardDate(studentCardNumber.CardNumber))
                    {
                        RegestrationDAO Registrator = new RegestrationDAO();
                        if (Registrator.IsCardUnsoldAndUnRegisteredWhileRegitered(studentCardNumber.CardNumber))
                        {
                            int StudentId = (Int32)Session["StudentId"];
                            Registrator.UpdateCardsTableWithStudentId(studentCardNumber.CardNumber, StudentId);
                            ModelState.AddModelError("", "The New Card is added successfully .Please check student information by searching.");
                            return View("SearchStudent");
                        }
                        else
                        {
                            ModelState.AddModelError("", "The Card is already sold,Please give an unsold card number.");
                            return View("SearchStudent");
                        }
                    }
                    else
                    {
                        ModelState.AddModelError("", "There is no card with this card number.Please give a valid card number.");
                        return View("SearchStudent");

                    }

                }
                else
                {
                    ModelState.AddModelError("", "Sorry Student information is not found.");
                    return View("SearchStudent");
                }

            }
            else
            {

                ModelState.AddModelError("", "Sorry Student information is not found.");
                return View("SearchStudent");
            }
        }
        public ActionResult ViewCardUsage(SearchStudent searchStudent)
        {
            if (ModelState.IsValid)
            {
                CardDAO Card_DAO = new CardDAO();
                if (Card_DAO.ISExsistCardDate(searchStudent.CardNumber))
                {
                    RegestrationDAO Registrator = new RegestrationDAO();

                    if (Registrator.IsValidCardInDataBase(searchStudent.CardNumber))
                    {
                        ParticularCardUsageDAO CardUsage_DAO = new ParticularCardUsageDAO();
                        List<History> CardUsageList = CardUsage_DAO.ShowParticularCardHisroty(searchStudent.CardNumber).ToList();

                        GridView gridView = new GridView();
                        gridView.DataSource = CardUsageList;
                        gridView.DataBind();
                        Session["CardUsage"] = gridView;
                        return View(CardUsageList);
                    }
                    else
                    {

                        ModelState.AddModelError("", "The Card with this card number is not sold yet.So there is no student registerd with this card number.");
                        return View("ShowCardUsage");
                    }
                }
                else
                {
                    ModelState.AddModelError("", "There is no card with this card number.Please give a valid card number.");
                    return View("ShowCardUsage");

                }
            }
            else
            {
                ModelState.AddModelError("", "The Card Number is invalid.");
                return View("ShowCardUsage");
            }
        }
        public ActionResult Download()
        {
            if (Session["CardsListEXCEL"] != null && Session["CardsList"] != null)
            {
                List<Card> cardList = (List<Card>)Session["CardsList"];
                CardDAO cardDAO = new CardDAO();
                try
                {
                    cardDAO.SaveCardsListIntoDataBase(cardList);
                    return new DownloadFileActionResult((GridView)Session["CardsListEXCEL"], "CardsListEXCEL.xls");

                }catch(Exception)
                {
                    ModelState.AddModelError("", "The Card list is already saved into the database.So,please generate new Cards");
                    return View("ShowCards");
                }

            }
            else
            {
                return View();
            }
        }
        public ActionResult ViewStudent(SearchStudent searchStudent)
        {
            if (ModelState.IsValid)
            {
                CardDAO Card_DAO = new CardDAO();
                if (Card_DAO.ISExsistCardDate(searchStudent.CardNumber))
                {
                    RegestrationDAO Registrator = new RegestrationDAO();
                    if (Registrator.IsValidCardInDataBase(searchStudent.CardNumber))
                    {
                        StudentDAO Student_DAO = new StudentDAO();
                        return View(Student_DAO.GetStudenInfo(searchStudent.CardNumber));
                    }
                    else
                    {
                        ModelState.AddModelError("", "The Card Number is not sold yet,so there is no student registerd with this card number");
                        return View("SearchStudent");
                    }

                }
                else
                {
                    ModelState.AddModelError("", "There is no card with this card number.Please give a valid card number");
                    return View("SearchStudent");

                }
            }
            else
            {
                ModelState.AddModelError("", "The Card Number is invalid");
                return View("SearchStudent");
            }
        }