I have a view model whose values are sent as a list from the view for edit four input boxs ...
public class UpdatePollViewModel
{
public List<string> Answer { get; set; }
}
In my service, I got the same values from the database via Id:
public bool UpdatePoll(Guid id, UpdatePollViewModel viewModel)
{
var polloption = _context.PollOptions.Where(p => p.PollId == Id).ToList();
}
I used this but it does not make sense because it repeats a lot!!!
foreach (string item in viewModel.Answer)
{
foreach (var item2 in polloption)
{
item2.Answer = item;
_context.SaveChanges();
}
}
What is the best way to handle this?