package nl.avansc1.facturatie.controller;

import nl.avansc1.facturatie.model.customers.Customer;
import nl.avansc1.facturatie.repository.CustomerDAO;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import java.util.Date;

/**
 * This controls the customer crud and front-end
 *
 * @author Bob van der Valk
 */
@Controller
@RequestMapping("/customer")
public class CustomerController {

    @RequestMapping("/")
    public String overview() {
        return "howdy";
    }

    /**
     * Add new customers page
     * @return template/customer/add.html
     */
    @RequestMapping("/new")
    public String add() {
        return "customer/add";
    }

    /**
     * Process the saving stuff
     * @return
     */
    @RequestMapping(value = "/new", method = RequestMethod.POST)
    public String addHandler(int csn, String firstName, String lastName, String streetName, String houseNumber,
                             String zipcode, String city, Date dateOfBirth, int phoneNumber, String email,
                             String iban) {
        Customer customer = new Customer();
        customer.setCsn(csn);
        customer.setFirstName(firstName);
        customer.setLastName(lastName);
        customer.setStreetName(streetName);
        customer.setHouseNumber(houseNumber);
        customer.setZipcode(zipcode);
        customer.setCity(city);
        customer.setDateOfBirth(dateOfBirth);
        customer.setPhoneNumber(phoneNumber);
        customer.setEmail(email);
        customer.setIban(iban);
        customerDAO.save(customer);
        return "saved!";
    }

    @Autowired
    private CustomerDAO customerDAO;
}

@@ -570,16 +570,99 @@
 oller %7B%0A
+    /**%0A     * Overview page%0A     * @return template/customer/overview.html%0A     */
 %0A    @Re
@@ -675,17 +675,16 @@
 apping(%22
-/
 %22)%0A    p
@@ -729,13 +729,25 @@
 rn %22
-howdy
+customer/overview
 %22;%0A 
@@ -986,16 +986,55 @@
  @return
+ saved message is the customer is saved
 %0A     */
@@ -1374,52 +1374,26 @@
     
-Customer customer = new Customer();%0A
+try %7B%0A    
         
 cust
@@ -1392,109 +1392,65 @@
     
-c
+C
 ustomer
-.setCsn(csn);%0A        customer.setFirstName(firstName);%0A        customer.setLa
+ customer = new Customer(csn, fir
 stName
-(
+, 
 lastName
 );%0A 
@@ -1449,203 +1449,50 @@
 Name
-);%0A        customer.setStreetName(streetName);%0A        customer.setHouseNumber(houseNumber);%0A        customer.setZipcode(zipcode);%0A        customer.setCity(city);%0A        customer.setDateOfBirth(
+, streetName, houseNumber, zipcode, city, 
 date
@@ -1498,27 +1498,29 @@
 eOfBirth
-);%0A
+,%0A   
         
 customer
@@ -1515,147 +1515,162 @@
     
-customer.setPhoneNumber(phoneNumber);%0A        customer.setEmail(email);%0A        customer.setIban(iban);%0A        customerDAO.save(customer);
+         phoneNumber, email, iban);%0A            customerDAO.save(customer);%0A        %7D catch (Exception ex) %7B%0A            return %22saving error%22;%0A        %7D%0A
 %0A   

Load template add saving using hibernate