public JsonResult AutocompleteCompanies(string term)
        {
            CustomerService cService = new CustomerService();
            var result = cService.GetCompanyNames(term);

            return Json(result, JsonRequestBehavior.AllowGet);
        }
        public ActionResult SelectCustomers()
        {
            MailSelectCustomersViewModel viewModel = new MailSelectCustomersViewModel();
            CustomerService cService = new CustomerService();
            viewModel.Customers = cService.GetCustomers();

            return View(viewModel);
        }
        //
        // GET: /Customers/
        public ActionResult Index()
        {
            CustomerIndexViewModel viewModel = new CustomerIndexViewModel();
            CustomerService cService = new CustomerService();
            viewModel.Customers = cService.GetCustomers();

            return View(viewModel);
        }
        public ActionResult Add(CustomerAddViewModel viewModel)
        {
            if (TryUpdateModel(viewModel))
            {
                CustomerAddViewModel model = new CustomerAddViewModel();
                CustomerService cService = new CustomerService();
                cService.Add(viewModel.NewCustomer);
                model.Message = "Customer was added";
                return View(model);
            }

            return View(new CustomerAddViewModel());
        }
        public JsonResult FilterCustomers(string company)
        {
            try
            {
                CustomerService cService = new CustomerService();
                List<CustomerDataModel> customers;
                if (company == "")
                {
                    customers = cService.GetCustomers();
                }
                else
                {
                    customers = cService.GetCustomers(company);
                }

                return Json(customers, JsonRequestBehavior.AllowGet);
            }
            catch (Exception)
            {
                return Json(false, JsonRequestBehavior.DenyGet);
            }
        }
        public ActionResult WriteLetter(FormCollection collection)
        {
            // select id of every checked customer
            int[] checkedCustomersId = collection.GetValues("id_customer").Select(n => Convert.ToInt32(n)).ToArray();

            CustomerService cService = new CustomerService();

            MailWriteLetterViewModel viewModel = new MailWriteLetterViewModel();
            viewModel.CustomersToSend = cService.GetCustomers(c => checkedCustomersId.Contains(c.Id));
            TempData["CustomersToSend"] = viewModel.CustomersToSend;

            return View(viewModel);
        }