public void setMessagesRead(String username, string vacancyNumber)
 {
     InboxDAO inboxDao = new InboxDAO();
     InboxDTO inboxDto = inboxDao.find(username, vacancyNumber);
     inboxDto.unread = "read";
     inboxDao.merge(inboxDto);
 }
        protected void vacRepeater_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            String element = e.CommandName.ToString();
             string userName = (string)Session["username"];

             ApplicationDAO app_ctx = new ApplicationDAO();
             ApplicationDTO obj = new ApplicationDTO();

             if(!app_ctx.isFound(userName,element) )
             {
                 obj.userName = userName;
                 obj.vacancyNumber = element;
                 obj.status = ApplicationStatus.APPLIED.ToString();
                 obj.appDate = DateTime.Now;
                 app_ctx.presist(obj);

                 InboxDTO inbox = new InboxDTO();
                 inbox.date = DateTime.Now;
                 inbox.message = "You have successfully applied for vacancy " + element;
                 inbox.status = ApplicationStatus.APPLIED.ToString();
                 inbox.unread = "unread";
                 inbox.userName = userName;
                 inbox.vacancyNumber = element;

                 InboxDAO dao = new InboxDAO();
                 dao.presist(inbox);

                 Response.Redirect("~/Inbox/InboxMessage.aspx");
             }
        }
 public void setMessagesRead(String username, int messageId)
 {
     InboxDAO inboxDao = new InboxDAO();
     InboxDTO inboxDto = inboxDao.find(username, messageId);
     inboxDto.unread = "read";
     inboxDao.merge(inboxDto);
 }
        public void inboxMessagesTest()
        {
            InboxService inboxService = new InboxServiceImpl();

            /*Context*/
            InboxDAO inbox_context = new InboxDAO();
            AccountDAO account_context = new AccountDAO();

            /*Insert*/
            AccountDTO account = new AccountDTO();
            account.userName = "******";
            account.status = "active";
            account.password = "******";
            account.accountType = "admin";

            account_context.presist(account);

            InboxDTO inbox = new InboxDTO();
            inbox.date = new DateTime(2012, 9, 30);
            inbox.message = "success";
            inbox.messageId = 1;
            inbox.unread = "unread";
            inbox.userName = "******";

            inbox_context.presist(inbox);

            bool expected = true;
            bool actual;
            actual = inbox_context.isFound("griddy", 1);
            Assert.AreEqual(expected, actual);

            //Test getInboxMessagesByDate method
            Assert.AreEqual(true, inboxService.hasUnreadMessage("griddy"));

            //Test getInboxMessagesByMessage method
            int inboxMessageNumber = inboxService.getNumberOfInboxMessages("griddy");
            Assert.AreEqual(1, inboxMessageNumber);

            //Test setMessagesRead method
            inboxService.setMessagesRead("griddy", 1);
            InboxMessageSearchService inboxSearchService = new InboxMessageSearchServiceImpl();
            List<InboxDTO> inboxDtoList = inboxSearchService.getInboxMessagesByUsername("griddy");

            Assert.AreEqual("read", inboxDtoList[0].unread);
            inboxDtoList.RemoveRange(0, inboxDtoList.Count);
            inboxDtoList = null;
            inbox = null;

            /*Delete*/
            inbox_context = new InboxDAO();
            inbox_context.removeByUserId("griddy", 1);
            bool expectedDelete = false;
            bool actualDelete = inbox_context.isFound("griddy", 1);
            Assert.AreEqual(expectedDelete, actualDelete);

            account_context.removeByUserId("griddy");
        }
        public List<InboxDTO> getUserInboxMessagesByDate(String username, DateTime date)
        {
            List<InboxDTO> inboxDtoList = new List<InboxDTO>();
            InboxDAO inboxDao = new InboxDAO();
            List<InboxDTO> inboxList = getInboxMessagesByUsername(username);

            foreach (InboxDTO inboxDto in inboxList)
            {
                if (inboxDto.date.Equals(date))
                {
                    inboxDtoList.Add(inboxDto);
                }
            }
            return inboxDtoList;
        }
        public List<InboxDTO> getInboxMessagesByUsername(String username)
        {
            List<InboxDTO> inboxDtoList = new List<InboxDTO>();
            InboxDAO inboxDao = new InboxDAO();
            List<InboxDTO> inboxList = inboxDao.findAll();

            foreach (InboxDTO inboxDto in inboxList)
            {
                if (inboxDto.userName.Equals(username))
                {
                    inboxDtoList.Add(inboxDto);
                }
            }
            return inboxDtoList;
        }
        public List<InboxDTO> getInboxMessagesByDate(DateTime date)
        {
            List<InboxDTO> inboxDtoList = new List<InboxDTO>();
            InboxDAO inboxDao = new InboxDAO();
            List<InboxDTO> inboxList = inboxDao.findAll();

            foreach (InboxDTO inboxDto in inboxList)
            {
                if (inboxDto.date.Equals(date))
                {
                    inboxDtoList.Add(inboxDto);
                }
            }
            return inboxDtoList;
        }
        public void InboxDAOConstructorTest()
        {
            /*Context*/
            InboxDAO inbox_context = new InboxDAO();
            AccountDAO account_context = new AccountDAO();

            /*Insert*/
            AccountDTO account = new AccountDTO();
            account.userName = "******";
            account.status = "active";
            account.password = "******";
            account.accountType = "admin";

            account_context.presist(account);

            InboxDTO inbox = new InboxDTO();
            inbox.date = new DateTime(2012, 9, 30);
            inbox.message = "success";
            inbox.vacancyNumber = "1";
            inbox.unread = "read";
            inbox.userName = "******";
            inbox.status = "applied";

            inbox_context.presist(inbox);

            bool expected = true;
            bool actual;
            actual = inbox_context.isFound("john", "1");
            Assert.AreEqual(expected, actual);

            /*Update*/
            inbox.unread = "not read";
            inbox_context.merge(inbox);
            string expectedUpdate = "not read";
            InboxDTO contUpd = inbox_context.find("john", "1");
            Assert.AreEqual(expectedUpdate, contUpd.unread);

            /*Delete*/
            inbox_context.removeByUserId("john", "1");
            bool expectedDelete = false;
            bool actualDelete = inbox_context.isFound("john", "1");
            Assert.AreEqual(expectedDelete, actualDelete);

            account_context.removeByUserId("john");
        }
        public List<InboxDTO> getUserUnreadInboxMessages(String username)
        {
            List<InboxDTO> inboxDtoList = new List<InboxDTO>();
            InboxDAO inboxDao = new InboxDAO();
            List<InboxDTO> inboxList = inboxDao.findAll();

            foreach (InboxDTO inboxDto in inboxList)
            {
                if (inboxDto.unread.Equals("unread"))
                {
                    inboxDtoList.Add(inboxDto);
                }
            }
            return inboxDtoList;
        }
        public List<InboxDTO> getUserInboxMessagesByVacancy(string username, string vacancyNumber)
        {
            List<InboxDTO> inboxDtoList = new List<InboxDTO>();
            InboxDAO inboxDao = new InboxDAO();
            List<InboxDTO> inboxList = getInboxMessagesByUsername(username);

            foreach (InboxDTO inboxDto in inboxList)
            {
                if (inboxDto.vacancyNumber.Equals(vacancyNumber))
                {
                    inboxDtoList.Add(inboxDto);
                }
            }
            return inboxDtoList;
        }