public void doDelete()
 {
     if (isMinimumValid())
     {
         DisabilityDAO disabilityDao = new DisabilityDAO();
         disabilityDao.removeByUserId(view.getUsername(), view.getDisabilityType());
         view.pageReload();
     }
     else
     {
         view.showFeedback("Error Field vlaues are not valid");
     }
 }
        public void doSave()
        {
            if (isValid())
            {
                DisabilityDTO disabilityDto = getDisabilityDto();
                DisabilityDAO disabilityDao = new DisabilityDAO();
                disabilityDao.presist(disabilityDto);
            }
            else
            {

            }
        }
 public void doReset()
 {
     if (isMinimumValid())
     {
         DisabilityDAO disabilityDao = new DisabilityDAO();
         DisabilityDTO disabilityInfoDto = disabilityDao.find(view.getUsername(), view.getDisabilityType());
         setDisabilityDto(disabilityInfoDto);
         view.showFeedback("Fields are reset.");
     }
     else
     {
         view.showFeedback("Error Field vlaues are not valid");
     }
 }
        public List<DisabilityDTO> getUserDisabilities(String username)
        {
            List<DisabilityDTO> dtoList = new List<DisabilityDTO>();
            DisabilityDAO dao = new DisabilityDAO();
            List<DisabilityDTO> list = dao.findAll();

            foreach (DisabilityDTO disability in list)
            {
                if (disability.userName.Equals(username))
                {
                    dtoList.Add(disability);
                }
            }
            return dtoList;
        }
        public void Disability_Test()
        {
            /*Context*/
            DisabilityDAO disability_context = new DisabilityDAO();
            AccountDAO account_context = new AccountDAO();
            /*Insert*/
            AccountDTO account = new AccountDTO();
            account.userName = "******";
            account.status = "active";
            account.password = "******";
            account.accountType = "admin";

            account_context.presist(account);

            DisabilityDTO disability = new DisabilityDTO();
            disability.disabilityType = "hearing";
            disability.description = "loss of hearing";
            disability.userName = "******";

            disability_context.presist(disability);

            bool expected = true;
            bool actual;
            actual = disability_context.isFound("griddy", "hearing");
            Assert.AreEqual(expected, actual);

            /*Update*/
            disability.description = "no hearing";
            disability_context.merge(disability);
            string expectedUpdate = "no hearing";
            DisabilityDTO contUpd = disability_context.find("griddy", "hearing");
            Assert.AreEqual(expectedUpdate, contUpd.description);

            /*Delete*/
            disability_context.removeByUserId("griddy", "hearing");

            bool expectedDelete = false;
            bool actualDelete = disability_context.isFound("griddy", "hearing");
            Assert.AreEqual(expectedDelete, actualDelete);

            account_context.removeByUserId("griddy");
        }
 public void doSave()
 {
     AccountService accountService = new AccountServiceImpl();
     if (isValid())
     {
         if (accountService.isUniqueDisability(view.getUsername(), view.getDisabilityType()))
         {
             DisabilityDAO disabilityDao = new DisabilityDAO();
             disabilityDao.presist(getDisabilityDto());
             view.pageReload();
         }
         else
         {
             view.setDisabilityTypeError("Error, this address type is already used. Enter another value");
         }
     }
     else
     {
         view.showFeedback("Error Field vlaues are not valid");
     }
 }
 public void doUpdate()
 {
     if (isValid())
     {
         DisabilityDAO disabilityInfoDao = new DisabilityDAO();
         disabilityInfoDao.merge(getDisabilityDto());
         view.showFeedback("Successfully updated");
     }
     else
     {
         view.showFeedback("Error Field vlaues are not valid");
     }
 }
        protected void rptDisability_ItemCommand(object source, RepeaterCommandEventArgs e)
        {
            DisabilityDTO dto;
            DisabilityDAO dao = new DisabilityDAO();
            String element = e.CommandName.ToString();

            if (element.Equals("disabilityType"))
            {
                dto = dao.find(getUsername(), e.CommandArgument.ToString());
                presenter.setDisabilityDto(dto);
                presenter.updateView();
            }
        }
 public bool isUniqueDisability(String username, String language)
 {
     bool isUnique = false;
     DisabilityDAO dao = new DisabilityDAO();
     try
     {
         return (!dao.isFound(username, language));
     }
     catch (InvalidOperationException ioe)
     {
         isUnique = true;
     }
     return isUnique;
 }