Example #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();
            }
        }
Example #2
0
 private void TryAddPrice(CostPriceEntity toSave)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         context.CostsAndPrices.Add(toSave);
         context.SaveChanges();
     }
 }
Example #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 void TryAdd(User aUser)
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         UserAndEntityConverter translator = new UserAndEntityConverter();
         UserEntity             anEntity   = translator.ToEntity(aUser);
         context.Users.Add(anEntity);
         context.SaveChanges();
     }
 }
Example #5
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();
     }
 }
Example #6
0
 private void TryToClear()
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         foreach (CostPriceEntity record in context.CostsAndPrices)
         {
             context.CostsAndPrices.Remove(record);
         }
         context.SaveChanges();
     }
 }
 private void TryClearing()
 {
     using (BlueBuilderDBContext context = new BlueBuilderDBContext())
     {
         foreach (OpeningTemplateEntity template in context.OpeningTemplates)
         {
             context.OpeningTemplates.Remove(template);
         }
         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();
         }
     }
 }
 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();
         }
     }
 }
Example #11
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();
            }
        }
Example #13
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 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();
                }
            }
        }