public ActionResult UserSearchByEmailForm(int travelGroupID) { var MyORM = new habiticatravelEntities(); var currentUserId = User.Identity.GetUserId(); // UserGroups viewmodel to pass both TravelGroup and the current username var currentTravelGroup = MyORM.TravelGroups.Find(travelGroupID); // we need to store a list of TravelGroupandUsers, I modified the viewmodel to also contain user id so we // can conditionally render the buttons according to if the user owns the group. var model = new TravelGroupandUser() { TravelGroup = new TravelGroup() { Destination = currentTravelGroup.Destination, GroupLeader = currentTravelGroup.GroupLeader, TravelGroupId = currentTravelGroup.TravelGroupId, TravelMethod = currentTravelGroup.TravelMethod }, }; return(View(model)); }
public ActionResult DeleteGroupUser(TravelGroupandUser model) { var MyORM = new habiticatravelEntities(); TravelGroupUser UserToDelete = MyORM.TravelGroupUsers.Find(model.TravelGroupUser.TravelGroupUsersId); MyORM.TravelGroupUsers.Remove(UserToDelete); MyORM.SaveChanges(); return(RedirectToAction("ManageMyGroup")); }
public ActionResult AddNewUserToGroup(TravelGroupandUser model) // Adds new user to travel group { //1. Search user by email or username var HabiticaORM = new habiticatravelEntities(); TravelGroupUser MyTravelGroupUser = new TravelGroupUser() { UserId = model.TravelGroupUser.UserId, TravelGroupId = model.TravelGroup.TravelGroupId, UserGroupRole = false, UserGroupScore = 0 }; //2. Add member to group , we really might not need this. HabiticaORM.TravelGroupUsers.Add(MyTravelGroupUser); HabiticaORM.SaveChanges(); //3. Return/Redirect Action to a View return(RedirectToAction("ManageMyGroup")); }
public ActionResult SearchUserByEmail(TravelGroupandUser model) { var userManager = new UserManager <ApplicationUser>(new UserStore <ApplicationUser>(new ApplicationDbContext())); //var userEmail try { ApplicationUser user = userManager.FindByEmail(model.Email); ViewBag.showEmail = user.Email; model.TravelGroupUser = new TravelGroupUser() { UserId = user.Id }; // model.TravelGroupUser = MyTGUser; return(View("UserSearchByEmailForm", model)); } catch (NullReferenceException) { // store into viewbag error "user does not exist" ViewBag.UserNullMessage = ("Sorry, Please enter an email of a registered user"); return(View("UserSearchByEmailForm", model)); } }
public ActionResult SaveUpdatedGroupChanges(TravelGroup model) { var MyORM = new habiticatravelEntities(); string currentUserId = User.Identity.GetUserId(); int TravelGroupId = model.TravelGroupId; if (!ModelState.IsValid) { return(View("../Shared/Error")); } var MyDBGroup = MyORM.TravelGroups.Find(model.TravelGroupId); MyORM.Entry(MyDBGroup).CurrentValues.SetValues(model); MyORM.SaveChanges(); List <TravelGroupandUser> model2 = new List <TravelGroupandUser>(); List <int> TravelGroupIds = MyORM.TravelGroupUsers.Where(u => u.UserId == currentUserId).Select(u => u.TravelGroupId).ToList(); foreach (int TGId in TravelGroupIds) { TravelGroup tempGroup = MyORM.TravelGroups.Single(u => u.TravelGroupId == TGId); TravelGroupandUser tempTGU = new TravelGroupandUser { TravelGroup = tempGroup }; //can insert another foreach loop if we need the users, too model2.Add(tempTGU); } return(View("ManageMyGroup", model2)); }
public ActionResult UserSearch(TravelGroupandUser model) { ViewBag.GroupId = model.TravelGroup.TravelGroupId; return(View(model)); }