public ActionResult Index()
        {
            using (var _libEntity = new LibEntities())
            {
                if (!string.IsNullOrEmpty(LibSecurity.UserId))
                {
                    LibSecurity.IsLoggedIn = true;

                    ViewBag.IsLoggedIn = LibSecurity.UserId;

                    //Viewed emails count script
                    string id = LibSecurity.UserId;
                    var getMail = _libEntity.GetMessageCount(id);
                    int ordercount = getMail.SingleOrDefault().Value;

                    Session["theCount"] = "Messages: " + ordercount;

                }
                else
                {
                    LibSecurity.IsLoggedIn = false;
                }
                return View();
            }
        }
        public ActionResult Chat()
        {
            var getChatList = _structureRepository.GetChatList();

            using (var _ncuElrc = new LibEntities())
            {
                var chatId = _ncuElrc.chat.FirstOrDefault(c => c.lib_chat == true);

                if (chatId != null)
                {
                    ViewBag.LibId = chatId.lib_id;
                }
            }
            return View(getChatList);
        }
        public ActionResult ChatStart()
        {
            LibEntities _ncuElrc = new LibEntities();
            var checkChatStart = _ncuElrc.chat.FirstOrDefault(c => c.lib_chat == true);

            if (checkChatStart == null)
            {
                var chatStart = _structureRepository.StartChat();
            }
            else
            {
                return Content("Sorry, but there's an active chat session. Please end the current session.");
            }

            _ncuElrc.Connection.Close();

            return Redirect("/structure/chat");
        }
        public ActionResult FileDownload(string id)
        {
            /*well good to know that I can't use this in the repository.
            Need to do more research about conflict with type model admin and
            and filecontentresult. Would really like to put this method in the
            admin repository but at this point I am uncertain on how to proceed.
            */

            using (var _libEntity = new LibEntities())
            {
                int keyId = int.Parse(id);

                var file = _libEntity.file_uploads.First(f => f.q_id == keyId);

                var fileRes = new FileContentResult(file.attachment_file.ToArray(), "application/octet-stream");

                fileRes.FileDownloadName = file.attachment_file_name;

                return fileRes;
            }
        }
        public ActionResult GetAnswer(string id)
        {
            using (var _libEntity = new LibEntities())
            {
                /*
                tried to move this to the repository but there are issues with lambdas
                and interfaces. Just not sure if there is a way to bring these types of statements
                into a repository where things are strongly typed to models. 9/28/2015
                */

                ViewBag.LibEmail = "library.ncu.edu?subject=" + id;

                var keyId = int.Parse(id);

                var fileName = _libEntity.file_uploads.FirstOrDefault(f => f.q_id == keyId);

                if (fileName != null)
                {
                    ViewBag.thisFile = fileName.attachment_file_name;
                    ViewBag.thisId = keyId;
                }

                var viewedMessages = _libEntity.quest_lib.Where(x => x.q_id == keyId).FirstOrDefault();

                if (viewedMessages.viewed_mess == false)
                {
                    viewedMessages.viewed_mess = true;
                    _libEntity.SaveChanges();
                }

                var getLibAnswer = _askRepository.GetLibAnswer(keyId);

                return View(getLibAnswer);

            }
        }
        public ActionResult ReturnResMonth(string entryId)
        {
            //check this out in debug mode to see if i can issue with resource of the month
            using (var _libEntity = new LibEntities())
            {
                int reEntryId = Convert.ToInt32(entryId);

                var userCheck = _libEntity.resources_tb_fdbk.FirstOrDefault(x => x.entry_id == reEntryId && x.user_id == LibSecurity.UserId);

                var getUsers = _libEntity.resources_tb_fdbk.Where(x => x.entry_id == reEntryId).Count();

                //we can that if userCheck is not null then we can do a count. Otherwise, there is no count. 
                if (userCheck != null)
                {
                    ViewBag.Message = "Thank you for reviewing this resource.";
                    ViewBag.theCount = getUsers;
                    ViewBag.Id = true;

                }
                else
                {
                    ViewBag.theCount = getUsers;

                }
                var getResMonth = _homeRepository.SumResourceMonth(entryId);

                ViewBag.GetSum = getResMonth.ToList().Select(c => c.Ratings).Sum();

                return View(getResMonth);
            }
            
            //write private method to acquire total number of respondents. 
        }
        public ActionResult GetRadioId(home _objModel, int id)
        {
            using (var _libEntity = new LibEntities())
            {
                var userCheck = _libEntity.resources_tb_fdbk.FirstOrDefault(x => x.entry_id == id && x.user_id == LibSecurity.UserId);


                if (_objModel.SelectRadioItem != null || _objModel.Comments != null)
                {
                    var addRadioId = _homeRepository.AddRadioId(_objModel, id);

                    string entryId = id.ToString();

                    return RedirectToAction("ReturnResMonth", new { entryId = id.ToString() });
                }
                else
                {
                    return Content("These are the variables " + id + " , " + _objModel.SelectRadioItem + _objModel.Comments);

                }
            }
        }
        public ViewResult SendEmail(mail _objModelMail)
        {
            //this will fire off an email to the library folder.
            //would really like to move this the repository but the lambdas and interface also exists with this bit of code. 10/12.

            using (var _libEntity = new LibEntities())
            {
                int? id = _objModelMail.QuestId;

                quest_tb qt = _libEntity.quest_tb.FirstOrDefault(x => x.q_id == id);

                MailMessage mail = new MailMessage();

                SmtpClient smtpServer = new SmtpClient("smtp.ncu.edu");

                mail.From = new MailAddress(qt.email_address, qt.u_last_name + ", " + qt.u_first_name);
                mail.To.Add("*****@*****.**");
                mail.Subject = "Feedback - Knowledge Base";
                mail.Body = "Feedback: " + _objModelMail.Comments + "\r QuestionID: " + id;

                smtpServer.Send(mail);

                return View(_objModelMail);
            }
        }