Exemplo n.º 1
0
        private bool TryAskingIfExists(IBlueprint asked)
        {
            bool exists;
            BlueprintAndEntityConverter translator = new BlueprintAndEntityConverter();
            BlueprintEntity             toAsk      = translator.BlueprintToEntiy(asked);

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                Guid askedId = asked.GetId();
                exists = context.Blueprints.Any(bp => bp.Id == askedId);
            }
            return(exists);
        }
Exemplo n.º 2
0
        private void TryToDelete(IBlueprint toRemove)
        {
            if (Exists(toRemove))
            {
                BlueprintAndEntityConverter translator = new BlueprintAndEntityConverter();
                BlueprintEntity             converted  = translator.BlueprintToEntiy(toRemove);

                using (BlueBuilderDBContext context = new BlueBuilderDBContext())
                {
                    Guid            removeId = toRemove.GetId();
                    BlueprintEntity record   = context.Blueprints.FirstOrDefault(be => be.Id == removeId);
                    context.Blueprints.Remove(record);
                    context.SaveChanges();
                }
            }
        }
Exemplo n.º 3
0
        private IBlueprint BuildBlueprint(BlueprintEntity blueprint)
        {
            BlueprintAndEntityConverter converter = new BlueprintAndEntityConverter();
            ICollection <WallEntity>    wallEnts;
            ICollection <OpeningEntity> openEnts;
            ICollection <ColumnEntity>  colEnts;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                wallEnts = context.Walls.Where(we => we.BearerBlueprint.Id == blueprint.Id).ToList();
                openEnts = context.Openings.Include(o => o.Template).Where(we => we.BearerBlueprint.Id == blueprint.Id).ToList();
                colEnts  = context.Columns.Where(ce => ce.BearerBlueprint.Id == blueprint.Id).ToList();
            }
            IBlueprint builtBlueprint = converter.EntityToBlueprint(blueprint, wallEnts, openEnts, colEnts);

            return(builtBlueprint);
        }
Exemplo n.º 4
0
        public void Add(IBlueprint toStore)
        {
            BlueprintAndEntityConverter   blueprintTranslator = new BlueprintAndEntityConverter();
            MaterialAndEntityConverter    materialTranslator  = new MaterialAndEntityConverter();
            BlueprintEntity               converted           = blueprintTranslator.BlueprintToEntiy(toStore);
            IEnumerable <ColumnEntity>    convertedColumns    = toStore.GetColumns().Select(c => materialTranslator.ColumnToEntity((Column)c, converted));
            IEnumerable <WallEntity>      convertedWalls      = toStore.GetWalls().Select(w => materialTranslator.WallToEntity(w, converted));
            IEnumerable <SignatureEntity> convertedSignatures = toStore.GetSignatures().Select(s => blueprintTranslator.SignatureToEntity(s, converted));
            ICollection <Opening>         itsOpenings         = toStore.GetOpenings();

            try
            {
                AddBlueprintEntity(converted, convertedWalls, convertedColumns, itsOpenings, convertedSignatures);
            }
            catch (DbException) {
                throw new InaccessibleDataException();
            }
        }