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 ActionResult Create([Bind(Include = "ID,LocationID,LocationName,LocationDescription,Country")] Location location) { if (ModelState.IsValid) { db.Locations.Add(location); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(location)); }
public ActionResult Create([Bind(Include = "idCliente,identificacion,nombre,apellidos,email,telefono,password,activo")] cliente cliente) { if (ModelState.IsValid) { db.cliente.Add(cliente); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(cliente)); }
public ActionResult Create([Bind(Include = "TourID,TourName,TourDescription,TourPrice")] Tour tour) { if (ModelState.IsValid) { db.Tours.Add(tour); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(tour)); }
public ActionResult Create([Bind(Include = "idReserva,idTour,idCliente,cantidadNinos,cantidadAdultos,costoTotal,fechaReserva")] reserva_tour reserva_tour) { if (ModelState.IsValid) { db.reserva_tour.Add(reserva_tour); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.idCliente = new SelectList(db.cliente, "idCliente", "identificacion", reserva_tour.idCliente); ViewBag.idTour = new SelectList(db.tour, "idTour", "nombre", reserva_tour.idTour); return(View(reserva_tour)); }
public ActionResult Create([Bind(Include = "ID,Name,PriceUSD,StartConnectionID,ProgramFirstDayID,Description,FoodTypeID")] Tour tour) { if (ModelState.IsValid) { db.Tour.Add(tour); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.ProgramFirstDayID = new SelectList(db.Day_Connection, "Id", "Id", tour.ProgramFirstDayID); ViewBag.FoodTypeID = new SelectList(db.FoodType, "Id", "Description", tour.FoodTypeID); ViewBag.StartConnectionID = new SelectList(db.Route_Connection, "ID", "ID", tour.StartConnectionID); return(View(tour)); }
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 void BookingTour(BookingTourCommand command) { var newCustomer = new Customer(command); _db.Customers.Add(newCustomer); _db.SaveChanges(); //Insert Contract ContractViewModel contract = new ContractViewModel(); { contract.CustomerId = newCustomer.Id; contract.TourId = command.TourId; contract.BeginDate = command.BeginDate; contract.Paid = false; contract.Content = command.Content; } var newContract = new Contract(contract); _db.Contracts.Add(newContract); _db.SaveChanges(); var tour = _db.Tours.FirstOrDefault(n => n.Id == command.TourId); { tour.Quantity = tour.Quantity - Convert.ToInt32(command.PeopleGo); } _db.SaveChanges(); //Insert ContractDetail ContractDetailViewModel contractDetail = new ContractDetailViewModel(); { contractDetail.TourId = tour.Id; contractDetail.NameTour = tour.NameTour; contractDetail.Cost = tour.Cost; contractDetail.PeopleGo = Convert.ToInt32(command.PeopleGo); contractDetail.ContractId = newContract.Id; } var newContractDetail = new ContractDetail(); { newContractDetail.TourId = contractDetail.TourId; newContractDetail.NameTour = contractDetail.NameTour; newContractDetail.Cost = contractDetail.Cost; newContractDetail.PeopleGo = contractDetail.PeopleGo; newContractDetail.ContractId = contractDetail.ContractId; } _db.ContractDetails.Add(newContractDetail); _db.SaveChanges(); }
private void Add() { StreamReader r = new StreamReader(Server.MapPath("~/App_Data/api_tours.json")); string json = r.ReadToEnd(); List <Tour> tours = JsonConvert.DeserializeObject <List <Tour> >(json); db.Tours.AddRange(tours); db.SaveChanges(); }
public ActionResult Crear(Models.tour objTour) { if (TempData.ContainsKey("mensaje")) { ViewBag.Mensaje = TempData["mensaje"].ToString(); } try { // TODO: Add insert logic here db.tour.Add(objTour); db.SaveChanges(); TempData["mensaje"] = "Tour guardado satisfactoriamente!"; return(RedirectToAction("Index")); } catch { TempData["mensaje"] = "Tour NO registrado"; return(View()); } }
public void AddTours() { using var context = new TourContext(serviceProvider.GetRequiredService <DbContextOptions <TourContext> >()); Console.WriteLine("Enter tour name: "); string name = Console.ReadLine(); Console.WriteLine("How many locations you want to add into the tour:"); int count = 0; try { count = Convert.ToInt32(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e); count = Convert.ToInt32(Console.ReadLine()); } List <Location> locations = new List <Location>(); for (int i = 0; i < count; i++) { Console.WriteLine($"Add the {i + 1} location's Id"); int id = Convert.ToInt32(Console.ReadLine()); locations.Add(context.Locations.Find(id)); } Tour tour = new Tour { Name = name, TourTypeID = 1//seed item for console app }; List <Location_Tour> lcs = new List <Location_Tour>(); foreach (Location location in locations) { var Location_Tour = new Location_Tour { TourID = tour.TourID, LocationID = location.LocationID }; context.LocationSets.Add(Location_Tour); lcs.Add(Location_Tour); } tour.Location_Tour = lcs; tour.MinDuration = tour.caculateMinDuration(); context.Tours.Add(tour); context.SaveChanges(); }
public void AddStaff(StaffCommand staffCommand) { var newStaff = new Staff(); { newStaff.Name = staffCommand.Name; newStaff.Phone = staffCommand.Phone; newStaff.DOB = staffCommand.DOB; newStaff.Address = staffCommand.Address; newStaff.Gender = staffCommand.Gender; } _db.Staffs.Add(newStaff); _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 async Task <IActionResult> AddOrEdit([FromForm] TourViewModel t) { if (ModelState.IsValid) { if (t.TourId == 0) { var tour = new Tour(); tour.TourId = t.TourId; tour.ToursName = t.ToursName; tour.Country = t.Country; tour.Description = t.Description; tour.DaysCost = t.DaysCost; tour.ImgSrc = "/Images/NoImageFound.png"; _context.Add(tour); await _context.SaveChangesAsync(); } else { var tour = _context.Tours.FirstOrDefault(u => u.TourId == t.TourId); tour.TourId = t.TourId; tour.ToursName = t.ToursName; tour.Country = t.Country; tour.Description = t.Description; tour.DaysCost = t.DaysCost; tour.ImgSrc = t.ImgSrc; _context.Update(tour); await _context.SaveChangesAsync(); } if (t.uploadedFile != null) { // путь к папке Files string path = "/Images/" + t.uploadedFile.FileName; // сохраняем файл в папку Files в каталоге wwwroot using (var fileStream = new FileStream(_appEnvironment.WebRootPath + path, FileMode.Create)) { await t.uploadedFile.CopyToAsync(fileStream); } var tour = _context.Tours.FirstOrDefault(u => u.TourId == t.TourId); tour.ImgSrc = path; _context.Tours.Update(tour); _context.SaveChanges(); } } return(RedirectToAction(nameof(Index)));; }
public void RemoveTour() { using var context = new TourContext(serviceProvider.GetRequiredService <DbContextOptions <TourContext> >()); Console.WriteLine("Enter the tour ID you want to remove:"); int Id = 0; try { Id = Convert.ToInt32(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e); Id = Convert.ToInt32(Console.ReadLine()); } context.Tours.Remove(context.Tours.Find(Id)); context.SaveChanges(); }
public void RemoveLocatonAsync() { using var context = new TourContext(serviceProvider.GetRequiredService <DbContextOptions <TourContext> >()); Console.WriteLine("Enter the tour Location you want to remove:"); int Id = 0; try { Id = Convert.ToInt32(Console.ReadLine()); } catch (Exception e) { Console.WriteLine(e); Id = Convert.ToInt32(Console.ReadLine()); } context.LocationSets.RemoveRange(context.LocationSets.Where(e => e.Location.LocationID == Id)); context.Locations.Remove(context.Locations.Find(Id)); context.SaveChanges(); }
public ActionResult CreateTour(Tour tour, int[] selectedList) { Tour newTour = tour; newTour.Categories.Clear(); if (selectedList != null) { foreach (var c in db.Categories.Where(co => selectedList.Contains(co.Id))) { newTour.Categories.Add(c); } } db.Tours.Add(newTour); db.SaveChanges(); return(RedirectToAction("Index")); }
public void Add(Gia gia) { _context.Gias.Add(gia); _context.SaveChanges(); }
public void Add(NhanVien entity) { _context.NhanViens.Add(entity); _context.SaveChanges(); }
public void Add(ChiTieu chiTieu) { _context.ChiTieus.Add(chiTieu); _context.SaveChanges(); }
public IActionResult Register(Account account) { _db.Accounts.Add(account); _db.SaveChanges(); return(View("/Views/Customer/Login.cshtml")); }
public void Add(Tour entity) { _context.Tours.Add(entity); _context.SaveChanges(); }
public void CreateTourCategory([FromBody] tourcategory tourCategory) { db.tourcategories.Add(tourCategory); db.SaveChanges(); }
public void Add(LoaiHinhDL lhdl) { _context.LoaiHinhDLs.Add(lhdl); _context.SaveChanges(); }
public void BookingTour(BookingTourCommand command) { var newCustomer = new Customer(); newCustomer.Name = command.Name; newCustomer.Email = command.Email; newCustomer.Address = command.Address; newCustomer.Phone = command.Phone; _db.Customers.Add(newCustomer); _db.SaveChanges(); //Insert Contract ContractViewModel contract = new ContractViewModel(); { contract.CustomerId = newCustomer.Id; contract.TourId = command.TourId; contract.BeginDate = command.BeginDate; contract.Paid = false; contract.Content = command.Content; } var newContract = new Contract(contract); _db.Contracts.Add(newContract); _db.SaveChanges(); var tour = new Tour(); using (var connection = new SqlConnection(this._db.Database.GetDbConnection().ConnectionString)) { connection.Open(); if (command != null) { tour = connection.Query <Tour>(@"select * from Tour").FirstOrDefault(n => n.Id == command.TourId); } connection.Close(); } tour.Quantity = tour.Quantity - Convert.ToInt32(command.PeopleGo); dbSet.Attach(tour); _db.Entry(tour).State = EntityState.Modified; _db.SaveChanges(); //Insert ContractDetail ContractDetailViewModel contractDetail = new ContractDetailViewModel(); { contractDetail.TourId = tour.Id; contractDetail.NameTour = tour.NameTour; contractDetail.Cost = tour.Cost; contractDetail.PeopleGo = Convert.ToInt32(command.PeopleGo); contractDetail.ContractId = newContract.Id; } var newContractDetail = new ContractDetail(); { newContractDetail.TourId = contractDetail.TourId; newContractDetail.NameTour = contractDetail.NameTour; newContractDetail.Cost = contractDetail.Cost; newContractDetail.PeopleGo = contractDetail.PeopleGo; newContractDetail.ContractId = contractDetail.ContractId; } _db.ContractDetails.Add(newContractDetail); _db.SaveChanges(); using (MailMessage emailMessage = new MailMessage()) { emailMessage.From = new MailAddress("*****@*****.**", "Công ty du lịch"); emailMessage.To.Add(new MailAddress("*****@*****.**", "Account1")); emailMessage.Subject = "Thông tin đặt tour"; emailMessage.Body = "TourId: " + contractDetail.TourId + Environment.NewLine + "Tên Tour: " + contractDetail.NameTour + Environment.NewLine + "Giá: " + contractDetail.Cost + Environment.NewLine + "Số người đi: " + contractDetail.PeopleGo; emailMessage.Priority = MailPriority.Normal; using (SmtpClient MailClient = new SmtpClient("smtp.gmail.com", 587)) { MailClient.EnableSsl = true; MailClient.Credentials = new System.Net.NetworkCredential("*****@*****.**", "tungvipro809"); MailClient.Send(emailMessage); } } }
public void Add(HanhKhach entity) { _context.HanhKhachs.Add(entity); _context.SaveChanges(); }
public void Add(DoanKhach entity) { _context.DoanKhachs.Add(entity); _context.SaveChanges(); }
public void Add(DiaDiem entity) { _context.DiaDiems.Add(entity); _context.SaveChanges(); }