public void VotingIsEnded(SendTaskFromAdminRequest request) { try { using (DDS_Context dbContext = new DDS_Context()) { InterestService _interest = new InterestService(); var sameSeniorsCount = _interest.GetSameInterestDevelopersCount(request.UserId); var acceptanceVotesCount = dbContext.TempWord.FirstOrDefault(x => x.Id == request.Id).AcceptanceVote; var rejectionVotesCount = dbContext.TempWord.FirstOrDefault(x => x.Id == request.Id).RejectionVote; if (acceptanceVotesCount + rejectionVotesCount == sameSeniorsCount) { if (acceptanceVotesCount < rejectionVotesCount) { var entity = dbContext.TempWord.FirstOrDefault(x => x.Id == request.Id); entity.Status = 6; dbContext.SaveChanges(); } else { var entity = dbContext.TempWord.FirstOrDefault(x => x.Id == request.Id); var item = new Dictionary_Development_System_Data.Dictionary(); //var willDeleteVotes = dbContext.Votes.Where(x => x.WordId == request.Id).ToList(); //var tempVotes = new List<Votes>(); //if(willDeleteVotes != null) //{ // foreach (var vote in willDeleteVotes) // { // tempVotes.Add(vote); // } // foreach (var vote in tempVotes) // { // willDeleteVotes.Remove(vote); // } // dbContext.SaveChanges(); //} item.Content = entity.Content; item.CreatedDate = entity.CreatedDate; item.UpdatedDate = DateTime.Now; item.InterestId = entity.InterestId; item.Word = entity.Word; item.DeveloperId = entity.DeveloperId ?? 0; dbContext.Dictionary.Add(item); dbContext.TempWord.Remove(entity); dbContext.SaveChanges(); } } else { return; } } } catch (Exception ex) { throw ex; } }