Ejemplo n.º 1
0
        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));
        }
Ejemplo n.º 3
0
        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));
        }
Ejemplo n.º 4
0
        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));
        }
Ejemplo n.º 5
0
        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));
        }
Ejemplo n.º 6
0
        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));
        }
Ejemplo n.º 7
0
        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();
        }
Ejemplo n.º 8
0
        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();
        }
Ejemplo n.º 9
0
        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();
        }
Ejemplo n.º 10
0
 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());
     }
 }
Ejemplo n.º 11
0
        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();
        }
Ejemplo n.º 12
0
        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();
        }
Ejemplo n.º 13
0
        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)));;
        }
Ejemplo n.º 15
0
        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();
        }
Ejemplo n.º 16
0
        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"));
        }
Ejemplo n.º 18
0
 public void Add(Gia gia)
 {
     _context.Gias.Add(gia);
     _context.SaveChanges();
 }
Ejemplo n.º 19
0
 public void Add(NhanVien entity)
 {
     _context.NhanViens.Add(entity);
     _context.SaveChanges();
 }
Ejemplo n.º 20
0
 public void Add(ChiTieu chiTieu)
 {
     _context.ChiTieus.Add(chiTieu);
     _context.SaveChanges();
 }
Ejemplo n.º 21
0
 public IActionResult Register(Account account)
 {
     _db.Accounts.Add(account);
     _db.SaveChanges();
     return(View("/Views/Customer/Login.cshtml"));
 }
Ejemplo n.º 22
0
 public void Add(Tour entity)
 {
     _context.Tours.Add(entity);
     _context.SaveChanges();
 }
Ejemplo n.º 23
0
 public void CreateTourCategory([FromBody] tourcategory tourCategory)
 {
     db.tourcategories.Add(tourCategory);
     db.SaveChanges();
 }
Ejemplo n.º 24
0
 public void Add(LoaiHinhDL lhdl)
 {
     _context.LoaiHinhDLs.Add(lhdl);
     _context.SaveChanges();
 }
Ejemplo n.º 25
0
        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);
                }
            }
        }
Ejemplo n.º 26
0
 public void Add(HanhKhach entity)
 {
     _context.HanhKhachs.Add(entity);
     _context.SaveChanges();
 }
Ejemplo n.º 27
0
 public void Add(DoanKhach entity)
 {
     _context.DoanKhachs.Add(entity);
     _context.SaveChanges();
 }
Ejemplo n.º 28
0
 public void Add(DiaDiem entity)
 {
     _context.DiaDiems.Add(entity);
     _context.SaveChanges();
 }