private void AddBlueprintEntity(BlueprintEntity converted, IEnumerable <WallEntity> itsWalls, IEnumerable <ColumnEntity> itsColumns, ICollection <Opening> itsOpenings, IEnumerable <SignatureEntity> itsSignatures) { using (BlueBuilderDBContext context = new BlueBuilderDBContext()) { context.Blueprints.Add(converted); UserEntity owner = converted.Owner; if (context.Users.Any(u => u.UserName.Equals(owner.UserName))) { context.Entry(converted.Owner).State = EntityState.Unchanged; } context.Columns.AddRange(itsColumns); context.Walls.AddRange(itsWalls); context.Signatures.AddRange(itsSignatures); MaterialAndEntityConverter materialTranslator = new MaterialAndEntityConverter(); foreach (Opening op in itsOpenings) { string tempName = op.getTemplateName(); OpeningTemplateEntity itsTemplate = context.OpeningTemplates .FirstOrDefault(t => t.Name.Equals(tempName)); OpeningEntity opRecord = materialTranslator.OpeningToEntity(op, itsTemplate, converted); context.Openings.Add(opRecord); } context.SaveChanges(); } }
public OpeningEntity OpeningToEntity(Opening toConvert, OpeningTemplateEntity itsTemplate, BlueprintEntity bearer) { OpeningEntity conversion = new OpeningEntity() { CoordX = toConvert.GetPosition().CoordX, CoordY = toConvert.GetPosition().CoordY, Template = itsTemplate, BearerBlueprint = bearer }; return(conversion); }
public Opening EntityToOpening(OpeningEntity toConvert) { Point pos = new Point(toConvert.CoordX, toConvert.CoordY); Template temp = EntityToOpeningTemplate(toConvert.Template); Opening conversion; switch (toConvert.Template.ComponentType) { case ((int)ComponentType.DOOR): conversion = new Door(pos, temp); break; case ((int)ComponentType.WINDOW): conversion = new Window(pos, temp); break; default: throw new Exception(); break; } return(conversion); }