private ServiceStatusVM ConvertServiceStatusToServiceStatusVM(List <ServiceStatus> servicesStatus) { ServiceStatusVM serviceStatusVM = new ServiceStatusVM(); //TODO: usar linq para agrupar foreach (ServiceStatus service in servicesStatus) { if (!serviceStatusVM.Regions.Exists(r => r.Id == service.RegionId)) { serviceStatusVM.Regions.Add(new RegionVM() { Id = service.RegionId, Name = service.Region.Name }); } ServiceVM serviceVM; if (!serviceStatusVM.Services.Any(s => s.Id == service.ServiceId)) { serviceVM = new ServiceVM() { Id = service.ServiceId, Name = service.Service.Name, }; serviceStatusVM.Services.Add(serviceVM); } else { serviceVM = serviceStatusVM.Services.First(s => s.Id == service.ServiceId); } serviceVM.Regions.Add(new RegionStatusVM() { RegionId = service.RegionId, Name = service.Region.Name, Status = service.Status.ToString() }); } return(serviceStatusVM); }
private ServiceStatusVM CompleteRegions(ServiceStatusVM serviceStatusVM) { foreach (RegionVM region in serviceStatusVM.Regions) { foreach (ServiceVM service in serviceStatusVM.Services) { if (!service.Regions.Any(r => r.RegionId == region.Id)) { service.Regions.Add(new RegionStatusVM() { RegionId = region.Id, Name = region.Name, Status = string.Empty }); } } } return(serviceStatusVM); }