public ActionResult Edit(int?id) { if (id == null) { return(new HttpStatusCodeResult(HttpStatusCode.BadRequest)); } CapNhatDoanKhachViewModel doanKhach = new CapNhatDoanKhachViewModel(); doanKhach = bus.getThongTinChiPhi(id); return(View(doanKhach)); }
public ActionResult Edit([Bind(Include = "maDoan,DSKhachSan,DSTienKS,DSAn,DSTienAn,DSPhuongTien,DSTienPT,DSKhac,DSTienKhac")] CapNhatDoanKhachViewModel doankhach) { if (ModelState.IsValid) { String error = bus.CapNhatTien(doankhach); if (error != null) { ViewBag.error = error; return(View()); } return(RedirectToAction("TienDoan")); } return(View(doankhach)); }
public CapNhatDoanKhachViewModel getThongTinChiPhi(int?id) { try { CapNhatDoanKhachViewModel result = new CapNhatDoanKhachViewModel(); result.maDoan = id.Value; foreach (KhachSanTheoDoan item in db.KhachSanTheoDoans.Where(c => c.DoanKhachId == id)) { result.DSKhachSan += item.TenKs + ", "; result.DSTienKS += item.GiaTien + ", "; } foreach (TienAnTheoDoan item in db.TienAnTheoDoans.Where(c => c.DoanKhachId == id)) { result.DSAn += item.TenGoi + ", "; result.DSTienAn += item.GiaTien + ", "; } foreach (PhuongTienTheoDoan item in db.PhuongTienTheoDoans.Where(c => c.DoanKhachId == id)) { result.DSPhuongTien += item.TenPT + ", "; result.DSTienPT += item.GiaTien + ", "; } foreach (ChiPhiKhacTheoDoan item in db.ChiPhiKhacTheoDoans.Where(c => c.DoanKhachId == id)) { result.DSKhac += item.TenGoi + ", "; result.DSTienKhac += item.GiaTien + ", "; } result.DSAn = result.DSAn.Remove(result.DSAn.Length - 2); result.DSTienAn = result.DSTienAn.Remove(result.DSTienAn.Length - 2); result.DSKhac = result.DSKhac.Remove(result.DSKhac.Length - 2); result.DSKhachSan = result.DSKhachSan.Remove(result.DSKhachSan.Length - 2); result.DSPhuongTien = result.DSPhuongTien.Remove(result.DSPhuongTien.Length - 2); result.DSTienKhac = result.DSTienKhac.Remove(result.DSTienKhac.Length - 2); result.DSTienKS = result.DSTienKS.Remove(result.DSTienKS.Length - 2); result.DSTienPT = result.DSTienPT.Remove(result.DSTienPT.Length - 2); return(result); } catch (Exception e) { CapNhatDoanKhachViewModel result = new CapNhatDoanKhachViewModel(); result.maDoan = id.Value; return(result); } }
public String CapNhatTien(CapNhatDoanKhachViewModel capnhat) { try { string[] stringSeparators = new string[] { ", " }; List <String> listks = capnhat.DSKhachSan.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listpt = capnhat.DSPhuongTien.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listkhac = capnhat.DSKhac.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listan = capnhat.DSAn.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listtienks = capnhat.DSTienKS.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listtienan = capnhat.DSTienAn.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listtienpt = capnhat.DSTienPT.Split(stringSeparators, StringSplitOptions.None).ToList(); List <String> listtienkhac = capnhat.DSTienKhac.Split(stringSeparators, StringSplitOptions.None).ToList(); for (int i = 0; i < listks.Count; i++) { String tenks = listks[i]; KhachSanTheoDoan ks = db.KhachSanTheoDoans.Where(c => c.DoanKhachId == capnhat.maDoan && c.TenKs == tenks).FirstOrDefault(); if (ks == null) { ks = new KhachSanTheoDoan(); ks.DoanKhachId = capnhat.maDoan; ks.GiaTien = Int32.Parse(listtienks[i]); ks.TenKs = listks[i]; db.KhachSanTheoDoans.Add(ks); db.SaveChanges(); } else { ks.TenKs = listks[i]; ks.GiaTien = Int32.Parse(listtienks[i]); db.Entry(ks).State = EntityState.Modified; db.SaveChanges(); } } for (int i = 0; i < listan.Count; i++) { String tenpt = listan[i]; TienAnTheoDoan ks = db.TienAnTheoDoans.Where(c => c.DoanKhachId == capnhat.maDoan && c.TenGoi == tenpt).FirstOrDefault(); if (ks == null) { ks = new TienAnTheoDoan(); ks.DoanKhachId = capnhat.maDoan; ks.GiaTien = Int32.Parse(listtienan[i]); ks.TenGoi = listan[i]; db.TienAnTheoDoans.Add(ks); db.SaveChanges(); } else { ks.GiaTien = Int32.Parse(listtienan[i]); ks.TenGoi = listan[i]; db.Entry(ks).State = EntityState.Modified; db.SaveChanges(); } } for (int i = 0; i < listpt.Count; i++) { String tenpt = listpt[i]; PhuongTienTheoDoan ks = db.PhuongTienTheoDoans.Where(c => c.DoanKhachId == capnhat.maDoan && c.TenPT == tenpt).FirstOrDefault(); if (ks == null) { ks = new PhuongTienTheoDoan(); ks.DoanKhachId = capnhat.maDoan; ks.GiaTien = Int32.Parse(listtienpt[i]); ks.TenPT = listpt[i]; db.PhuongTienTheoDoans.Add(ks); db.SaveChanges(); } else { ks.GiaTien = Int32.Parse(listtienpt[i]); ks.TenPT = listpt[i]; db.Entry(ks).State = EntityState.Modified; db.SaveChanges(); } } for (int i = 0; i < listkhac.Count; i++) { String ten = listkhac[i]; ChiPhiKhacTheoDoan ks = db.ChiPhiKhacTheoDoans.Where(c => c.DoanKhachId == capnhat.maDoan && c.TenGoi == ten).FirstOrDefault(); if (ks == null) { ks = new ChiPhiKhacTheoDoan(); ks.DoanKhachId = capnhat.maDoan; ks.GiaTien = Int32.Parse(listtienkhac[i]); ks.TenGoi = listkhac[i]; db.ChiPhiKhacTheoDoans.Add(ks); db.SaveChanges(); } else { ks.GiaTien = Int32.Parse(listtienkhac[i]); ks.TenGoi = listkhac[i]; db.Entry(ks).State = EntityState.Modified; db.SaveChanges(); } } if (TinhTongTien(capnhat.maDoan)) { return(null); } else { return("Nhập Sai Số"); } } catch (Exception e) { return("Có Lỗi xảy ra:" + e); } }