public BusinessEntityType Create(BusinessEntityType businessEntityType) { if (businessEntityType != null) { _context.BusinessEntityTypes.Add(businessEntityType); _context.SaveChanges(); } return(_context.BusinessEntityTypes.Find(businessEntityType.Id)); }
/// <summary> /// Add /// </summary> /// <param name="name"></param> /// <returns></returns> public static bool Add(string name, BusinessEntity parent, BusinessEntityType type) { lock (BusinessEntity.m_sDS) { bool success = false; if (parent != null) { // Ensure that the parent and the child does not have the same name... success = !parent.Name.Equals(name, StringComparison.OrdinalIgnoreCase); // Ensure none of the sibiings has the same name already... success = success && !parent.Children.Exists(d => d.Name.Equals(name, StringComparison.OrdinalIgnoreCase)); } else if (type == BusinessEntityType.Company && parent == null) { // Ensure that companies at the root with the same does not exist... success = All.Where(s => s.Parent == null).Count(f => f.Name.Equals(name, StringComparison.OrdinalIgnoreCase)) == 0; } if (success) { success = false; // Reset var dataRow = m_sDS.BusinessEntities.AddBusinessEntitiesRow(name, (parent == null) ? null : parent.m_dataRow, (byte)type); try { success = m_sTA.Update(dataRow) == 1; } catch { } if (!success) { m_sDS.BusinessEntities.RemoveBusinessEntitiesRow(dataRow); } else { m_sBusinessEntities.Add(new BusinessEntity(dataRow)); } } return(success); } }