public Poll Add(Poll poll) { var id = _polls.Max(e => e.Id) + 1; poll.Id = id; _polls.Add(poll); var maxQuestionId = UtilForPoll.MaxQuestionId(_polls); var maxAnswerId = UtilForPoll.MaxAnswerId(_polls); _polls = _polls.SetIds(maxQuestionId, maxAnswerId); return(poll); }
public Poll Update(Poll pollChanges) { var pollId = pollChanges.Id; foreach (var poll in _polls.Where(poll => poll.Id == pollId)) { poll?.Update(pollChanges); } var maxQuestionId = UtilForPoll.MaxQuestionId(_polls); var maxAnswerId = UtilForPoll.MaxAnswerId(_polls); _polls = _polls.SetIds(maxQuestionId, maxAnswerId); return(GetPoll(pollId)); }
public Question UpdateQuestion(Question questionChanges) { foreach (var poll in _polls) { foreach (var question in poll.Questions) { if (question.Id == questionChanges.Id) { question.Update(questionChanges); } } } var maxQuestionId = UtilForPoll.MaxQuestionId(_polls); var maxAnswerId = UtilForPoll.MaxAnswerId(_polls); //_polls = UtilForPoll.SetIds(_polls, maxQuestionId, maxAnswerId); return(questionChanges); }