Пример #1
0
 // 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());
     }
 }
Пример #2
0
 // <summary>新增客戶資料</summary>
 /// <returns></returns>
 public void AddCustomer(CustomerViewModel models)
 {
     Mapper.CreateMap<CustomerViewModel, Customers>();
     var cust = Mapper.Map<CustomerViewModel, Customers>(models);
     db.Insert(cust);
 }
Пример #3
0
 /// <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);
 }
Пример #4
0
        /// <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);
        }