Exemplo n.º 1
0
        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();
            }
        }
        private MaterialContainer BuildUpContainer(ICollection <WallEntity> wallEnts, ICollection <OpeningEntity> openEnts, ICollection <ColumnEntity> colEnts)
        {
            MaterialAndEntityConverter translator = new MaterialAndEntityConverter();

            ICollection <Wall>    walls    = wallEnts.Select(w => translator.EntityToWall(w)).ToList();
            ICollection <Opening> openings = openEnts.Select(o => translator.EntityToOpening(o)).ToList();
            ICollection <ISinglePointComponent> columns = colEnts.Select(c => (ISinglePointComponent)translator.EntityToColumn(c)).ToList();
            MaterialContainer container = new MaterialContainer(walls, openings, columns);

            return(container);
        }
        private void TryModifying(Template entity)
        {
            if (!Exists(entity))
            {
                throw new TemplateDoesNotExistException();
            }
            MaterialAndEntityConverter translator = new MaterialAndEntityConverter();
            OpeningTemplateEntity      record     = translator.OpeningTemplateToEntity(entity);

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                context.Entry(record).State = System.Data.Entity.EntityState.Modified;
                context.SaveChanges();
            }
        }
        private ICollection <Template> TrySelectingByCriteria(Expression <Func <OpeningTemplateEntity, bool> > aCriteria)
        {
            ICollection <Template> elegibleUsers = new List <Template>();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                MaterialAndEntityConverter         translator      = new MaterialAndEntityConverter();
                IQueryable <OpeningTemplateEntity> elegibleRecords = context.OpeningTemplates.Where(aCriteria);
                foreach (OpeningTemplateEntity record in elegibleRecords)
                {
                    elegibleUsers.Add(translator.EntityToOpeningTemplate(record));
                }
            }

            return(elegibleUsers);
        }
Exemplo n.º 5
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();
            }
        }
        private void TryAdding(Template entity)
        {
            MaterialAndEntityConverter translator = new MaterialAndEntityConverter();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                try
                {
                    OpeningTemplateEntity converted = translator.OpeningTemplateToEntity(entity);
                    context.OpeningTemplates.Add(converted);
                    context.SaveChanges();
                }
                catch (DbUpdateException)
                {
                    throw new TemplateAlreadyExistsException();
                }
            }
        }
        private Template TrySelectFirstOrDefault(Expression <Func <OpeningTemplateEntity, bool> > aCondition)
        {
            Template firstToComply;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                MaterialAndEntityConverter translator  = new MaterialAndEntityConverter();
                OpeningTemplateEntity      firstRecord = context.OpeningTemplates.FirstOrDefault(aCondition);

                if (firstRecord == null)
                {
                    throw new TemplateDoesNotExistException();
                }
                else
                {
                    firstToComply = translator.EntityToOpeningTemplate(firstRecord);
                }
            }

            return(firstToComply);
        }