public ActionResult FriendInvite(FriendInviteViewModel model, int?friendId) { ViewBag.HasFriends = true; //find the current logged-on user var email = User.Identity.GetUserName(); var currContactUser = _contactService.GetContactByEmail(email); var currID = currContactUser.ContactId; // Get the Game from the Model var game = _gameService.GetGameById(model.GameId); // Check model validation before doing anything if (!ModelState.IsValid) { PopulateDropdownValues(currID); return(View(model)); } // get list of friends from logged in user List <Friend> friendList = _contactService.GetUsersFriends(currID); // Get contact info from friend Friend friendinv = friendList.Find(f => f.FriendID == friendId); int friendInvId = friendinv.FriendContactID; var venueName = _venueService.GetVenueNameById(game.VenueId); var sportName = _gameService.GetSportNameById(game.SportId); var fileContents = System.IO.File.ReadAllText(Server.MapPath("~/Content/EmailFormat.html")); //add game link to the email var directUrl = Url.Action("GameDetails", "Game", new { id = game.GameId }, protocol: Request.Url.Scheme); fileContents = fileContents.Replace("{URL}", directUrl); fileContents = fileContents.Replace("{URLNAME}", "CHECK"); fileContents = fileContents.Replace("{VENUE}", venueName); fileContents = fileContents.Replace("{SPORT}", sportName); fileContents = fileContents.Replace("{STARTTIME}", game.StartTime.ToString()); fileContents = fileContents.Replace("{ENDTIME}", game.EndTime.ToString()); fileContents = fileContents.Replace("{TITLE}", "Game Invite"); fileContents = fileContents.Replace("{INFO}", "Your Friend as invited youi to a game!"); var subject = "Game Invite"; // pass Game and ContactFriend to the send email function SendInvite(game, friendInvId, fileContents, subject); //redirect them back to the changed game detail return(RedirectToAction("GameDetails", "Game", new { id = model.GameId })); }
public ActionResult FriendInvite(int gameId) { ViewBag.HasFriends = false; //find the current logged-on user string email = User.Identity.GetUserName(); Contact currContactUser = _contactService.GetContactByEmail(email); // Get the id of the user int currID = currContactUser.ContactId; //Showing error message when the user has no friends on their list List <Friend> friendList = _contactService.GetUsersFriends(currContactUser.ContactId); if (friendList == null || friendList.Count == 0) { PopulateDropdownValues(currID); ViewData.ModelState.AddModelError("NoFriends", "You currently have no friends to invite"); return(View()); } else { ViewBag.HasFriends = true; } // Populate Dropdown list PopulateDropdownValues(currID); // populate model FriendInviteViewModel model = new FriendInviteViewModel(); model.ContactId = currID; model.GameId = gameId; return(View(model)); }