public async Task <RiggedFixture> AddRiggedFixtureAsync(RiggedFixture fixture) { try { fixture.Structure = await _context.Structures.FirstAsync(s => s.Id == fixture.Structure.Id); } catch (InvalidOperationException) { throw new KeyNotFoundException("Structure ID not found"); } try { fixture.Fixture = await _context.Fixtures.Include(f => f.Modes).FirstAsync(f => f.Id == fixture.Fixture.Id); } catch (InvalidOperationException) { throw new KeyNotFoundException("Fixture ID not found"); } if (fixture.Mode != null) { fixture.Mode = await _context.FixtureModes.FirstAsync(fm => fm.Id == fixture.Mode.Id); } else if (fixture.Fixture.Modes.Count > 0) { fixture.Mode = fixture.Fixture.Modes[0]; } await _context.RiggedFixtures.AddAsync(fixture); await _context.SaveChangesAsync(); await _structureService.UpdateLastModifiedAsync(fixture.Structure); return(fixture); }
public async Task <View> CreateViewAsync(View view) { Drawing drawing; try { drawing = await _context.Drawings.FirstAsync(d => d.Id == view.Drawing.Id); } catch (InvalidOperationException) { throw new KeyNotFoundException("Drawing ID not found"); } View newView = new View(); newView.Drawing = drawing; newView.Name = view.Name; newView.Width = view.Width; newView.Height = view.Height; newView.Type = view.Type; newView.Structures = new List <Structure>(); newView.Labels = new List <Label>(); await _context.Views.AddAsync(newView); await _context.SaveChangesAsync(); await UpdateLastModifiedAsync(newView); return(newView); }
public async Task CreateFixtureAsync(Fixture fixture) { try { fixture.Type = await _context.FixtureTypes.FirstAsync(t => t.Id == fixture.Type.Id); fixture.Image = await _context.StoredImages.FirstAsync(i => i.Id == fixture.Image.Id); fixture.Symbol = await _context.Symbols.Include(s => s.Bitmap).FirstAsync(i => i.Id == fixture.Symbol.Id); } catch (InvalidOperationException) { throw new KeyNotFoundException("Related record not found"); } if (fixture.Modes == null || fixture.Modes.Count == 0) { fixture.Modes = new List <FixtureMode>(); fixture.Modes.Add(new FixtureMode { Name = "Default", Channels = 1 }); } // if symbol bitmap not already created if (fixture.Symbol.Bitmap == null) { fixture.Symbol.Bitmap = await CreateSymbolBitmapAsync(fixture.Symbol.Path); } await _context.Fixtures.AddAsync(fixture); await _context.SaveChangesAsync(); }
public async Task <Label> AddLabelAsync(Label label) { try { label.View = await _context.Views.FirstAsync(v => v.Id == label.View.Id); } catch (InvalidOperationException) { throw new KeyNotFoundException("View ID not found"); } _context.Labels.Add(label); await _context.SaveChangesAsync(); return(label); }
public async Task <Structure> AddStructureAsync(Structure structure) { try { structure.View = await _context.Views.FirstAsync(v => v.Id == structure.View.Id); } catch (InvalidOperationException) { throw new KeyNotFoundException("View ID not found"); } if (structure.Type != null) { structure.Type = await _context.StructureTypes.FirstAsync(st => st.Id == structure.Type.Id); } else { structure.Type = await GetStructureTypeByNameAsync("Bar"); } if (structure.Fixtures != null) { foreach (RiggedFixture fixture in structure.Fixtures) { fixture.Fixture = await _context.Fixtures.FirstAsync(f => f.Id == fixture.Fixture.Id); fixture.Mode = await _context.FixtureModes.FirstAsync(fm => fm.Id == fixture.Mode.Id); } } await _context.Structures.AddAsync(structure); await _context.SaveChangesAsync(); await _viewService.UpdateLastModifiedAsync(structure.View); return(structure); }
public async Task CreateTypesAsync(string[] names) { foreach (string name in names) { FixtureType type = new FixtureType(); type.Name = name; await _context.FixtureTypes.AddAsync(type); await _context.SaveChangesAsync(); } }
public async Task CreateTemplateAsync(string drawingId) { Drawing drawing; try { drawing = await _context.Drawings.FirstAsync(d => d.Id == drawingId); } catch (InvalidOperationException) { throw new KeyNotFoundException("Drawing ID not found"); } if (await IsTemplateAsync(drawingId)) { throw new InvalidOperationException("Drawing is already a template"); } Template template = new Template(); template.Drawing = drawing; _context.Templates.Add(template); await _context.SaveChangesAsync(); }
public async Task <string> CreateDrawingAsync(string userId, Drawing drawing) { try { drawing.Owner = await _context.Users.FirstAsync(u => u.Id == userId); } catch (InvalidOperationException) { throw new UnauthorizedAccessException("Invalid user ID"); } drawing.LastModified = DateTime.Now; View view = new View(); view.Drawing = drawing; view.Name = "Default"; view.Width = drawing.Views[0].Width; view.Height = drawing.Views[0].Height; drawing.Views = null; _context.Drawings.Add(drawing); _context.Views.Add(view); await _context.SaveChangesAsync(); return(drawing.Id); }