Exemple #1
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 <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));
        }
Exemple #3
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Length,Price,Rating,IncludesMeals")] Tour tour)
        {
            if (id != tour.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tour);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TourExists(tour.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tour));
        }
Exemple #4
0
        public async Task <IActionResult> Edit(int id, [Bind("LocationId,Place,Continent")] Location location)
        {
            if (id != location.LocationId)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(location);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!LocationExists(location.LocationId))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(location));
        }
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,Description,Image,EventDate,LocationId")] City city)
        {
            if (id != city.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(city);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!CityExists(city.Id))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["LocationId"] = new SelectList(_context.Locations, "LocationId", "LocationId", city.LocationId);
            return(View(city));
        }
Exemple #6
0
        public async Task <IActionResult> Edit(int id, [Bind("TourTypeID,Label")] TourType tourType)
        {
            if (id != tourType.TourTypeID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tourType);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TourTypeExists(tourType.TourTypeID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tourType));
        }
        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> 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));
        }