public ActionResult Update(ViewModels.客戶銀行資訊.UpdateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } using (_db = new Models.客戶資料Entities()) { var customerBankInfo = _db.客戶銀行資訊.Find(viewModel.Id); if (null == customerBankInfo) { return(HttpNotFound()); } customerBankInfo.銀行名稱 = viewModel.銀行名稱; customerBankInfo.銀行代碼 = viewModel.銀行代碼; customerBankInfo.分行代碼 = viewModel.分行代碼; customerBankInfo.帳戶名稱 = viewModel.帳戶名稱; customerBankInfo.帳戶號碼 = viewModel.帳戶名稱; _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Update(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModels.客戶資料.UpdateViewModel viewModel; using (_db = new Models.客戶資料Entities()) { var customer = _db.客戶資料.Find(id); if (null == customer) { return(HttpNotFound()); } viewModel = new ViewModels.客戶資料.UpdateViewModel { Id = customer.Id, 客戶名稱 = customer.客戶名稱, 統一編號 = customer.統一編號, 電話 = customer.電話, 傳真 = customer.傳真, 地址 = customer.地址, Email = customer.Email }; } return(View(viewModel)); }
public ActionResult Create(ViewModels.客戶銀行資訊.CreateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var customerBankInfo = new Models.客戶銀行資訊 { 客戶Id = viewModel.客戶Id, 銀行名稱 = viewModel.銀行名稱, 銀行代碼 = viewModel.銀行代碼, 分行代碼 = viewModel.分行代碼, 帳戶名稱 = viewModel.帳戶名稱, 帳戶號碼 = viewModel.帳戶號碼, }; using (_db = new Models.客戶資料Entities()) { _db.客戶銀行資訊.Add(customerBankInfo); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index(ViewModels.客戶資料.ReadViewModel viewModel) { viewModel.PageIndex = viewModel.PageIndex < 1 ? 1 : viewModel.PageIndex; using (_db = new Models.客戶資料Entities()) { var query = _db.客戶資料.AsQueryable(); if (!string.IsNullOrEmpty(viewModel.Condition.客戶名稱)) { query = query.Where(x => x.客戶名稱.Contains(viewModel.Condition.客戶名稱)); } if (!string.IsNullOrEmpty(viewModel.Condition.統一編號)) { query = query.Where(x => x.統一編號.Contains(viewModel.Condition.統一編號)); } if (!string.IsNullOrEmpty(viewModel.Condition.電話)) { query = query.Where(x => x.電話.Contains(viewModel.Condition.電話)); } query = query.Where(x => x.刪除 == false); viewModel.CustomerList = query.OrderBy(x => x.Id).ToPagedList(viewModel.PageIndex, 5); } return(View(viewModel)); }
public ActionResult Create(ViewModels.客戶資料.CreateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var customer = new Models.客戶資料 { 客戶名稱 = viewModel.客戶名稱, 統一編號 = viewModel.統一編號, 電話 = viewModel.電話, 傳真 = viewModel.傳真, 地址 = viewModel.地址, Email = viewModel.Email, }; using (_db = new Models.客戶資料Entities()) { _db.客戶資料.Add(customer); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Detail(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModels.客戶資料.DetailViewModel viewModel; using (_db = new Models.客戶資料Entities()) { var customer = _db.客戶資料.Find(id); if (null == customer) { return(HttpNotFound()); } viewModel = new ViewModels.客戶資料.DetailViewModel { Id = customer.Id, 客戶名稱 = customer.客戶名稱, 統一編號 = customer.統一編號, 電話 = customer.電話, 傳真 = customer.傳真, 地址 = customer.地址, Email = customer.Email, 客戶聯絡人清單 = _db.客戶聯絡人.Where(x => x.客戶Id == customer.Id && x.刪除 == false).ToList() }; } return(View(viewModel)); }
public ActionResult Update(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModels.客戶銀行資訊.UpdateViewModel viewModel; using (_db = new Models.客戶資料Entities()) { var customerBankInfo = _db.客戶銀行資訊.Find(id); if (null == customerBankInfo) { return(HttpNotFound()); } viewModel = new ViewModels.客戶銀行資訊.UpdateViewModel { Id = customerBankInfo.Id, 客戶Id = customerBankInfo.客戶Id, 銀行名稱 = customerBankInfo.銀行名稱, 銀行代碼 = customerBankInfo.銀行代碼, 分行代碼 = customerBankInfo.分行代碼, 帳戶名稱 = customerBankInfo.帳戶名稱, 帳戶號碼 = customerBankInfo.帳戶號碼 }; } return(View(viewModel)); }
public ActionResult Update(ViewModels.客戶資料.UpdateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } using (_db = new Models.客戶資料Entities()) { var customer = _db.客戶資料.Find(viewModel.Id); if (null == customer) { return(HttpNotFound()); } customer.客戶名稱 = viewModel.客戶名稱; customer.統一編號 = viewModel.統一編號; customer.電話 = viewModel.電話; customer.傳真 = viewModel.傳真; customer.地址 = viewModel.地址; customer.Email = viewModel.Email; _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Update(ViewModels.客戶聯絡人.UpdateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } using (_db = new Models.客戶資料Entities()) { var customerContact = _db.客戶聯絡人.Find(viewModel.Id); if (null == customerContact) { return(HttpNotFound()); } customerContact.職稱 = viewModel.職稱; customerContact.姓名 = viewModel.姓名; customerContact.Email = viewModel.Email; customerContact.手機 = viewModel.手機; customerContact.電話 = viewModel.電話; _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Update(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } ViewModels.客戶聯絡人.UpdateViewModel viewModel; using (_db = new Models.客戶資料Entities()) { var customerContact = _db.客戶聯絡人.Find(id); if (null == customerContact) { return(HttpNotFound()); } viewModel = new ViewModels.客戶聯絡人.UpdateViewModel { Id = customerContact.Id, 客戶Id = customerContact.客戶Id, 職稱 = customerContact.職稱, 姓名 = customerContact.姓名, Email = customerContact.Email, 手機 = customerContact.手機, 電話 = customerContact.電話 }; } return(View(viewModel)); }
public ActionResult Create(ViewModels.客戶聯絡人.CreateViewModel viewModel) { if (!ModelState.IsValid) { return(View(viewModel)); } var customerContact = new Models.客戶聯絡人 { 客戶Id = viewModel.客戶Id, 職稱 = viewModel.職稱, 姓名 = viewModel.姓名, Email = viewModel.Email, 手機 = viewModel.手機, 電話 = viewModel.電話 }; using (_db = new Models.客戶資料Entities()) { _db.客戶聯絡人.Add(customerContact); _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult DeleteConfirmed(int id) { using (_db = new Models.客戶資料Entities()) { var customer = _db.客戶資料.Find(id); customer.刪除 = true; _db.SaveChanges(); } return(RedirectToAction("Index")); }
public ActionResult Index() { var viewModel = new ViewModels.客戶資料.ReadViewModel(); using (_db = new Models.客戶資料Entities()) { var data = _db.客戶資料.Where(x => x.刪除 == false).ToList(); viewModel.CustomerList = data.OrderBy(x => x.Id).ToPagedList(1, 5); } return(View(viewModel)); }
public ActionResult Index() { var viewModel = new ViewModels.客戶聯絡人.ReadViewModel(); using (_db = new Models.客戶資料Entities()) { var data = _db.客戶聯絡人.Where(x => x.刪除 == false).ToList(); viewModel.CustomerContactList = data; } return(View(viewModel)); }
public IEnumerable <ValidationResult> Validate(ValidationContext validationContext) { bool emailExist; using (Models.客戶資料Entities db = new Models.客戶資料Entities()) { var customerContact = db.客戶聯絡人.Where(x => x.客戶Id == 客戶Id && x.刪除 == false).ToList(); emailExist = customerContact.Any(x => x.Email == Email); } if (emailExist) { yield return(new ValidationResult("同一個客戶Email不得重複.", new[] { "Email" })); } }
public ActionResult Login(ViewModels.Home.LoginViewModel viewModel) { if (!ModelState.IsValid) { return(View()); } using (_db = new Models.客戶資料Entities()) { var customer = _db.客戶資料.Where(x => x.帳號 == viewModel.UserName && x.密碼 == viewModel.Password).SingleOrDefault(); if (null == customer) { throw new ArgumentException("登入失敗,帳號或密碼錯誤。"); } } return(RedirectToAction("Index", "Home")); }
public ActionResult Export() { DataTable dt; using (_db = new Models.客戶資料Entities()) { var query = _db.客戶資料 .Where(x => x.刪除 == false) .OrderBy(x => x.Id); JArray jObjects = new JArray(); foreach (var item in query) { var jo = new JObject { { "Id", item.Id }, { "客戶名稱", item.客戶名稱 }, { "統一編號", item.統一編號 }, { "電話", item.電話 }, { "傳真", item.傳真 }, { "地址", item.地址 } }; jObjects.Add(jo); } dt = JsonConvert.DeserializeObject <DataTable>(jObjects.ToString()); } var exportFileName = string.Concat("客戶資料_", DateTime.Now.ToString("yyyyMMddHHmmss"), ".xlsx"); return(new ExportExcelResult { SheetName = "客戶資料", FileName = exportFileName, ExportData = dt }); }