Ejemplo n.º 1
0
        public async Task <IActionResult> Copy([Bind("TourID,Name,TourTypeID,MinDuration")] Tour tour, int?ETour)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tour);
                await _context.SaveChangesAsync(); //save tour here

                var e   = _context.Tours.Find(ETour);
                var lcs = _context.LocationSets.Where(e => e.TourID == e.TourID).ToList(); //find the target location sets
                foreach (var lc in lcs)                                                    //for each location in list
                {
                    var locationTour = new Location_Tour
                    {
                        LocationID = lc.Location.LocationID,
                        TourID     = tour.TourID
                    };
                    _context.Add(locationTour);
                    tour.Location_Tour.Add(locationTour);
                }

                tour.MinDuration = e.MinDuration;
                _context.Update(tour);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["TourTypeID"] = new SelectList(_context.TourTypes, "TourTypeID", "Label", tour.TourTypeID);
            return(View(tour));
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Create([Bind("Name,Role")] User user, int LoginId, string Password)
        {
            if (LoginId < 10000000)
            {
                ModelState.AddModelError("CreateFailed", "Wrong insetion, length of loginID too short.");
            }

            if (ModelState.IsValid)
            {
                _context.Add(user);
                await _context.SaveChangesAsync();

                var login = new Login
                {
                    LoginID          = LoginId,
                    ActivationStatus = true,
                    PasswordHash     = PBKDF2.Hash(Password),
                    UserID           = user.UserID
                };
                _context.Add(login);
                user.Login = login;
                _context.Update(user);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }


            return(View(user));
        }
        public async Task UpdateTouristGroupDetailsOfStaff(int touristGroupId, List <TouristGroupDetailsOfStaff> newList)
        {
            var listTouristGroupDetailsOfStaff = _context.TouristGroupDetailsOfStaff.Where(t => t.TouristGroupId == touristGroupId);

            _context.TouristGroupDetailsOfStaff.RemoveRange(listTouristGroupDetailsOfStaff);
            await _context.TouristGroupDetailsOfStaff.AddRangeAsync(newList);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 4
0
        public async Task <ActionResult <Tour> > PostTour(Tour tourItem)
        {
            tourItem.CreatedAt    = DateTime.Now;
            tourItem.LastModified = DateTime.Now;

            _context.Tours.Add(tourItem);
            await _context.SaveChangesAsync();

            return(CreatedAtAction(nameof(GetTourItem), new { id = tourItem.Id }, tourItem));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Length,Price,Rating,IncludesMeals")] Tour tour)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tour);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tour));
        }
Ejemplo n.º 6
0
        public async Task <IActionResult> Create([Bind("LocationId,Place,Continent")] Location location)
        {
            if (ModelState.IsValid)
            {
                _context.Add(location);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
        public async Task <IActionResult> Create([Bind("Name,X,Y,Description,MinTime")] Location location)
        {
            if (ModelState.IsValid)
            {
                _context.Add(location);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Create([Bind("TourTypeID,Label")] TourType tourType)
        {
            if (ModelState.IsValid)
            {
                _context.Add(tourType);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tourType));
        }
Ejemplo n.º 9
0
        public async Task <IActionResult> Create([Bind("Id,Name,Description,Image,EventDate,LocationId")] City city)
        {
            if (ModelState.IsValid)
            {
                _context.Add(city);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocationId"] = new SelectList(_context.Locations, "LocationId", "LocationId", city.LocationId);
            return(View(city));
        }
Ejemplo n.º 10
0
        public async Task DeleteCostDetails(int costId)
        {
            var CostDetailsList = _context.CostDetails.Where(m => m.CostId == costId);

            _context.CostDetails.RemoveRange(CostDetailsList);
            await _context.SaveChangesAsync();
        }
        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 async Task <IActionResult> Create([Bind("Location_TourID,TourID,LocationID")] Location_Tour location_Tour)
        {
            if (ModelState.IsValid)
            {
                location_Tour.Location = _context.Locations.Find(location_Tour.LocationID);
                _context.Add(location_Tour);
                var tour = _context.Tours.Find(location_Tour.TourID);
                tour.Location_Tour.Add(location_Tour);
                tour.MinDuration += location_Tour.Location.MinTime;
                await _context.SaveChangesAsync();

                return(RedirectToAction("Index", "Tours"));
            }
            ViewData["LocationID"] = new SelectList(_context.Locations, "LocationID", "Name", location_Tour.LocationID);
            ViewData["TourID"]     = new SelectList(_context.Tours, "TourID", "Name", location_Tour.TourID);
            return(View(location_Tour));
        }
        public async Task <IActionResult> AddOrEdit([Bind("TourId,TourTitle,Description,ParkCode")] Tour tour)
        {
            if (ModelState.IsValid)
            {
                if (tour.TourId == 0)
                {
                    _context.Add(tour);
                }
                else
                {
                    _context.Update(tour);
                }


                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(tour));
        }
Ejemplo n.º 14
0
        public async Task AddTourDetails(TourDetails tourDetails)
        {
            await _context.TourDetails.AddAsync(tourDetails);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 15
0
        public async Task Add(T entity)
        {
            await _context.Set <T>().AddAsync(entity);

            await _context.SaveChangesAsync();
        }
Ejemplo n.º 16
0
        public async Task AddJobDetails(List <JobDetails> listJob)
        {
            await _context.JobDetails.AddRangeAsync(listJob);

            await _context.SaveChangesAsync();
        }