/// <summary>
        /// Creates the or edit.
        /// </summary>
        /// <param name="id">The identifier.</param>
        /// <returns></returns>
        public ActionResult CreateOrEdit(int id = 0)
        {
            var model = new CustomerUpdateModel();
            PrepareCusomterModel(model);

            if (id == 0) return View(model);

            var customer = _customerService.GetCustomerById(id);
            model.Name = customer.Username;
            model.Id = id;
            return View(model);
        }
        public ActionResult CreateOrEdit(CustomerUpdateModel model)
        {
            PrepareCusomterModel(model);
            if (!ModelState.IsValid) return View(model);

            var customer = model.Id != 0 ? _customerService.GetCustomerById(model.Id) : new Customer();
            customer.Username = model.Name;
            customer.CreatedOn=DateTime.Now;
            customer.LastActivityDate=DateTime.Now;
            if (model.Id != 0)
            {
                _customerService.UpdateCustomer(customer);
            }
            else
            {
                _customerService.InsertCustomer(customer);
            }
            return RedirectToAction("List");
        }
 /// <summary>
 /// Prepares the cusomter model.
 /// </summary>
 /// <param name="model">The model.</param>
 private void PrepareCusomterModel(CustomerUpdateModel model)
 {
     var roles = _customerService.GetAllCustomerRoles();
     model.AvailableRoles = roles.ToSelectItems();
     model.AvailableRoles.Insert(0, new SelectListItem() {Text = "请选择", Value = "0"});
 }