public IActionResult Create(UserViewModel userViewModel) { var admin = HttpContext.Session.GetObjectFromJson <User>("admin"); if (admin == null) { return(RedirectToAction("Index", "Auth")); } if (ModelState.IsValid) { db.User.Add( new User { UserTypeId = userViewModel.UserTypeId, Email = userViewModel.Email, Username = userViewModel.Username, FirstName = userViewModel.FirstName, LastName = userViewModel.LastName, Password = userViewModel.Password } ); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(userViewModel)); }
public IActionResult Create(CheckInViewModel checkInViewModel) { var user = HttpContext.Session.GetObjectFromJson <User>("user"); if (user == null) { return(RedirectToAction("Index", "Home")); } //TODO: make checkin here //get current user from session //and do checkin operation Random rand = new Random(); string code = rand.Next(100000, 999999).ToString(); db.Reservation.Add( new Reservation { UserId = user.Id, GymId = checkInViewModel.GymId, Code = code } ); db.SaveChanges(); return(RedirectToAction("Index", "CheckIn")); }
public IActionResult Create(ReservationViewModel reservationViewModel) { var admin = HttpContext.Session.GetObjectFromJson <User>("admin"); if (admin == null) { return(RedirectToAction("Index", "Auth")); } Random rand = new Random(); string code = rand.Next(100000, 999999).ToString(); db.Reservation.Add( new Reservation { UserId = reservationViewModel.UserId, GymId = reservationViewModel.GymId, Code = code } ); db.SaveChanges(); return(RedirectToAction("Index")); }
public IActionResult SignUp(RegisterViewModel registerViewModel) { if (ModelState.IsValid) { var user = new User(registerViewModel); user.UserTypeId = 3; user.Username = "******"; db.User.Add(user); db.SaveChanges(); return(RedirectToAction("Index", "Home")); } return(View(registerViewModel)); }
public IActionResult CheckIn(CheckInViewModel checkInViewModel, int id) { var gym_owner = HttpContext.Session.GetObjectFromJson <User>("gym_owner"); if (gym_owner == null) { return(RedirectToAction("Index", "Auth")); } var reservation = db.Reservation.Where(x => x.Id == id).FirstOrDefault(); if (reservation.Code == checkInViewModel.Code && !reservation.didCheckIn()) { CheckIn checkin = new CheckIn { ReservationId = id }; db.CheckIn.Add(checkin); db.SaveChanges(); } return(RedirectToAction("Index")); }
public IActionResult Create(GymViewModel gymViewModel) { var admin = HttpContext.Session.GetObjectFromJson <User>("admin"); if (admin == null) { return(RedirectToAction("Index", "Auth")); } if (ModelState.IsValid) { db.Gym.Add( new Gym { OwnerId = gymViewModel.OwnerId, Title = gymViewModel.Title } ); db.SaveChanges(); return(RedirectToAction("Index")); } return(View(gymViewModel)); }
public IActionResult AddCustomExercise(WorkoutViewModel model, string returnUrl = null) { ModelState.Remove("WorkoutName"); ModelState.Remove("WorkoutDescription"); ModelState.Remove("StartDate"); ModelState.Remove("EndDate"); ModelState.Remove("ExerciseID"); ModelState.Remove("Day"); ModelState.Remove("Amount"); ModelState.Remove("Aunit"); ViewData["ReturnUrl"] = returnUrl; if (ModelState.IsValid) { string userID = _userManager.GetUserId(User); UserExercise newCustom = new UserExercise(); newCustom.uid = userID; newCustom.name = model.CustomName + " (Custom)"; newCustom.description = model.CustomDescription; newCustom.category = 0; _context.UserEx.Add(newCustom); _context.SaveChanges(); TempData["SuccessMessage"] = "Your Exercise has been created successfully!"; ViewBag.Exercises = getExercisesFromAPI(); ViewBag.Workouts = getWorkoutsForUser(); return(View("Program")); } TempData["ErrorMessage"] = "Oops... Something went wrong.."; ViewBag.Exercises = getExercisesFromAPI(); ViewBag.Workouts = getWorkoutsForUser(); return(View("Program")); }