package bg.car_wash.areas.customer.controller;

import bg.car_wash.areas.customer.models.bindingModel.CustomerBindingModel;
import bg.car_wash.areas.customer.service.CustomerService;
import bg.car_wash.configurations.site.PageTitle;
import org.modelmapper.ModelMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.Model;
import org.springframework.validation.BindingResult;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.ModelAttribute;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.validation.Valid;

@Controller
@RequestMapping("/customer")
public class CustomerController {

	@Autowired
	private CustomerService customerService;

	@Autowired
	private ModelMapper modelMapper;

	@GetMapping("/add")
	public String addCarForWorkPage(
			Model model,
			@Valid @ModelAttribute CustomerBindingModel customerBindingModel,
			BindingResult bindingResult) {
		model.addAttribute("pageTitle", PageTitle.CUSTOMER_ADD_PAGE);

		return "customer/customer-add";
	}
}

@@ -79,43 +79,165 @@
 mer.
-models.bindingModel.CustomerBinding
+entity.Customer;%0Aimport bg.car_wash.areas.customer.models.bindingModel.CustomerBindingModel;%0Aimport bg.car_wash.areas.customer.models.viewModels.CustomerView
 Mode
@@ -709,16 +709,76 @@
 ribute;%0A
+import org.springframework.web.bind.annotation.PostMapping;%0A
 import o
@@ -863,16 +863,91 @@
 n.Valid;
+%0Aimport java.util.Date;%0Aimport java.util.LinkedList;%0Aimport java.util.List;
 %0A%0A@Contr
@@ -1158,21 +1158,22 @@
 ing 
-addCarForWork
+getAddCustomer
 Page
@@ -1358,16 +1358,16 @@
 PAGE);%0A%0A
-
 %09%09return
@@ -1394,11 +1394,1046 @@
 add%22;%0A%09%7D
+%0A%0A%09@PostMapping(%22/add%22)%0A%09public String addCustomerPage(%0A%09%09%09Model model,%0A%09%09%09@Valid @ModelAttribute CustomerBindingModel customerBindingModel,%0A%09%09%09BindingResult bindingResult) %7B%0A%0A%09%09if(bindingResult.hasErrors()) %7B%0A%09%09%09model.addAttribute(%22pageTitle%22, PageTitle.CUSTOMER_ADD_PAGE);%0A%09%09%09return %22customer/customer-add%22;%0A%09%09%7D%0A%0A%09%09customerBindingModel.setDate(new Date());%0A%0A%09%09Customer customer = this.modelMapper.map(customerBindingModel, Customer.class);%0A%0A%09%09this.customerService.createCustomer(customer);%0A%0A%09%09return %22customer/customer-all%22;%0A%09%7D%0A%0A%09@GetMapping(%22/all%22)%0A%09public String getAllCustomerPage(Model model) %7B%0A%09%09List%3CCustomerViewModel%3E customersViewModels = new LinkedList%3C%3E();%0A%09%09List%3CCustomer%3E customers = this.customerService.findAllCustomers();%0A%09%09for (Customer customer : customers) %7B%0A%09%09%09customersViewModels.add(this.modelMapper.map(customer, CustomerViewModel.class));%0A%09%09%7D%0A%0A%09%09model.addAttribute(%22pageTitle%22, PageTitle.CUSTOMER_ALL_PAGE);%0A%09%09model.addAttribute(%22customersViewModel%22, customersViewModels);%0A%0A%09%09return %22customer/customer-all%22;%0A%09%7D
 %0A%7D%0A

create add and all mapping for customer