public IActionResult EditLocation(LocationCommand command, Mien mien) { int SelectValue = mien.ID; ViewBag.SelectedValue = mien.ID; List <Mien> listMien = new List <Models.db.Mien>(); listMien = (from t in _db.Miens select t).ToList(); //listMien.Insert(0, new Mien { ID = 0, Tenmien = "Chọn miền" }); ViewBag.ListMien = listMien; var model = this._locationService.SeeLocation(command.ID); model.Tendiadiem = command.Tendiadiem; model.Mota = command.Mota; if (ModelState.IsValid) { this._locationService.EditLocation(command); return(RedirectToAction("AllLocation", "Admin")); } return(View(model)); }
public IActionResult AddLocation(LocationCommand command, Mien mien) { //ViewBag.Tinh = new SelectList(_db.Miens.ToList()); if (ModelState.IsValid) { this._locationService.AddLocation(command); return(RedirectToAction("AllLocation", "Admin")); } //if (command.ID == 0) //{ // ModelState.AddModelError("", "Chọn miền"); //} int SelectValue = mien.ID; ViewBag.SelectedValue = mien.ID; List <Mien> listMien = new List <Models.db.Mien>(); listMien = (from t in _db.Miens select t).ToList(); //listMien.Insert(0, new Mien { ID = 0, Tenmien = "Chọn miền" }); ViewBag.ListMien = listMien; return(View()); }
public IActionResult InsertTour(InsertTourCommand tourCommand, Diadiemdulich diadiem, Mien mien) { List <Diadiemdulich> listDiadiem = new List <Models.db.Diadiemdulich>(); listDiadiem = (from t in _db.Diadiemduliches //where t.MienID == SelectedValue2 select t).ToList(); ViewBag.ListDiaDiem = listDiadiem; List <Mien> listMien = new List <Models.db.Mien>(); listMien = (from t in _db.Miens select t).ToList(); ViewBag.ListMien = listMien; string getNameLichTrinh = null; string getNamePicture = null; if (ModelState.IsValid) { if (tourCommand != null) { getNameLichTrinh = Path.GetFileName(tourCommand.Lichtrinh.FileName); var uploadFolderLT = Path.Combine(this._hostingEnvironment.WebRootPath, "docs/lichtrinh"); var getLichtrinhToFolder = Path.Combine(uploadFolderLT, getNameLichTrinh); getNamePicture = Path.GetFileName(tourCommand.Hinhanh.FileName); var uploadFolder = Path.Combine(this._hostingEnvironment.WebRootPath, "images/tour_images"); var getPictureToFolder = Path.Combine(uploadFolder, getNamePicture); if (System.IO.File.Exists(getPictureToFolder)) { ViewBag.Picture = "Hinh anh da ton tai"; return(View()); } else { var filestream2 = new FileStream(getLichtrinhToFolder, FileMode.Create); tourCommand.Lichtrinh.CopyTo(filestream2); var filestream = new FileStream(getPictureToFolder, FileMode.Create); tourCommand.Hinhanh.CopyTo(filestream); var newTour = new Tour(); { //newTour.ID = _db.Tours.Count() + 1; newTour.Tentour = tourCommand.Tentour; newTour.Code = tourCommand.Code; newTour.Diadiemkhoihanh = tourCommand.Diadiemkhoihanh; newTour.Diemden = tourCommand.Diemden; newTour.Ngaydi = tourCommand.Ngaydi; newTour.Thuocmien = tourCommand.Thuocmien; if (tourCommand.Loaitour == "Trong nước") { newTour.Loaitour = "Trong nước"; } else { newTour.Loaitour = "Nước ngoài"; } newTour.Thoigiandi = tourCommand.Thoigiandi; newTour.Lichtrinh = getNameLichTrinh; newTour.Gianguoilon = tourCommand.Gianguoilon; newTour.Hinhanh = getNamePicture /*+ DateTime.Now.ToString()*/; newTour.Mota = tourCommand.Mota; newTour.Songuoi = tourCommand.Songuoi; //newTour.Loaitour = tourCommand.Loaitour; newTour.TenHDV = tourCommand.TenHDV; newTour.Trangthai = "Còn chỗ"; //foreach (var selectedId in tourCommand.MultiDiaDiem) //{ // _db.DiadiemTours.Add(new DiadiemTour // { // TourID = newTour.ID, // DiadiemdulichID = selectedId, // }); //} //_db.SaveChanges(); } _db.Tours.Add(newTour); _db.SaveChanges(); RedirectToAction("Index", "Admin"); } } } return(View()); }