public async Task <IActionResult> Delete([FromBody] Models.Follow follow) { var user = await base.GetAuthenticatedUserAsync(); if (user == null) { return(base.UnauthorizedException()); } var existingFollow = await _followStore.SelectByNameThingIdAndCreatedUserId( follow.Name, follow.ThingId, user.Id); if (existingFollow != null) { var result = await _followManager.DeleteAsync(existingFollow); if (result.Succeeded) { return(base.Result(existingFollow)); } } // We should not reach here return(base.InternalServerError()); }
public ActionResult Follow(ApplicationUser model) { Follow follow = new Models.Follow(); follow.User = StaticClasses.UserRetriever.RetrieveUser(User, context); try { follow.FollowedUser = (from data in context.Users where data.UserName == model.UserName select data).First(); } catch { return(RedirectToAction("Index", "Gardener")); } follow.DateChecked = DateTime.Now; follow.DateUpdated = DateTime.Now; var follows = (from data in context.Follows where data.User.Id == follow.User.Id && data.FollowedUser.Id == follow.FollowedUser.Id select data).ToList(); if (follows.Count > 0) { return(RedirectToAction("Index", "Gardener")); } else { context.Follows.Add(follow); context.SaveChanges(); return(RedirectToAction("Index", "Gardener")); } }
public void FollowInsertTest() { Models.Follow follow = new Models.Follow(); follow.ArtistId = 9999; follow.FollowerId = 9998; Follow blFollow = new Follow(); int result = blFollow.Insert(follow); Assert.IsTrue(result > 0); }
public int Insert(Models.Follow follow) { tblFollow newFollow = new tblFollow { FollowerId = follow.FollowerId, ArtistId = follow.ArtistId }; db.Follows.Add(newFollow); db.SaveChanges(); return(newFollow.Id); }
public void Update(Models.Follow follow) { var existing = db.Follows.SingleOrDefault(f => f.Id == follow.Id); if (existing != null) { existing.ArtistId = follow.ArtistId; existing.FollowerId = follow.FollowerId; db.SaveChanges(); } }
public void FollowDeleteTest() { Follow follow = new Follow(); List <Models.Follow> follows = new List <Models.Follow>(); follows = follow.Load(); Models.Follow row = follows.Where(x => x.FollowerId == 9998).FirstOrDefault(); if (row != null) { bool actual = follow.Delete(row.Id); Assert.IsTrue(actual == true); } }
public async Task <IActionResult> Post([FromBody] Models.Follow follow) { // We need a user to subscribe to the thing var user = await base.GetAuthenticatedUserAsync(); if (user == null) { return(base.UnauthorizedException()); } // Is the user already following the thing? var existingFollow = await _followStore.SelectByNameThingIdAndCreatedUserId( follow.Name, follow.ThingId, user.Id); if (existingFollow != null) { return(base.Result(HttpStatusCode.OK, $"Authenticated user already following object with id '{follow.ThingId}'")); } // Build a new subscription var followToAdd = new Models.Follow() { Name = follow.Name, ThingId = follow.ThingId, CreatedUserId = user.Id, CreatedDate = DateTime.UtcNow }; // Add and return result var result = await _followManager.CreateAsync(followToAdd); if (result != null) { return(base.Result(result)); } // We should not reach here return(base.InternalServerError()); }
public Task <IActionResult> Put(Models.Follow follow) { throw new NotImplementedException(); }