public IActionResult RegisterUser(RegisterUserViewModel registerUserViewModel) { //check to see if the user name entered already exists //checkUserName = context.User.Single(u => u.Username == registerUserViewModel.Username); User checkUserName = context.User.FirstOrDefault(u => u.Username == registerUserViewModel.Username); if (checkUserName != null) { ViewBag.userNameExists = "This user name already exists. Please select another user name"; ViewBag.colon = ":"; return(View(registerUserViewModel)); } if (ModelState.IsValid) { User newUser = new User(registerUserViewModel.Username, registerUserViewModel.Password, registerUserViewModel.GCalEmail, registerUserViewModel.GCalEmailPassword, registerUserViewModel.CellPhoneNumber); context.User.Add(newUser); context.SaveChanges(); ViewBag.User = registerUserViewModel; HttpContext.Session.SetString("Username", newUser.Username); HttpContext.Session.SetInt32("ID", newUser.ID); HttpContext.Session.SetString("CellPhone", newUser.CellPhoneNumber); HttpContext.Session.SetString("CellPhoneNumber", newUser.CellPhoneNumber); return(View("UserHomePage", newUser)); } return(View(registerUserViewModel)); }
public IActionResult ScheduleEventsAndReminders(ScheduleEventsAndRemindersViewModel newEventAndReminder) { if (ModelState.IsValid) { // create recurring reminder record User newUser = context.User.Single(u => u.ID == newEventAndReminder.UserId); RecurringReminders newRecurringReminder = new RecurringReminders(newEventAndReminder.RecurringEventName, newEventAndReminder.RecurringEventDescription, newEventAndReminder.RecurringReminderStartAlertDate, newEventAndReminder.RecurringReminderLastAlertDate, newEventAndReminder.RecurringReminderRepeatFrequency); newRecurringReminder.User = newUser; context.RecurringReminders.Add(newRecurringReminder); // create recurring event record RecurringEvents newEventTypeRecurring = new RecurringEvents(newEventAndReminder.RecurringEventName, newEventAndReminder.RecurringEventDescription); newEventTypeRecurring.User = newUser; context.RecurringEvents.Add(newEventTypeRecurring); // save the new event and reminder to the data base context.SaveChanges(); return(View("RecurringEventsAndReminders", newRecurringReminder)); } //ViewBag.User = registerUserViewModel; return(View(newEventAndReminder)); }
public IActionResult RegisterUser(RegisterUserViewModel registerUserViewModel) { // check to see if the user name entered alredy exists User checkUserName = context.User.Single(u => u.Username == registerUserViewModel.Username); if (checkUserName.Username != null) { ViewBag.userNameExists = "This user name already exists. Please select another user name"; return(View(registerUserViewModel)); } if (ModelState.IsValid) { User newUser = new User(registerUserViewModel.Username, registerUserViewModel.Password, registerUserViewModel.GCalEmail, registerUserViewModel.GCalEmailPassword); context.User.Add(newUser); context.SaveChanges(); ViewBag.User = registerUserViewModel; return(View("UserHomePage", newUser)); } return(View(registerUserViewModel)); }