public async Task OnGetAsync() { var allMedia = await mpc.GetMediaAsync(); foreach (var item in allMedia) { MediaDTO media = new MediaDTO(); media.Id = item.Id; media.Type = item.Type; media.AbsPath = item.AbsPath; media.Deleted = item.Deleted; media.Characteristics = new List <CharacteristicDTO>(); foreach (var cc in item.Characteristics) { CharacteristicDTO cdto = new CharacteristicDTO(); cdto.Id = cc.Id; cdto.Name = cc.Name; cdto.Type = cc.Type; cdto.CharValues = new List <CharValueDTO>(); foreach (var cv in cc.CharValues) { CharValueDTO cvdto = new CharValueDTO(); cvdto.Id = cv.Id; cvdto.Value = cv.Value; cdto.CharValues.Add(cvdto); } media.Characteristics.Add(cdto); } Media.Add(media); } }
public async Task <IActionResult> OnGetAsync(int?id) { if (id == null) { return(NotFound()); } var allMedia = await mpc.GetMediaAsync(); foreach (var item in allMedia) { if (item.Id == id) { Media.Id = item.Id; Media.Type = item.Type; Media.AbsPath = item.AbsPath; Media.Deleted = item.Deleted; Media.Characteristics = new List <CharacteristicDTO>(); foreach (var cc in item.Characteristics) { CharacteristicDTO cdto = new CharacteristicDTO(); cdto.Id = cc.Id; cdto.Name = cc.Name; cdto.Type = cc.Type; cdto.CharValues = new List <CharValueDTO>(); foreach (var cv in cc.CharValues) { if (cv.Media.Id == id) { CharValueDTO cvdto = new CharValueDTO(); cvdto.Id = cv.Id; cvdto.Value = cv.Value; cdto.CharValues.Add(cvdto); } } Media.Characteristics.Add(cdto); } } } if (Media == null) { return(NotFound()); } return(Page()); }