@RequestMapping(value = "/submit/{id}", method = RequestMethod.GET)
  public String submitAction(
      final RedirectAttributes redirectAttributes,
      Principal principal,
      @PathVariable Long id,
      Model model) {

    Member member = memberService.findOneByUsername(principal.getName());
    Expense expense = expenseService.findOneByMemberAndId(member, id);

    if (expense instanceof Expense == false) {
      redirectAttributes.addFlashAttribute("message", "message.record.not.access");
      return "redirect:/userexpense/list";
    }

    expense.setSubmitted(true);
    expenseService.save(expense);
    return "redirect:/userexpense/show/" + id;
  }
  @RequestMapping(value = "/delete", method = RequestMethod.DELETE)
  public String delete(
      final RedirectAttributes redirectAttributes,
      Principal principal,
      @RequestParam(value = "id", required = true) Long id) {

    Member member = memberService.findOneByUsername(principal.getName());
    Expense expense = expenseService.findOneByMemberAndId(member, id);

    if (expense instanceof Expense == false) {
      redirectAttributes.addFlashAttribute("message", "message.record.not.access");
      return "redirect:/userexpense/list";
    } else if (expense.isSubmitted()) {
      redirectAttributes.addFlashAttribute("message", "message.record.not.editable");
      return "redirect:/userexpense/show/" + expense.getId();
    } else {
      redirectAttributes.addFlashAttribute("message", "message.completed.delete");
      expenseService.delete(expense);
      return "redirect:/userexpense/list";
    }
  }
  @RequestMapping(value = "/edit/{id}", method = RequestMethod.GET)
  public String editAction(
      final RedirectAttributes redirectAttributes, @PathVariable Long id, Model model) {

    Expense expense = expenseService.findOne(id);
    if (expense.isSubmitted()) {
      redirectAttributes.addFlashAttribute("message", "message.record.not.editable");
      return "redirect:/userexpense/show/" + expense.getId();
    }

    model.addAttribute("expensetypes", expensetypeService.findAll());
    model.addAttribute("userexpenseAttribute", expense);
    return "/userexpense/form";
  }
  @RequestMapping(value = "/save", method = RequestMethod.POST)
  public String saveAction(
      final RedirectAttributes redirectAttributes,
      Principal principal,
      @ModelAttribute("userexpenseAttribute") @Valid Expense formData,
      BindingResult result,
      Model model) {

    if (result.hasErrors()) {
      model.addAttribute("expensetypes", expensetypeService.findAll());
      return "/userexpense/form";
    }

    Member member = memberService.findOneByUsername(principal.getName());
    formData.setMember(member);

    Expense expense = expenseService.save(formData);
    redirectAttributes.addFlashAttribute("message", "message.completed.save");
    return "redirect:/userexpense/show/" + expense.getId();
  }