예제 #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();
            }
        }
예제 #2
0
 private void TryAddPrice(CostPriceEntity toSave)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         context.CostsAndPrices.Add(toSave);
         context.SaveChanges();
     }
 }
예제 #3
0
 private void TrySettingPrice(int componentType, float newPrice)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         CostPriceEntity record = context.CostsAndPrices.FirstOrDefault(cp => cp.ComponentType == componentType);
         record.Price = newPrice;
         context.SaveChanges();
     }
 }
        private bool TryAskingIfEmpty()
        {
            bool isEmpty;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                isEmpty = !context.OpeningTemplates.Any();
            }
            return(isEmpty);
        }
예제 #5
0
        private float TryGettingPrice(int componentType)
        {
            float price;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                price = context.CostsAndPrices.FirstOrDefault(cp => cp.ComponentType == componentType).Price;
            }
            return(price);
        }
        private bool TryAskingIfExists(Template record)
        {
            bool doesExist;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                doesExist = context.OpeningTemplates.Any(ote => ote.Name.Equals(record.Name));
            }
            return(doesExist);
        }
예제 #7
0
        private bool TryAskIsEmpty()
        {
            bool isEmpty;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                isEmpty = !context.Blueprints.Any();
            }
            return(isEmpty);
        }
        private bool TryAskIsEmpty()
        {
            bool isEmpty;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                isEmpty = !context.Users.Any(u => !u.UserName.Equals("admin"));
            }
            return(isEmpty);
        }
 private void TryAdd(User aUser)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         UserAndEntityConverter translator = new UserAndEntityConverter();
         UserEntity             anEntity   = translator.ToEntity(aUser);
         context.Users.Add(anEntity);
         context.SaveChanges();
     }
 }
예제 #10
0
        private float TryGettingCost(int componentType)
        {
            float cost;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                CostPriceEntity query = context.CostsAndPrices.FirstOrDefault(cp => cp.ComponentType == componentType);
                cost = query.Cost;
            }
            return(cost);
        }
예제 #11
0
 private void TryDeletingBlueprintsOfUser(User aUser)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         foreach (BlueprintEntity bpEnt in context.Blueprints.Where(bp => bp.Owner.UserName.Equals(aUser.UserName)))
         {
             context.Blueprints.Remove(bpEnt);
         }
         context.SaveChanges();
     }
 }
        private bool TryAskIfExists(string aUserName)
        {
            bool doesExist;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                doesExist = context.Users.Any(u => u.UserName.Equals(aUserName));
            }

            return(doesExist);
        }
 private void TryClearing()
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         foreach (OpeningTemplateEntity template in context.OpeningTemplates)
         {
             context.OpeningTemplates.Remove(template);
         }
         context.SaveChanges();
     }
 }
예제 #14
0
 private void TryToClear()
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         foreach (CostPriceEntity record in context.CostsAndPrices)
         {
             context.CostsAndPrices.Remove(record);
         }
         context.SaveChanges();
     }
 }
        private void TryModify(User modified)
        {
            UserAndEntityConverter translator = new UserAndEntityConverter();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                UserEntity record = translator.ToEntity(modified);
                context.Users.Attach(record);
                context.Entry(record).State = EntityState.Modified;
                context.SaveChanges();
            }
        }
 private void TryDeleting(Template toDelete)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         OpeningTemplateEntity entity = context.OpeningTemplates.FirstOrDefault(ote => ote.Name.Equals(toDelete.Name));
         if (entity != null)
         {
             context.OpeningTemplates.Remove(entity);
             context.SaveChanges();
         }
     }
 }
예제 #17
0
        private IBlueprint TryGetting(Guid id)
        {
            IBlueprint queried;

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                BlueprintEntity record = context.Blueprints.Include(bp => bp.Owner).FirstOrDefault(bp => bp.Id.Equals(id));

                queried = BuildBlueprint(record);
            }
            return(queried);
        }
 private void TryDelete(User toDelete)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         UserEntity entity = context.Users.FirstOrDefault(r => r.UserName.Equals(toDelete.UserName));
         //if it exists, delete it.
         if (entity != null)
         {
             context.Users.Remove(entity);
             context.SaveChanges();
         }
     }
 }
예제 #19
0
        private ICollection <IBlueprint> TryGetAll()
        {
            ICollection <IBlueprint> converted = new List <IBlueprint>();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                foreach (BlueprintEntity be in context.Blueprints.Include(b => b.Owner))
                {
                    converted.Add(BuildBlueprint(be));
                }
            }
            return(converted);
        }
예제 #20
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);
        }
        private ICollection <Signature> GetBlueprintSignatures(BlueprintEntity toConvert)
        {
            ICollection <Signature> signatures = new List <Signature>();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext()) {
                IEnumerable <SignatureEntity> queriedSignatures = context.Signatures.Where(se => se.BlueprintSigned.Id == toConvert.Id);
                foreach (SignatureEntity se in queriedSignatures)
                {
                    signatures.Add(EntityToSignature(se));
                }
            }
            return(signatures);
        }
예제 #22
0
 private void TryToClear()
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         foreach (SignatureEntity se in context.Signatures)
         {
             context.Signatures.Remove(se);
         }
         foreach (BlueprintEntity bpe in context.Blueprints)
         {
             context.Blueprints.Remove(bpe);
         }
         context.SaveChanges();
     }
 }
        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 <User> TryFilter(Expression <Func <UserEntity, bool> > aCriteria)
        {
            ICollection <User> elegibleUsers = new List <User>();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                UserAndEntityConverter  translator      = new UserAndEntityConverter();
                IQueryable <UserEntity> elegibleRecords = context.Users.Where(aCriteria);
                foreach (UserEntity record in elegibleRecords)
                {
                    elegibleUsers.Add(translator.ToUser(record));
                }
            }

            return(elegibleUsers);
        }
예제 #25
0
        private ICollection <IBlueprint> TryGettingBlueprintsOfUser(User owner)
        {
            ICollection <IBlueprint> queriedBlueprints = new List <IBlueprint>();

            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                ICollection <BlueprintEntity> query = context.Blueprints.Include(bp => bp.Owner)
                                                      .Where(bp => bp.Owner.UserName.Equals(owner.UserName)).ToList();

                foreach (BlueprintEntity bpe in query)
                {
                    queriedBlueprints.Add(BuildBlueprint(bpe));
                }
            }
            return(queriedBlueprints);
        }
예제 #26
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();
                }
            }
        }
        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);
        }
예제 #28
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);
        }
        private void TryClearUsers()
        {
            using (BlueBuilderDBContext context = new BlueBuilderDBContext())
            {
                foreach (UserEntity userEnt in context.Users)
                {
                    context.Users.Remove(userEnt);
                }
                AdminEntity putBackAdmin = new AdminEntity()
                {
                    Name = "admin", Surname = "admin", UserName = "******", Password = "******"
                };

                context.Users.Add(putBackAdmin);
                context.SaveChanges();
            }
        }
        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();
                }
            }
        }