public void DeleteAttractionFastPassRequest(long AttractionFastPassRequestID, long userID) { AttractionFastPassRequest a = db.AttractionFastPassRequests.Include(nameof(User)).First(p => p.AttractionFastPassRequestID == AttractionFastPassRequestID); if (userID == a.User.UserID) { a.Status = AttractionFastPassRequestStatusEnum.Deleted; db.SaveChanges(); } }
public GetAttractionFastPassRequestsWithStatisticsModel(AttractionFastPassRequest attractionFastPassRequest, User user, Attraction attraction, Park park, DateTime?lastChecked, DateTime nextCheck, DateTime?lastAvailableResult, int numberOfChecks, int numberOfAvailableResults) { this.AttractionFastPassRequest = attractionFastPassRequest; this.AttractionFastPassRequest.User = user; this.AttractionFastPassRequest.Attraction = attraction; this.AttractionFastPassRequest.Attraction.Park = park; this.LastCheckTimestamp = lastChecked; this.NextCheck = nextCheck; this.LastAvailableResultTimestamp = lastAvailableResult; this.NumberOfChecks = numberOfChecks; this.NumberOfAvailableResults = numberOfAvailableResults; }
public IActionResult Home(HomeViewModel model) { if (ModelState.IsValid) { // get the user from the database, and determine if we're dealing with an existing user or a new one var user = facade.GetUserWithStatisticsBySMSNotificationPhoneNumber(model.SMSNotificationPhoneNumber); bool isNewUser = (user == null); // for code readability bool isExistingUser = !isNewUser; // for code readability // if this is an existing user and it is NOT the signed in user... if (isExistingUser && this.HttpContext.AppUser().IsAuthenticated&& user.User.UserID != this.HttpContext.AppUser().UserID) { // redirect to the home page return(RedirectToAction(nameof(HomeController.Home))); } // if this is an existing user and the user is NOT signed in, redirect to a sign in page with explanation if (isExistingUser && !this.HttpContext.AppUser().IsAuthenticated) { ModelState.AddModelError(nameof(SignInViewModel.PhoneNumber), string.Format(Messages.USER_BY_PHONE_NUMBER_ALREADY_EXISTS, Helpers.FormatPhoneNumber(model.SMSNotificationPhoneNumber))); return(RedirectToAction(nameof(UserController.SignIn), nameof(UserController).Replace("Controller", ""), new SignInViewModel { PhoneNumber = Helpers.FormatPhoneNumber(model.SMSNotificationPhoneNumber) })); } // if this is a new user, add the user to the database if (isNewUser) { facade.AddUser(new User { SMSNotificationPhoneNumber = model.SMSNotificationPhoneNumber }); facade.db.SaveChanges(); user = facade.GetUserWithStatisticsBySMSNotificationPhoneNumber(model.SMSNotificationPhoneNumber); } // add the fastpass check var check = new AttractionFastPassRequest { Date = model.Date, Attraction = facade.db.Attractions.First(p => p.AttractionID == model.AttractionID), NumberOfPeople = model.NumberOfPeople, UserID = user.User.UserID, Status = AttractionFastPassRequestStatusEnum.Active, CreatedOn = DateTime.UtcNow }; facade.db.AttractionFastPassRequests.Add(check); facade.db.SaveChanges(); // if this is an existing user and they are signed in redirect to the saved-successful page if (isExistingUser && this.HttpContext.AppUser().IsAuthenticated) { return(RedirectToAction(nameof(UserController.Dashboard), nameof(UserController).Replace("Controller", ""), new DashboardViewModel { NewAttractionFastPassRequestID = check.AttractionFastPassRequestID })); } // if this was a new user, send the sign in code & link and redirect to explanation page else { return(RedirectToAction(nameof(UserController.SendSignInLinkForNewUserAfterCheckCreated), nameof(UserController).Replace("Controller", ""), new SignInViewModel { PhoneNumber = model.SMSNotificationPhoneNumber })); } } return(View(model)); }