public IHttpActionResult Follow() { var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault()); var tId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("teamId").FirstOrDefault()); var uRepo = new UserRepository(); var tRepo = new TeamRepository(); if (!(uRepo.ContainsId(uId) && tRepo.ContainsId(tId))) return NotFound(); var u = uRepo.GetById(uId); var t = tRepo.GetById(tId); u.FollowedTeams.Add(t); uRepo.SaveOrUpdate(u); return Ok(); }
public IHttpActionResult UnFollow() { var uId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("userId").FirstOrDefault()); var tId = Int32.Parse(HttpContext.Current.Request.Form.GetValues("teamId").FirstOrDefault()); var uRepo = new UserRepository(); var tRepo = new TeamRepository(); if (!(uRepo.ContainsId(uId) && tRepo.ContainsId(tId))) return NotFound(); var u = uRepo.GetById(uId); var t = tRepo.GetById(tId); if (u.FollowedTeams.Where(x => x.Id == t.Id).Take(1).Count() > 0) { u.FollowedTeams.Remove(t); t.FollowedBy.Remove(u); } uRepo.SaveOrUpdate(u); return Ok(); }