public async Task <IActionResult> RemoveAssetLocationFromAsset(int assetId, int assetLocationId) { Maestro.Data.Models.Asset asset = await _context.Assets .Include(a => a.Locations) .Where(a => a.Id == assetId) .SingleOrDefaultAsync(); if (asset == null) { return(NotFound(new ApiError($"The asset with id '{assetId}' was not found."))); } var assetLocation = asset.Locations.Find(al => al.Id == assetLocationId); // If asset location is not in the asset, nothing to do if (assetLocation == null) { return(StatusCode((int)HttpStatusCode.NotModified)); } _context.AssetLocations.Remove(assetLocation); await _context.SaveChangesAsync(); return(StatusCode((int)HttpStatusCode.OK)); }
private Asset ToClientModelAsset(Maestro.Data.Models.Asset other) { return(new Asset( other.Id, other.BuildId, other.NonShipping, other.Name, other.Version, other.Locations?.Select(l => ToClientAssetLocation(l)).ToImmutableList())); }
public async Task <IActionResult> AddAssetLocationToAsset(int assetId, [Required] string location, [Required] LocationType assetLocationType) { var assetLocation = new Data.Models.AssetLocation { Location = location, Type = (Maestro.Data.Models.LocationType)assetLocationType, }; Maestro.Data.Models.Asset asset = await _context.Assets .Include(a => a.Locations) .Where(a => a.Id == assetId) .SingleOrDefaultAsync(); if (asset == null) { return(NotFound(new ApiError($"The asset with id '{assetId}' was not found."))); } // If asset location is already in asset, nothing to do if (asset.Locations != null && asset.Locations.Any(existing => existing.Location.Equals(assetLocation.Location, StringComparison.OrdinalIgnoreCase) && existing.Type == assetLocation.Type)) { return(StatusCode((int)HttpStatusCode.NotModified)); } asset.Locations = asset.Locations ?? new List <Data.Models.AssetLocation>(); asset.Locations.Add(assetLocation); await _context.SaveChangesAsync(); return(CreatedAtRoute( new { action = "GetAsset", id = assetLocation.Id }, new AssetLocation(assetLocation))); }
private Asset ToClientModelAsset(Maestro.Data.Models.Asset other) { return(new Asset(other.Id, other.BuildId, other.NonShipping, other.Name, other.Version, null)); }