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 <ActionResult> Create(FormCollection collection) { var model = new Models.PrimaryObject() { Description = collection[nameof(Models.PrimaryObject.Description)], Name = collection[nameof(Models.PrimaryObject.Name)], SecondaryObjects = new Models.SecondaryObject[0], }; try { await _primaryObjectService.CreateAsync(model); return(RedirectToAction("Index")); } catch (Exception ex) { return(View(model)); } }
public async Task <ActionResult> Delete(Guid id) { var primaryObject = await _primaryObjectService.GetAsync(id); var model = new Models.PrimaryObject() { Id = primaryObject.Id, Description = primaryObject.Description, Name = primaryObject.Name, SecondaryObjects = primaryObject.SecondaryObjects?.Select(so => new Models.SecondaryObject() { Id = so.Id, Description = so.Description, Name = so.Name, PrimaryObjectId = primaryObject.Id, })?.ToArray() ?? new Models.SecondaryObject[0], }; return(View(model)); }
public ActionResult Create() { var model = new Models.PrimaryObject(); return(View(model)); }