public async Task <IActionResult> Edit(int id, [Bind("PostId,Text,TypeId,DateCreated,Images,OwnerId")] Post post) { if (id != post.PostId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(post); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!PostExists(post.PostId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } //ViewData["OwnerId"] = new SelectList(_context.Users, "Id", "Id", post.OwnerId); ViewData["TypeId"] = new SelectList(_context.Interests, "InterestId", "Name", post.TypeId); return(View(post)); }
public async Task <IActionResult> SendFriendRequest(string UserId, bool accept = true, bool fr = false) { var CurrentUserId = _userManager.GetUserId(User); Friend requestSent = await _context.Friends.FindAsync(CurrentUserId, UserId); Friend requestRecieved = await _context.Friends.FindAsync(UserId, CurrentUserId); if (ModelState.IsValid) { if (requestSent == null && requestRecieved == null) { Friend friend = new Friend { RequestedById = CurrentUserId, RequestedToId = UserId, RequestTime = DateTime.Now, FriendRequestFlag = FriendRequestFlag.Pending }; _context.Add(friend); } else if (requestSent != null) { _context.Remove(requestSent); } else if (requestRecieved != null && accept) { requestRecieved.FriendSince = DateTime.Now; requestRecieved.FriendRequestFlag = FriendRequestFlag.Approved; _context.Update(requestRecieved); } else if (requestRecieved != null && !accept) { _context.Remove(requestRecieved); } else { //mislim da su to sve opcije } await _context.SaveChangesAsync(); } if (fr) { return(RedirectToAction("FriendRequests", "AppUsers")); } return(RedirectToAction("Details", "AppUsers", new { id = UserId })); }