public async Task <ActionResult> Edit(Guid id) { var primaryObject = await _primaryObjectService.GetAsync(id); var secondaryObjectModels = new List <Models.SecondaryObject>(); if (primaryObject.SecondaryObjects != null) { foreach (var secondaryObjectThin in primaryObject.SecondaryObjects.Where(so => so.Id.HasValue)) { var secondaryObject = await _secondaryObjectService.GetAsync(secondaryObjectThin.Id.Value); secondaryObjectModels.Add(new Models.SecondaryObject() { Id = secondaryObject.Id, Description = secondaryObject.Description, Name = secondaryObject.Name, PrimaryObjectId = primaryObject.Id, }); } } var model = new Models.PrimaryObject() { Id = primaryObject.Id, Description = primaryObject.Description, Name = primaryObject.Name, SecondaryObjects = secondaryObjectModels.OrderBy(_ => _.Name).ToArray(), }; return(View(model)); }
public async Task <ApiModels.PrimaryObject> GetAsync(Guid id) { var domainPrimaryObject = await _primaryObjectService.GetAsync(id); Ensure.That(domainPrimaryObject, nameof(domainPrimaryObject)) .WithException(_ => new HttpResponseException(HttpStatusCode.NotFound)) .IsNotNull(); return(this.Map(domainPrimaryObject)); }