public async Task <IActionResult> Post([FromBody] AddCustomerTypeViewModel model) { if (model == null) { return(BadRequest()); } if (await _customerTypeRepo.IsExistNameAsync(model.Name)) { ModelState.AddModelError("Name", Resources.Global.Common.ThisNameExist); return(BadRequest(ModelState.GetWithErrorsKey())); } var customerType = new CustomerType(model.Name, model.Note); var affectedRows = await _customerTypeRepo.AddAsync(customerType); if (affectedRows > 0) { var viewModel = AutoMapper.Mapper.Map <CustomerTypeViewModel>(customerType); return(CreatedAtRoute("GetCustomerType", new { id = customerType.Number }, viewModel)); } return(BadRequest()); }
/// <summary> /// 新增 /// </summary> /// <param name="input"></param> /// <returns></returns> private async Task Create(CreateOrEditCustomerTypeCommand input) { var model = new Domain.CustomerType(input.Type, input.Name, input.Memo); await _customerTypeRepository.AddAsync(model); }