コード例 #1
0
        public async Task <IActionResult> Edit(string id, [Bind("ID,TripId,UserEmail,RegistrationDateTime")] TripRegistration tripRegistration)
        {
            if (id != tripRegistration.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(tripRegistration);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TripRegistrationExists(tripRegistration.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(tripRegistration));
        }
コード例 #2
0
ファイル: TripController.cs プロジェクト: yuvalmich/yyy-tours
        public async Task <IActionResult> Edit(string id, [Bind("ID,DisplayName,Description,PlaceId,GuideId,Price,Date,TimeInHours")] Trip trip)
        {
            if (getSessionUserType() != UserType.Admin)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(View("Error", new ErrorViewModel {
                    ErrorDescription = "אינך מורשה לגשת לעמוד זה"
                }));
            }

            if (id != trip.ID)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(View("Error", new ErrorViewModel {
                    ErrorDescription = "טיול זה לא נמצא", ControllerToLink = "Trip", ActionToLink = nameof(Index), TextToLink = "חזרה לרשימת הטיולים"
                }));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(trip);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!TripExists(trip.ID))
                    {
                        Response.StatusCode = (int)HttpStatusCode.NotFound;
                        return(View("Error", new ErrorViewModel {
                            ErrorDescription = "טיול זה לא נמצא", ControllerToLink = "Trip", ActionToLink = nameof(Index), TextToLink = "חזרה לרשימת הטיולים"
                        }));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            ViewData["GuideId"] = new SelectList(_context.User, "Email", "FullName");
            ViewData["PlaceId"] = new SelectList(_context.Place, "ID", "Name");
            return(View(trip));
        }
コード例 #3
0
ファイル: UserController.cs プロジェクト: yuvalmich/yyy-tours
        public async Task <IActionResult> Edit(string email, [Bind("Email,FullName,Phone,Password,Type")] User user)
        {
            if (getSessionUserType() != UserType.Admin)
            {
                return(View("NotAuthorized"));
            }

            if (email != user.Email)
            {
                return(View("NotFound"));
            }

            bool userTypeNotValid = _context.Trip.Count(t => t.GuideId == email) > 0 && user.Type == UserType.Tourist;

            if (userTypeNotValid)
            {
                ModelState.AddModelError("UserTypeError", "לא ניתן לשנות מדריך עם טיולים לטייל");
            }

            if (ModelState.IsValid && !userTypeNotValid)
            {
                try
                {
                    _context.Update(user);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!UserExists(user.Email))
                    {
                        return(View("NotFound"));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }

            ViewData["Type"] = EnumSelect.ToSelectList <UserType>();
            return(View(user));
        }
コード例 #4
0
        public async Task <IActionResult> Edit(string id, [Bind("ID,Name,Description,ImageUrl,Country")] Place place)
        {
            if (getSessionUserType() != UserType.Admin)
            {
                Response.StatusCode = (int)HttpStatusCode.Unauthorized;
                return(View("Error", new ErrorViewModel {
                    ErrorDescription = "אינך מורשה לגשת לעמוד זה"
                }));
            }

            if (id != place.ID)
            {
                Response.StatusCode = (int)HttpStatusCode.NotFound;
                return(View("Error", new ErrorViewModel {
                    ErrorDescription = "מקום זה לא נמצא", ControllerToLink = "Place", ActionToLink = nameof(Index), TextToLink = "חזרה לרשימת המקומות"
                }));
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(place);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PlaceExists(place.ID))
                    {
                        Response.StatusCode = (int)HttpStatusCode.NotFound;
                        return(View("Error", new ErrorViewModel {
                            ErrorDescription = "מקום זה לא נמצא", ControllerToLink = "Place", ActionToLink = nameof(Index), TextToLink = "חזרה לרשימת המקומות"
                        }));
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(place));
        }