public ActionResult Update(Customer customer) { try { var aCustomer = _customer.GetCustomerById(customer.Code); if (aCustomer != null) { aCustomer.Name = customer.Name; aCustomer.Code = customer.Code; aCustomer.Address = customer.Address; aCustomer.Email = customer.Email; aCustomer.Contact = customer.Contact; aCustomer.LoyalityPoint = customer.LoyalityPoint; var isUpdate = _customer.Update(aCustomer); if (isUpdate) { ViewBag.SUpdate = "Update Success."; } else { ViewBag.FUpdate = "Update Failed."; } } else { ViewBag.FMsg = "Customer not found."; } } catch (Exception exception) { ViewBag.FMsg = exception.Message; } return(View()); }
// PUT api/customerapi/5 public CCustomer Put(int id, CCustomer value) { var user = (CSign)HttpContext.Current.Session[ConfigurationManager.AppSettings["AuthSaveKey"]]; if (user == null) { throw new HttpResponseException(new SiginFailureMessage()); } using (var dal = DalBuilder.CreateDal(ConfigurationManager.ConnectionStrings["DefaultConnection"].ConnectionString, 0)) { bool ok; try { dal.Open(); ok = CustomerBll.Update(dal, value, string.Format("{0}-{1}", user.UserCode, user.UserName)); } catch (Exception ex) { LogBll.Write(dal, new CLog { LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName), LogContent = string.Format("{0}#{1}", "Customer.Put", ex.Message), LogType = LogType.系统异常 }); throw new HttpResponseException(new SystemExceptionMessage()); } if (!ok) { LogBll.Write(dal, new CLog { LogContent = string.Format("修改客户{0}-{1}", value.CustomerCode, value.CustomerName), LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName) }); throw new HttpResponseException(new DataNotFoundMessage()); } LogBll.Write(dal, new CLog { LogContent = string.Format("修改客户{0}-{1}", value.CustomerCode, value.CustomerName), LogType = LogType.操作成功, LogUser = string.Format("{0}-{1}", user.UserCode, user.UserName) }); dal.Close(); return(value); } }
private void updateButton_Click_1(object sender, EventArgs e) { //Set Id as Mandatory if (String.IsNullOrEmpty(idTextBox.Text)) { MessageBox.Show("Id Can not be Empty!!!"); return; } if (String.IsNullOrEmpty(nameTextBox.Text)) { MessageBox.Show("Id Can not be Empty!!!"); return; } if (String.IsNullOrEmpty(addressTextBox.Text)) { MessageBox.Show("Id Can not be Empty!!!"); return; } if (String.IsNullOrEmpty(contactTextBox.Text)) { MessageBox.Show("Contact Can not be Empty!!!"); return; } //Check UNIQUE if (_customerBll.IsContactExists(contactTextBox.Text)) { MessageBox.Show("Conact " + contactTextBox.Text + " is Already Exists!"); return; } if (_customerBll.Update(Convert.ToInt32(idTextBox.Text), nameTextBox.Text, addressTextBox.Text, Convert.ToInt32(contactTextBox.Text))) { MessageBox.Show("Updated"); showDataGridView.DataSource = _customerBll.Display(); } else { MessageBox.Show("Not Updated"); } }