public void DeleteTour(InsertTourCommand command) { var checkTour = _db.Tours.FirstOrDefault(n => n.Id == command.Id); _db.Remove(checkTour); _db.SaveChanges(); }
public void EditTour(InsertTourCommand command) { var checkTour = new Tour(); using (var connection = new SqlConnection(this._db.Database.GetDbConnection().ConnectionString)) { connection.Open(); if (command != null) { checkTour = connection.Query <Tour>(@"select * from Tour").FirstOrDefault(n => n.Id == command.Id); } connection.Close(); } checkTour.Code = command.Code; checkTour.Cost = command.Cost; checkTour.Day = command.Day; checkTour.Night = command.Night; checkTour.Quantity = command.Quantity; checkTour.Description = command.Description; dbSet.Attach(checkTour); _db.Entry(checkTour).State = EntityState.Modified; _db.SaveChanges(); }
public InsertTourCommand SeeTour(int id) { InsertTourCommand tourViewModel = new InsertTourCommand(); var item = _db.Tours.FirstOrDefault(n => n.ID == id); { tourViewModel.ID = item.ID; tourViewModel.Code = item.Code; tourViewModel.Tentour = item.Tentour; tourViewModel.Diadiemkhoihanh = item.Diadiemkhoihanh; tourViewModel.Diemden = item.Diemden; tourViewModel.Ngaydi = item.Ngaydi; tourViewModel.Thoigiandi = item.Thoigiandi; //tourViewModel.Ngayve = item.Ngayve; //tourViewModel.Lichtrinh = item.Lichtrinh; //tourViewModel.Hinhanh = item.Hinhanh; tourViewModel.Gianguoilon = item.Gianguoilon; //tourViewModel.Giatreem = item.Giatreem; tourViewModel.TenHDV = item.TenHDV; tourViewModel.Mota = item.Mota; tourViewModel.Trangthai = item.Trangthai; tourViewModel.Songuoi = item.Songuoi; tourViewModel.Thuocmien = item.Thuocmien; } return(tourViewModel); }
public void XoaTour(InsertTourCommand model) { var checkTour = _db.Tours.FirstOrDefault(n => n.ID == model.ID); { checkTour.Trangthai = "Xóa tour"; } _db.SaveChanges(); }
public IActionResult XoaTour(InsertTourCommand viewModel) { if (viewModel.ID == null) { return(View("/Views/Shared/Error.cshtml")); } this._tourService.XoaTour(viewModel); return(RedirectToAction("ShowAllTour", "Admin")); }
public void EditTour(InsertTourCommand command) { var checkTour = _db.Tours.FirstOrDefault(n => n.Id == command.Id); { checkTour.Code = command.Code; checkTour.Cost = command.Cost; checkTour.Day = command.Day; checkTour.Night = command.Night; checkTour.Quantity = command.Quantity; checkTour.Description = command.Description; checkTour.Discount = command.Discount; } _db.SaveChanges(); }
public IActionResult InsertTour(InsertTourCommand tourCommand) { string getNamePicture = null; if (tourCommand != null) { getNamePicture = Path.GetFileName(tourCommand.Picture.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 = "Hình ảnh đã tồn tại"; return(View()); } else { var filestream = new FileStream(getPictureToFolder, FileMode.Create); tourCommand.Picture.CopyTo(filestream); var newTour = new Tour(); { newTour.NameTour = tourCommand.NameTour; newTour.Code = tourCommand.Code; newTour.Day = tourCommand.Day; newTour.Night = tourCommand.Night; if (tourCommand.CheckNational == true) { newTour.Domestic = true; newTour.National = false; } else { newTour.Domestic = false; newTour.National = true; } newTour.Description = tourCommand.Description; newTour.Cost = tourCommand.Cost; newTour.Discount = tourCommand.Discount; newTour.Quantity = tourCommand.Quantity; newTour.Picture = getNamePicture; newTour.Title = tourCommand.Title; } _db.Tours.Add(newTour); _db.SaveChanges(); RedirectToAction("Index", "Admin"); } } return(View()); }
public IActionResult DeleteTour(InsertTourCommand command) { this._travelService.DeleteTour(command); return(RedirectToAction("ShowAllTour", "Admin")); }
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()); }