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 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 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(); } }