@RequestMapping(value = "/staffcreatenewusersubmit", method = RequestMethod.POST)
  public ModelAndView createUserSubmit(
      @ModelAttribute("form") UserForm userForm, BindingResult result) {

    log.debug("Entering....");
    ModelAndView modelAndView = new ModelAndView("staffcreatenewuser");

    boolean isSuccess = true;
    validateUserForm(userForm, result);
    if (userForm.getDateOfBirth() != null) {
      if (!AppUtil.isAValidDDMMYYYYDate(userForm.getDateOfBirth())) {
        log.error("Invalid date format " + userForm.getDateOfBirth());
        isSuccess = false;
        result.addError(
            new ObjectError(
                "dateOfBirth", "Invalid dateOfBirth. Please use the format " + DATE_FORMAT));
      }
    }
    if (isSuccess && !result.hasErrors()) {

      String tenantId = userForm.getTenantId();
      Profile staffProfile = profileService.getProfileById(userForm.getStaffProfileId(), tenantId);
      if (staffProfile != null) {
        userForm.setStaffFirstName(staffProfile.getFirstName());
        userForm.setStaffLastName(staffProfile.getLastName());
      }

      // Create Profile
      String profileId = profileService.saveProfile(createProfile(userForm));
      try {
        // Create Use Account
        loginService.CreateUser(createUser(userForm, profileId));

      } catch (Exception e) {
        log.error("Error Creating User {} ", e);
        isSuccess = false;
        profileService.deleteProfile(profileId, tenantId);
      }

      if (isSuccess) {
        modelAndView.addObject(
            "successMessage", "User '" + userForm.getUserName() + "' successfully created !!!");
        resetForm(userForm);
      } else {
        result.addError(new ObjectError("userAccount", "Error creating new user"));
      }
    }
    modelAndView.addObject("roleType", loadRoleMap());
    modelAndView.addObject("form", userForm);
    log.debug("Existing..........");
    return modelAndView;
  }
 private Profile createProfile(UserForm form) {
   Profile profile = new Profile();
   profile.setFirstName(form.getFirstName());
   profile.setLastName(form.getLastName());
   profile.setDateOfBirth(AppUtil.getDateFromStr(form.getDateOfBirth()));
   profile.setAddress(form.getAddress());
   profile.setEmailAddress(form.getEmailAddress());
   profile.setPhone(form.getPhoneNo());
   profile.setTenantId(form.getUserTenandId());
   profile.setSex(form.getSex());
   profile.setCreatedBy(form.getStaffFirstName() + " " + form.getStaffLastName());
   profile.setCreatedDate(new Date());
   return profile;
 }