public async Task <Tuple <string, IList <Genericattribute> > > CreateAttributeBulk(IList <AttributeBulk> attributesCreates) { StringBuilder logger = new StringBuilder(); Check.Require(attributesCreates != null, "attributesCreates must be supplied."); var utcNow = DateTime.UtcNow; var lstTuple = new List <Tuple <Genericattributetype, Genericattributevalue> >(); var attributeTypeRepositoryLocal = (ILedgerLocalDbFullDomainRepository <Genericattributetype>)ServiceLocatorSingleton.Instance.ServiceProvider.GetService(typeof(ILedgerLocalDbFullDomainRepository <Genericattributetype>)); var maxGaType = attributeTypeRepositoryLocal.DbSet.Max(x => x.Genericattributetypeid); var attributeValueRepositoryLocal = (ILedgerLocalDbFullDomainRepository <Genericattributevalue>)ServiceLocatorSingleton.Instance.ServiceProvider.GetService(typeof(ILedgerLocalDbFullDomainRepository <Genericattributevalue>)); var maxGaValue = attributeValueRepositoryLocal.DbSet.Max(x => x.Genericattributevalueid); foreach (var a1 in attributesCreates) { maxGaType = maxGaType + 1; maxGaValue = maxGaValue + 1; var t1 = CreateBulkTupleTypeValue(a1); t1.Item1.Genericattributetypeid = maxGaType; t1.Item2.Genericattributevalueid = maxGaValue; lstTuple.Add(t1); } var tuple1 = new List <Tuple <string, string> >(); tuple1.Add(new Tuple <string, string>("GenericAttributeTypeId", "GenericAttributeTypeId")); tuple1.Add(new Tuple <string, string>("CategoryId", "CategoryID")); tuple1.Add(new Tuple <string, string>("Name", "Name")); tuple1.Add(new Tuple <string, string>("Sort", "Sort")); tuple1.Add(new Tuple <string, string>("MetaTypeString", "MetaTypeString")); tuple1.Add(new Tuple <string, string>("MetaTypeLabel", "MetaTypeLabel")); tuple1.Add(new Tuple <string, string>("ValueString", "ValueString")); tuple1.Add(new Tuple <string, string>("ValueNumber", "ValueNumber")); tuple1.Add(new Tuple <string, string>("ValueBool", "ValueBool")); tuple1.Add(new Tuple <string, string>("ValueDate", "ValueDate")); tuple1.Add(new Tuple <string, string>("ValueLabelString", "ValueLabelString")); tuple1.Add(new Tuple <string, string>("ValueLabelNumber", "ValueLabelNumber")); tuple1.Add(new Tuple <string, string>("ValueLabelBool", "ValueLabelBool")); tuple1.Add(new Tuple <string, string>("ValueLabelDate", "ValueLabelDate")); tuple1.Add(new Tuple <string, string>("CreatedOn", "CreatedOn")); tuple1.Add(new Tuple <string, string>("ModifiedOn", "ModifiedOn")); tuple1.Add(new Tuple <string, string>("CreatedBy", "CreatedBy")); tuple1.Add(new Tuple <string, string>("ModifiedBy", "ModifiedBy")); var lstTypes = lstTuple.Select(x => x.Item1).ToList(); var LedgerLocalBulkOperatorLocal1 = (ILedgerLocalBulkOperator)ServiceLocatorSingleton.Instance.ServiceProvider.GetService(typeof(ILedgerLocalBulkOperator)); await LedgerLocalBulkOperatorLocal1.BulkInsertBulkCopy <Genericattributetype>(lstTypes, tuple1, "[System].[Genericattributetype]", 1000); logger.AppendLine(string.Format("Genericattributetype Bulked: {0} rows", lstTypes.Count)); var tuple2 = new List <Tuple <string, string> >(); tuple2.Add(new Tuple <string, string>("GenericAttributeValueId", "GenericAttributeValueId")); tuple2.Add(new Tuple <string, string>("Name", "Name")); tuple2.Add(new Tuple <string, string>("Label", "Label")); tuple2.Add(new Tuple <string, string>("Sort", "Sort")); tuple2.Add(new Tuple <string, string>("MetaTypeString", "MetaTypeString")); tuple2.Add(new Tuple <string, string>("MetaTypeLabel", "MetaTypeLabel")); tuple2.Add(new Tuple <string, string>("ValueString", "ValueString")); tuple2.Add(new Tuple <string, string>("ValueNumber", "ValueNumber")); tuple2.Add(new Tuple <string, string>("ValueBool", "ValueBool")); tuple2.Add(new Tuple <string, string>("ValueDate", "ValueDate")); tuple2.Add(new Tuple <string, string>("ValueLabelString", "ValueLabelString")); tuple2.Add(new Tuple <string, string>("ValueLabelNumber", "ValueLabelNumber")); tuple2.Add(new Tuple <string, string>("ValueLabelBool", "ValueLabelBool")); tuple2.Add(new Tuple <string, string>("ValueLabelDate", "ValueLabelDate")); tuple2.Add(new Tuple <string, string>("CreatedOn", "CreatedOn")); tuple2.Add(new Tuple <string, string>("ModifiedOn", "ModifiedOn")); tuple2.Add(new Tuple <string, string>("CreatedBy", "CreatedBy")); tuple2.Add(new Tuple <string, string>("ModifiedBy", "ModifiedBy")); var lstValues = lstTuple.Select(x => x.Item2).ToList(); var LedgerLocalBulkOperatorLocal2 = (ILedgerLocalBulkOperator)ServiceLocatorSingleton.Instance.ServiceProvider.GetService(typeof(ILedgerLocalBulkOperator)); await LedgerLocalBulkOperatorLocal2.BulkInsertBulkCopy <Genericattributevalue>(lstValues, tuple2, "[System].[Genericattributevalue]", 1000); logger.AppendLine(string.Format("Genericattributevalue Bulked: {0} rows", lstValues.Count)); var lstAttributes = new List <Genericattribute>(); var ix1 = 0; var attributeRepositoryLocal = (ILedgerLocalDbFullDomainRepository <Genericattribute>)ServiceLocatorSingleton.Instance.ServiceProvider.GetService(typeof(ILedgerLocalDbFullDomainRepository <Genericattribute>)); var maxGAttribute = attributeRepositoryLocal.DbSet.Max(x => x.Genericattributeid); foreach (var t1 in lstTuple) { maxGAttribute = maxGAttribute + 1; var attribute = new Genericattribute(); attribute.Genericattributeid = maxGAttribute; attribute.Genericattributetypeid = t1.Item1.Genericattributetypeid; attribute.Genericattributevalueid = t1.Item2.Genericattributevalueid; attribute.Typestring = attributesCreates[ix1].Type; attribute.Valuestring = attributesCreates[ix1].Value; attribute.Createdon = utcNow; attribute.Modifiedon = utcNow; attribute.Createdby = "System"; attribute.Modifiedby = "System"; JsonSerializerSettings settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, }; settings.Converters.Insert(0, new PrimitiveJsonConverter()); if (attributesCreates[ix1].TypeObject != null) { attribute.Typelabelstring = JsonConvert.SerializeObject(attributesCreates[ix1].TypeObject, settings); } else { attribute.Typelabelstring = EncodeLabel(attributesCreates[ix1].Type); } if (attributesCreates[ix1].ValueObject != null) { attribute.Valuelabelstring = JsonConvert.SerializeObject(attributesCreates[ix1].ValueObject, settings); } else { attribute.Valuelabelstring = EncodeLabel(attributesCreates[ix1].Value); } lstAttributes.Add(attribute); ix1 = ix1 + 1; } var tuple3 = new List <Tuple <string, string> >(); tuple3.Add(new Tuple <string, string>("GenericAttributeId", "GenericAttributeId")); tuple3.Add(new Tuple <string, string>("GenericAttributeTypeId", "GenericAttributeTypeId")); tuple3.Add(new Tuple <string, string>("GenericAttributeValueId", "GenericAttributeValueId")); tuple3.Add(new Tuple <string, string>("TypeString", "TypeString")); tuple3.Add(new Tuple <string, string>("TypeLabelString", "TypeLabelString")); tuple3.Add(new Tuple <string, string>("ValueString", "ValueString")); tuple3.Add(new Tuple <string, string>("ValueLabelString", "ValueLabelString")); tuple3.Add(new Tuple <string, string>("CreatedOn", "CreatedOn")); tuple3.Add(new Tuple <string, string>("ModifiedOn", "ModifiedOn")); tuple3.Add(new Tuple <string, string>("CreatedBy", "CreatedBy")); tuple3.Add(new Tuple <string, string>("ModifiedBy", "ModifiedBy")); var LedgerLocalBulkOperatorLocal3 = (ILedgerLocalBulkOperator)ServiceLocatorSingleton.Instance.ServiceProvider.GetService(typeof(ILedgerLocalBulkOperator)); await LedgerLocalBulkOperatorLocal3.BulkInsertBulkCopy <Genericattribute>(lstAttributes, tuple3, "[System].[Genericattribute]", 1000); logger.AppendLine(string.Format("Genericattribute Bulked: {0} rows", lstAttributes.Count)); return(new Tuple <string, IList <Genericattribute> >(logger.ToString(), lstAttributes)); }
public async Task <Genericattribute> CreateOrGetAttribute( string type, string value, object typeObject = null, object valueObject = null, int typeSort = 0, int valueSort = 0, int?categoryId = null) { Check.Require(!string.IsNullOrWhiteSpace(type), "type must be supplied."); Check.Require(!string.IsNullOrWhiteSpace(value), "value must be supplied."); var utcNow = DateTime.UtcNow; var tupleTypeValue = await CreateOrGetTupleTypeValue(type, value, typeObject, valueObject, typeSort, valueSort, categoryId); var findAttribute = _attributeRepository.DbSet.FirstOrDefault(x => x.Genericattributetypeid == tupleTypeValue.Item1.Genericattributetypeid && x.Genericattributevalueid == tupleTypeValue.Item2.Genericattributevalueid); if (findAttribute != null) { return(findAttribute); } var attribute = new Genericattribute(); attribute.Genericattributetypeid = tupleTypeValue.Item1.Genericattributetypeid; attribute.Genericattributevalueid = tupleTypeValue.Item2.Genericattributevalueid; attribute.Typestring = type; attribute.Valuestring = value; attribute.Createdon = utcNow; attribute.Modifiedon = utcNow; attribute.Createdby = "System"; attribute.Modifiedby = "System"; JsonSerializerSettings settings = new JsonSerializerSettings() { TypeNameHandling = TypeNameHandling.All, }; settings.Converters.Insert(0, new PrimitiveJsonConverter()); if (typeObject != null) { attribute.Typelabelstring = JsonConvert.SerializeObject(typeObject, settings); } else { attribute.Typelabelstring = EncodeLabel(type); } if (valueObject != null) { attribute.Valuelabelstring = JsonConvert.SerializeObject(valueObject, settings); } else { attribute.Valuelabelstring = EncodeLabel(value); } await _attributeRepository.AddAsync(attribute); var error1 = _unitOfWork.CommitHandled(); if (!error1) { _logger.LogError($"Can't Attribute ! {JsonConvert.SerializeObject(attribute, Formatting.Indented, new JsonSerializerSettings { ReferenceLoopHandling = ReferenceLoopHandling.Ignore })} "); } return(attribute); }