public bool SubscribesByUserId(int unSubUserId, int myUserId) { Following following = new Following() { FollowerId = myUserId, FollowingId = unSubUserId }; var result = _followingRepository.GetFollowByUserId(unSubUserId, myUserId); if (result == null) { _followingRepository.Add(following); _followingRepository.SaveChange(); } else { if (result.IsDelete == true) { result.IsDelete = false; _followingRepository.Update(result); _followingRepository.SaveChange(); } } return(true); }
public ActionResult Create([Bind(Include = "follwingId,followerUserId,followeeuserId")] Following following) { if (_followingRepository.GetAll().Any(x => x.followerUserId == following.followerUserId && x.followeeuserId == following.followeeuserId)) { string followerUsername = _userDataRepository.FindById(following.followerUserId).userName; string followeeUsername = _userDataRepository.FindById(following.followeeuserId).userName; ModelState.AddModelError("", followerUsername + " already follows " + followeeUsername); } if (following.followerUserId == following.followeeuserId) { ModelState.AddModelError("", "A user cannot follow him/herself"); } if (ModelState.IsValid) { _followingRepository.Add(following); return(RedirectToAction("Index")); } ViewBag.followeeuserId = new SelectList(_userDataRepository.GetAll(), "userId", "userName"); ViewBag.followerUserId = new SelectList(_userDataRepository.GetAll(), "userId", "userName"); return(View(following)); }
public IActionResult Post(Following following) { _followingRepository.Add(following); return(Ok()); }