public ActionResult Create(FitFit fitfit) { fitfit.Date = DateTime.Now; fitfit.UserId = WebSecurity.GetUserId(User.Identity.Name); if (ModelState.IsValid) { db.FitFits.Add(fitfit); db.SaveChanges(); return(RedirectToAction("Index")); } ViewBag.UserId = new SelectList(db.UserProfiles, "UserId", "UserName", fitfit.UserId); return(View(fitfit)); }
public ActionResult Create(PrivateMessage privatemessage, string ToWho) { privatemessage.Date = DateTime.Now; privatemessage.IsRead = false; var user = Membership.GetUser(true); privatemessage.SenderUserId = _db.UserProfiles.Find(user.ProviderUserKey).UserId; if (!ToWho.Contains(",")) { privatemessage.ReceiverUserId = _db.UserProfiles.Where(n => n.UserName == ToWho).FirstOrDefault().UserId; } else { //Burada string'i parçalayıp her receiverUsername için Id alınacak. } string conversationId1 = privatemessage.SenderUserId.ToString() + "-" + privatemessage.ReceiverUserId.ToString(); string conversationId2 = privatemessage.ReceiverUserId.ToString() + "-" + privatemessage.SenderUserId.ToString(); // Check if conversationId exists. var conversation = _db.PrivateMessages.Where(p => p.ConversationId == conversationId1 || p.ConversationId == conversationId2).FirstOrDefault(); string conversationId = String.Empty; if (conversation != null) { conversationId = conversation.ConversationId; } // If there is an initiated conversation this message belongs to that queue if (conversationId != null || conversationId != String.Empty) { privatemessage.ConversationId = conversationId; } else { privatemessage.ConversationId = privatemessage.SenderUserId + "-" + privatemessage.ReceiverUserId; } if (ModelState.IsValid) { _db.PrivateMessages.Add(privatemessage); _db.SaveChanges(); return(RedirectToAction("Index")); } return(View(privatemessage)); }
public ActionResult ExternalLoginConfirmation(RegisterExternalLoginModel model, string returnUrl) { string provider = null; string providerUserId = null; if (User.Identity.IsAuthenticated || !OAuthWebSecurity.TryDeserializeProviderUserId(model.ExternalLoginData, out provider, out providerUserId)) { return(RedirectToAction("Manage")); } if (ModelState.IsValid) { // Insert a new user into the database using (FeedForSitesDb db = new FeedForSitesDb()) { UserProfile user = db.UserProfiles.FirstOrDefault(u => u.UserName.ToLower() == model.UserName.ToLower()); // Check if user already exists if (user == null) { // Insert name into the profile table db.UserProfiles.Add(new UserProfile { UserName = model.UserName }); db.SaveChanges(); OAuthWebSecurity.CreateOrUpdateAccount(provider, providerUserId, model.UserName); OAuthWebSecurity.Login(provider, providerUserId, createPersistentCookie: false); return(RedirectToLocal(returnUrl)); } else { ModelState.AddModelError("UserName", "User name already exists. Please enter a different user name."); } } } ViewBag.ProviderDisplayName = OAuthWebSecurity.GetOAuthClientData(provider).DisplayName; ViewBag.ReturnUrl = returnUrl; return(View(model)); }
public ActionResult Fitfit(string fit) { var user = Membership.GetUser(true); FitFit fitfit = new FitFit { Date = DateTime.Now, Text = fit }; fitfit.UserId = _db.UserProfiles.Find(user.ProviderUserKey).UserId; if (ModelState.IsValid) { _db.FitFits.Add(fitfit); _db.SaveChanges(); //var fitfits = _db.FitFits.Where(f => f.UserId == fitfit.UserId).OrderByDescending(f => f.Date); return(Content(fitfit)); } return(Content(Boolean.FalseString)); }
public ActionResult Add(int?id) { UserProfile addeduser = _db.UserProfiles.Find(id); UserProfile loggedUser = _db.UserProfiles.Find(Membership.GetUser().ProviderUserKey); Friendship friendship = new Friendship() { FriendOneId = loggedUser.UserId, FriendTwoId = Convert.ToInt32(id), Approval = false, Date = DateTime.Now }; _db.Friendships.Add(friendship); _db.SaveChanges(); List <UserProfile> users = _db.UserProfiles.ToList(); ViewBag.Message = "You have send a request to add " + addeduser.UserName + " as a friend."; return(View("Index", users)); }