public void DownVote(int _PlayHistoryId) { AuthHelper _ah = new AuthHelper(_uow); var _userId = _ah.SetupUser(); var _voteId = 0; List <VoteViewModel> _vvm; Vote _vote = new Vote { VoteId = 0, VoteValue = false, PlayHistoryId = _PlayHistoryId, UserId = _userId }; _vvm = this.GetVotes(_PlayHistoryId); if (_vvm != null) { if (_vvm.Find(i => i.UserId == _userId) == null) { repo.Add(_vote); } else { if (_vvm.Find (i => (i.UserId == _userId) && (i.VoteValue == true)) != null) { _voteId = _vvm.Find (i => (i.UserId == _userId) && (i.VoteValue == true)) .VoteId; _vote = repo.GetByQuery(i => i.VoteId == _voteId).FirstOrDefault(); _vote.VoteValue = false; repo.Update(_vote.UpdateData(_vote.ToModel())); } else if (_vvm.Find (i => (i.UserId == _userId) && (i.VoteValue == false)) != null) { _voteId = _vvm.Find (i => (i.UserId == _userId) && (i.VoteValue == false)) .VoteId; _vote = repo.GetByQuery(i => i.VoteId == _voteId).FirstOrDefault(); repo.Delete(_vote.DeleteData(_vote.ToModel())); } } } else { repo.Add(_vote); } repo.SaveChanges(); }