// POST: api/Customer public HttpResponseMessage Post(CustomerViewModel models) { try { service.AddCustomer(models); return Request.CreateResponse(HttpStatusCode.OK); } catch (Exception ex) { return Request.CreateResponse(HttpStatusCode.BadRequest, ex.Message.ToString()); } }
// <summary>新增客戶資料</summary> /// <returns></returns> public void AddCustomer(CustomerViewModel models) { Mapper.CreateMap<CustomerViewModel, Customers>(); var cust = Mapper.Map<CustomerViewModel, Customers>(models); db.Insert(cust); }
/// <summary>儲存客戶資訊</summary> /// <param name="models"></param> public void SaveCustomer(CustomerViewModel models) { Mapper.CreateMap<CustomerViewModel, Customers>(); var cust = Mapper.Map<CustomerViewModel, Customers>(models); db.Update(cust); }
/// <summary> /// 儲存客戶資訊 /// </summary> /// <param name="models"></param> public void SaveCustomer(CustomerViewModel models) { var config = new MapperConfiguration(cfg => cfg.CreateMap<Customers, CustomerViewModel>()); config.AssertConfigurationIsValid();//驗證應對 var mapper = config.CreateMapper(); var cust = mapper.Map<CustomerViewModel, Customers>(models); db.Update(cust); }