public List <FollowViewModel> getFollowing(int userId) { string connectionString = config.GetConnectionString("DefaultConnection"); MySqlConnection conn = new MySqlConnection(connectionString); MySqlCommand mySqlCommand = new MySqlCommand(); List <FollowViewModel> followViewModels = new List <FollowViewModel>(); try { conn.Open(); //opening DB connection mySqlCommand.Connection = conn; mySqlCommand.CommandText = "get_all_following"; mySqlCommand.CommandType = CommandType.StoredProcedure; mySqlCommand.Parameters.Add(new MySqlParameter("_user_id", userId)); MySqlDataReader reader = mySqlCommand.ExecuteReader(); while (reader.Read()) { FollowViewModel followViewModel = getFollowViewModelFromReader(reader); followViewModels.Add(followViewModel); } } catch (Exception ex) { System.Diagnostics.Debug.WriteLine(ex.Message); } finally { conn.Close(); //closing DB connection } return(followViewModels); }
public async Task <bool> FollowUser([FromBody] FollowViewModel username) { //the User who wants to follow someone. var userId = _caller.Claims.Single(c => c.Type == "id"); var customer = await _appDbContext.Customers.Include(c => c.Identity).SingleAsync(c => c.Identity.Id == userId.Value); //The user that should be followed. var FollowUser = await _appDbContext.Customers.Include(c => c.Identity).Where(x => x.Identity.Email == username.username).SingleAsync(c => c.Identity.Email == username.username); UserFollower checkFollow = _appDbContext.UserFollowers.Where(x => x.AppUserId == customer.IdentityId).Where(y => y.FollowerId == FollowUser.IdentityId).FirstOrDefault(); if (checkFollow == null) { UserFollower userFollower = new UserFollower { AppUserId = customer.Identity.Id, FollowerId = FollowUser.Identity.Id, }; _appDbContext.Add(userFollower); _appDbContext.SaveChanges(); return(true); } else { _appDbContext.UserFollowers.Remove(checkFollow); _appDbContext.SaveChanges(); return(false); } }
public IActionResult MyFollowers() { var followers = _context.Follows.Where(e => e.Followed == _userId).Include(e => e.ApplicationUser).ToList(); var follow = new FollowViewModel(); follow.Follows = followers; return(View(follow)); }
public IActionResult PeopleIFollow() { var followering = _context.Follows.Where(e => e.Following == _userId).Include(e => e.ApplicationUser).ToList(); var follow = new FollowViewModel(); follow.Follows = followering; return(View(follow)); }
public ActionResult Following() { var viewModel = new FollowViewModel { FolloweeId = _unitOfWork.Follow.GetAllUserIamFollowing(User.Identity.GetUserId()) }; return(View(viewModel)); }
private FollowViewModel getFollowViewModelFromReader(MySqlDataReader reader) { FollowViewModel followViewModel = new FollowViewModel(); followViewModel.userId = Int32.Parse(reader["user_id"].ToString()); followViewModel.username = reader["username"].ToString(); followViewModel.firstName = reader["first_name"].ToString(); followViewModel.lastName = reader["last_name"].ToString(); return(followViewModel); }
public ActionResult Index() { var userId = User.Identity.GetUserId(); var followees = _unitOfWork.Users.GetArtistsFollowedBy(userId); var viewModel = new FollowViewModel { Followees = followees, ShowActions = User.Identity.IsAuthenticated, Heading = "Artists I'm Following" }; return(View(viewModel)); }
public async Task <IActionResult> Unfollow([FromBody] FollowViewModel vm) { if (!ModelState.IsValid) { return(new BadResponseResult(ModelState)); } if (await SocialDb.Followers.Unfollow(vm.UserId, vm.FollowingId)) { return(new OkResponseResult("Now you unfollow", new { IsFollowed = false })); } return(new ResponseResult((int)HttpStatusCode.InternalServerError, "We can not disconnect you to this user.", new { IsFollowed = true })); }
public async Task <IActionResult> FollowAsync([FromBody] FollowViewModel followViewModel) { if (!ModelState.IsValid) { return(Json(ModelState.DefaultInvalidModelStateWithErrorMessages())); } int userId = Convert.ToInt32(User.FindFirstValue(ClaimTypes.NameIdentifier)); FollowerDto follower = followViewModel.GetFollowerDto(userId); ServiceResponseDto followResultDto = await _followerService.FollowUserAsync(follower); await _tempDataService.UpdateTempDataAsync(TempData, userId); return(Json(followResultDto)); }
public async Task <IActionResult> Follow([FromBody] FollowViewModel vm) { if (!ModelState.IsValid) { return(new BadResponseResult(ModelState)); } if (!await SocialDb.Followers.Follow(vm.UserId, vm.FollowingId)) { return(new ResponseResult((int)HttpStatusCode.InternalServerError, "We can not connect you to this user.", new { IsFollowed = false })); } await Hub.Notifications.SendFollowNotification(vm.UserId, vm.FollowingId, DateTime.UtcNow); return(new OkResponseResult("Now you follow", new { IsFollowed = true })); }
public async Task <ActionResult <Follow> > PostFollow(FollowViewModel vm) { Follow follow = new Follow(); var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value; var user = _context.Users.Find(userId); follow.Follower = user; follow.User = _context.Users.Find(vm.UserId); follow.DateTime = DateTime.Now; if (_context.Follows.Where(x => x.Follower == user && x.User == follow.User).Count() == 0) { _context.Follows.Add(follow); } else { _context.Follows.RemoveRange(_context.Follows.Where(x => x.Follower == user && x.User == follow.User).ToList()); } await _context.SaveChangesAsync(); return(CreatedAtAction("GetFollow", new { id = follow.Id }, follow)); }
public ActionResult Follow(string CoId, string StId) { FollowViewModel viewmodel = new FollowViewModel(); var currentUser = WebSecurity.CurrentUserId; if (!String.IsNullOrEmpty(CoId)) { var coid = EncryptionHelper.Unprotect(CoId); var followers = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid); viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser); viewmodel.Followers = followers.Count(); viewmodel.CoId = coid; } else if (!String.IsNullOrEmpty(StId)) { var stid = EncryptionHelper.Unprotect(StId); var followers = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid); viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser); viewmodel.Followers = followers.Count(); viewmodel.storeId = stid; } return(PartialView(viewmodel)); }
/// <summary> /// Creates an instance of the given type. /// </summary> /// <param name="requestedType"></param> /// <returns></returns> /// <remarks> /// Every object in the composite root should be instantiates before returning the requested type. /// Otherwise, classes may not work correctly with each other, if they use an indirect way of communicating /// such as through events. /// </remarks> private object CreateInstance(Type requestedType) { MetroWindow metroWindow = Application.Current.MainWindow as MetroWindow; App app = Application.Current as App; LibraryUpdater libraryUpdater = new LibraryUpdater(); DialogCoordinator dialogCoordinator = new DialogCoordinator(); Persister persister = new Persister(); UpdateEliteAPI updateEliteAPI = new UpdateEliteAPI(libraryUpdater, EventMessenger); SelectCharacter selectCharacterRequest = new SelectCharacter(EventMessenger, metroWindow); SelectAbilityRequestHandler selectAbilityRequestHandler = new SelectAbilityRequestHandler(metroWindow); BattlesViewModel battlesViewModel = new BattlesViewModel(); FollowViewModel followViewModel = new FollowViewModel(); IgnoredViewModel ignoredViewModel = new IgnoredViewModel(); LogViewModel logViewModel = new LogViewModel(); ReportViewModel reportViewModel = new ReportViewModel(); SelectProcessViewModel selectProcessViewModel = new SelectProcessViewModel(new SelectProcessDialog()); AutoAttachCharacter onLoadEvents = new AutoAttachCharacter(selectCharacterRequest, selectProcessViewModel, dialogCoordinator, EventMessenger); RestingViewModel restingViewModel = new RestingViewModel(); RoutesViewModel routesViewModel = new RoutesViewModel(); SettingsViewModel settingsViewModel = new SettingsViewModel(); TargetingViewModel targetingViewModel = new TargetingViewModel(); TargetsViewModel targetsViewModel = new TargetsViewModel(); TabViewModels tabViewModels = new TabViewModels(new List <IViewModel>() { reportViewModel, battlesViewModel, targetingViewModel, restingViewModel, routesViewModel, followViewModel, logViewModel, settingsViewModel, }); MainViewModel mainViewModel = new MainViewModel(tabViewModels); MasterViewModel masterViewModel = new MasterViewModel(mainViewModel, EventMessenger); if (requestedType == typeof(EventMessenger)) { return(EventMessenger); } if (requestedType == typeof(App)) { return(app); } if (requestedType == typeof(LibraryUpdater)) { return(libraryUpdater); } if (requestedType == typeof(SelectCharacter)) { return(selectCharacterRequest); } if (requestedType == typeof(SelectAbilityRequestHandler)) { return(selectAbilityRequestHandler); } if (requestedType == typeof(IDialogCoordinator)) { return(dialogCoordinator); } if (requestedType == typeof(IPersister)) { return(persister); } if (requestedType == typeof(UpdateEliteAPI)) { return(updateEliteAPI); } if (requestedType == typeof(AutoAttachCharacter)) { return(onLoadEvents); } if (requestedType == typeof(BattlesViewModel)) { return(battlesViewModel); } if (requestedType == typeof(FollowViewModel)) { return(followViewModel); } if (requestedType == typeof(IgnoredViewModel)) { return(ignoredViewModel); } if (requestedType == typeof(LogViewModel)) { return(logViewModel); } if (requestedType == typeof(ReportViewModel)) { return(reportViewModel); } if (requestedType == typeof(TabViewModels)) { return(tabViewModels); } if (requestedType == typeof(MainViewModel)) { return(mainViewModel); } if (requestedType == typeof(MasterViewModel)) { return(masterViewModel); } if (requestedType == typeof(SelectProcessViewModel)) { return(selectProcessViewModel); } if (requestedType == typeof(RestingViewModel)) { return(restingViewModel); } if (requestedType == typeof(RoutesViewModel)) { return(routesViewModel); } if (requestedType == typeof(SettingsViewModel)) { return(settingsViewModel); } if (requestedType == typeof(TargetingViewModel)) { return(targetingViewModel); } if (requestedType == typeof(TargetsViewModel)) { return(targetsViewModel); } throw new InvalidOperationException($"Could not create instance of requested type {requestedType.Name}"); }
public ActionResult FollowInsert(string company, string store) { var currentUser = WebSecurity.CurrentUserId; if (!String.IsNullOrEmpty(company)) { var coid = EncryptionHelper.Unprotect(company); var following = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid && f.followerUserID == currentUser).SingleOrDefault(); if (following != null) { unitOfWork.FollowingRepository.Delete(following); unitOfWork.Save(); FollowViewModel viewmodel = new FollowViewModel(); var followers = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid); viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser); viewmodel.Followers = followers.Count(); viewmodel.CoId = coid; return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) })); } else { var newFollow = new Following(); newFollow.followedCoID = coid; newFollow.followerUserID = currentUser; newFollow.followDate = DateTime.UtcNow; unitOfWork.FollowingRepository.Insert(newFollow); unitOfWork.Save(); FollowViewModel viewmodel = new FollowViewModel(); var followers = unitOfWork.FollowingRepository.Get(f => f.followedCoID == coid); viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser); viewmodel.Followers = followers.Count(); viewmodel.CoId = coid; return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) })); } } else if (!String.IsNullOrEmpty(store)) { var stid = EncryptionHelper.Unprotect(store); var following = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid && f.followerUserID == currentUser).SingleOrDefault(); if (following != null) { unitOfWork.FollowingRepository.Delete(following); unitOfWork.Save(); FollowViewModel viewmodel = new FollowViewModel(); var followers = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid); viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser); viewmodel.Followers = followers.Count(); viewmodel.storeId = stid; return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) })); } else { var newFollow = new Following(); newFollow.followedStoreID = stid; newFollow.followerUserID = currentUser; newFollow.followDate = DateTime.UtcNow; unitOfWork.FollowingRepository.Insert(newFollow); unitOfWork.Save(); FollowViewModel viewmodel = new FollowViewModel(); var followers = unitOfWork.FollowingRepository.Get(f => f.followedStoreID == stid); viewmodel.followedByUser = followers.Any(f => f.followerUserID == currentUser); viewmodel.Followers = followers.Count(); viewmodel.storeId = stid; return(Json(new { Result = RenderPartialViewHelper.RenderPartialView(this, "Follow", viewmodel) })); } } throw new JsonCustomException(ControllerError.ajaxErrorFollowing); }
public NicoNicoFollow(FollowViewModel owner) { Owner = owner; }