Пример #1
0
        private Entity CreateEntityFromObject(TEntityData item)
        {
            Entity entity = SchemaInstance.CreateEntity(UserConnection);

            FillEntityFromObject(entity, item);
            return(entity);
        }
Пример #2
0
        /// <summary>
        /// Used to create related to Product Id and PriceList Id ProductPrice entity.
        /// </summary>
        /// <param name="basePriceListId">PriceList Id.</param>
        /// <param name="productId">Product Id.</param>
        /// <returns>ProductPrice entity.</returns>
        protected virtual Entity GetNewBaseProductPriceEntity(Guid basePriceListId, Guid productId)
        {
            Entity baseProductPrice = _productPriceSchema.CreateEntity(_userConnection);

            baseProductPrice.SetDefColumnValues();
            baseProductPrice.SetColumnValue("Id", Guid.NewGuid());
            baseProductPrice.SetColumnValue("PriceListId", basePriceListId);
            baseProductPrice.SetColumnValue("ProductId", productId);
            return(baseProductPrice);
        }
 private static void ProcessSheetColumns(
     UserConnection userConnection, EntitySchema columnSchema, IEnumerable <ForecastColumn> columns)
 {
     foreach (ForecastColumn column in columns)
     {
         if (!IsFormulaColumn(column))
         {
             continue;
         }
         FormulaSetting settings = column.GetColumnSettings <FormulaSetting>();
         if (!ShouldMigrateColumn(settings))
         {
             continue;
         }
         var sumFormulaItems = settings.UseInSummary
                                 ? BuildSumAllFormula(settings)
                                 : BuildSUMSelfFormula(column);
         settings.SummaryValue = sumFormulaItems;
         var newSettingsJson = JsonConvert.SerializeObject(settings);
         var entity          = columnSchema.CreateEntity(userConnection);
         entity.FetchFromDB(column.Id);
         entity.SetColumnValue("Settings", newSettingsJson);
         entity.Save(false);
     }
 }
Пример #4
0
        public virtual void SetDefaultSysMsgUserSettings()
        {
            var          entitySchemaManager      = UserConnection.GetSchemaManager("EntitySchemaManager") as EntitySchemaManager;
            EntitySchema wSysAccountSchema        = entitySchemaManager.GetInstanceByName("WSysAccount");
            Entity       wSysAccountEntity        = wSysAccountSchema.CreateEntity(UserConnection);
            EntitySchema sysMsgUserSettingsSchema = entitySchemaManager.GetInstanceByName("SysMsgUserSettings");
            Entity       sysMsgUserSettingsEntity = sysMsgUserSettingsSchema.CreateEntity(UserConnection);

            sysMsgUserSettingsEntity.SetDefColumnValues();
            sysMsgUserSettingsEntity.SetColumnValue("UserId", Entity.PrimaryColumnValue);
            sysMsgUserSettingsEntity.SetColumnValue("SysMsgLibId", WebitelSymMsgLibId);
            Dictionary <string, object> connectionParamsDictionary = new Dictionary <string, object>()
            {
                { "isWrapUpDisabled", false },
                { "debugMode", false },
                { "disableCallCentre", false },
                { "isAutoLogin", true },
                { "useWebitelCti", false },
                { "useWebPhone", true },
                { "useVideo", false }
            };
            string connectionParams = ServiceStackTextHelper.Serialize(connectionParamsDictionary);

            sysMsgUserSettingsEntity.SetColumnValue("ConnectionParams", connectionParams);
            sysMsgUserSettingsEntity.Save();
        }
Пример #5
0
        private bool TryGetActivityEntity(Guid activityId, out Entity activityEntity)
        {
            EntitySchema activitySchema = UserConnection.EntitySchemaManager.FindInstanceByName(ActivitySchemaName);

            activityEntity = activitySchema.CreateEntity(UserConnection);
            return(activityEntity.FetchFromDB(activityId));
        }
Пример #6
0
        /// <summary>
        /// Apply data to database based on EntitySchema name, KeyColumn name and Column mapping.
        /// Base implementation sorts out data set, map columns with column mapping and set
        /// columns on entity.
        /// </summary>
        /// <param name="entitySchemaName">Entity schema name, for which data applied.</param>
        /// <param name="keyColumnName">Key column of entity.</param>
        /// <param name="columnMapping">Columns mapping for DataSet.</param>
        /// <param name="dataSet">DataSet which applied.</param>
        public virtual void ApplyData(
            string entitySchemaName,
            string keyColumnName,
            Dictionary <string, string> columnMapping,
            IEnumerable <Dictionary <string, object> > dataSet)
        {
            EntitySchema schema = _userConnection.EntitySchemaManager.GetInstanceByName(entitySchemaName);
            Entity       entity = schema.CreateEntity(_userConnection);

            try {
                var mappedKeyColumnName = columnMapping[keyColumnName];
                using (var dataSetEnumerator = dataSet.GetEnumerator()) {
                    while (dataSetEnumerator.MoveNext())
                    {
                        var currentRow = dataSetEnumerator.Current;
                        if (entity.FetchFromDB(currentRow[mappedKeyColumnName]))
                        {
                            SetMappedColumns(currentRow, keyColumnName, columnMapping, entity);
                            entity.Save();
                        }
                    }
                }
            }
            catch (KeyNotFoundException) {
                throw new KeyNotFoundException("Column not found in columnMapping dictionary");
            }
        }
Пример #7
0
        /// <summary>
        /// Get template from db.
        /// </summary>
        /// <param name="conditions">Conditions.</param>
        /// <returns>Template entity.</returns>
        private Entity GetTemplateFromDb(Dictionary <string, object> conditions)
        {
            EntitySchema schema   = UserConnection.EntitySchemaManager.FindInstanceByName(SchemaName);
            Entity       template = schema.CreateEntity(UserConnection);

            return(template.FetchFromDB(conditions) ? template : null);
        }
        protected virtual Entity GetDestinationEntity(EntitySchema destinationSchema)
        {
            var entity = destinationSchema.CreateEntity(UserConnection);

            entity.SetDefColumnValues();
            return(entity);
        }
Пример #9
0
        protected virtual Entity GetEntity(Guid entityId, EntitySchema schema = null)
        {
            schema = schema ?? _rootSchema;
            var linkedEntity = schema.CreateEntity(_userConnection);

            return(linkedEntity.FetchFromDB(entityId) ? linkedEntity : null);
        }
Пример #10
0
        /// <summary>
        /// Removes operations.
        /// Returns a string that is a JSON object representing execution result.
        /// </summary>
        /// <param name="recordIds">Array of operations identity</param>
        /// <returns>JSON-format string.
        /// Includes serialized object whith fields:
        /// Success - the method is successfully executed.,
        /// ExMessage - string with error, if Success = false </returns>
        public string DeleteAdminOperation(Guid[] recordIds)
        {
            bool   success   = false;
            string exMessage = string.Empty;

            try {
                DBSecurityEngine engine = _userConnection.DBSecurityEngine;
                engine.CheckCanChangeAdminOperationGrantee();
                EntitySchema adminOperationTableSchema = _userConnection.EntitySchemaManager.GetInstanceByName("SysAdminOperation");
                Entity       adminOperationEntity      = adminOperationTableSchema.CreateEntity(_userConnection);
                foreach (var recordId in recordIds)
                {
                    if (adminOperationEntity.FetchFromDB("Id", recordId))
                    {
                        adminOperationEntity.Delete();
                    }
                }
                success = true;
            }
            catch (Exception ex) {
                if (ex is SecurityException)
                {
                    exMessage = ex.Message;
                }
                else
                {
                    exMessage = new LocalizableString(_userConnection.ResourceStorage, "RightsHelper",
                                                      "LocalizableStrings.NonSecurityExeption.Value");
                }
            }
            return(JsonConvert.SerializeObject(new {
                Success = success,
                ExMessage = exMessage
            }));
        }
        /// <summary>
        /// Returns mailbox synchronization setting for the specific sender email address.
        /// </summary>
        /// <param name="senderEmailAddress">Sender email address.</param>
        /// <returns><see cref="Terrasoft.Core.Entities.Entity"/> instance of <see cref="MailboxSyncSettings"/> entity type.</returns>
        protected virtual Entity GetMailboxSynSettingEntity(string senderEmailAddress)
        {
            EntitySchema entitySchema = _schemaManager.GetInstanceByName("MailboxSyncSettings");
            Entity       mailbox      = entitySchema.CreateEntity(UserConnection);

            return(mailbox.FetchFromDB("SenderEmailAddress", senderEmailAddress, false) ? mailbox : null);
        }
Пример #12
0
        /// <summary>
        /// Inserts days in calendar.
        /// </summary>
        /// <param name="calendarId">Calendar identifier.</param>
        /// <param name="weekTemplate">Days in calendar.</param>
        /// <returns>Success of operation.</returns>
        protected virtual bool InsertDaysInCalendar(Guid calendarId, IEnumerable <ICalendarDay> weekTemplate)
        {
            if (weekTemplate.IsNullOrEmpty())
            {
                return(true);
            }
            bool         result = false;
            EntitySchema schema = _userConnection.EntitySchemaManager.FindInstanceByName("DayInCalendar");

            foreach (ICalendarDay day in weekTemplate)
            {
                Guid   dayOfWeekId = GetDayOfWeekId(day.DayOfWeek);
                Entity entity      = schema.CreateEntity(_userConnection);
                entity.SetColumnValue("DayTypeId", day.DayTypeUId);
                entity.SetColumnValue("DayOfWeekId", dayOfWeekId);
                entity.SetColumnValue("CalendarId", calendarId);
                result = entity.Save(validateRequired: false);
                if (!result)
                {
                    return(false);
                }
                result = InsertWorkingTimeIntervals("DayInCalendarId", entity.PrimaryColumnValue, day.WorkingIntervals);
            }
            return(result);
        }
Пример #13
0
        private Entity GetCalendarEntity()
        {
            EntitySchema schema = _userConnection.EntitySchemaManager.FindInstanceByName("Calendar");
            Entity       entity = schema.CreateEntity(_userConnection);

            return(entity);
        }
Пример #14
0
        public virtual bool ChangeApprovalWithLocationException(string entityName, Guid id,
                                                                Dictionary <string, object> additionalColumnValues)
        {
            EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName(entityName);
            Entity       entity       = entitySchema.CreateEntity(UserConnection);

            if (!entity.FetchFromDB(id))
            {
                throw new VisaNotFoundException();
            }
            if (IsFinalStatus(entity))
            {
                throw new VisaFinalStatusException();
            }
            entity.SetColumnValue("SetDate", DateTime.UtcNow);
            entity.SetColumnValue("SetById", UserConnection.CurrentUser.ContactId);
            if (additionalColumnValues != null)
            {
                foreach (var item in additionalColumnValues)
                {
                    entity.SetColumnValue(item.Key, item.Value);
                }
            }
            if (!entity.Save())
            {
                throw new SaveVisaChangesException();
            }
            return(true);
        }
Пример #15
0
        /// <summary>
        /// Used to retrieve the Product entity by Id.
        /// </summary>
        /// <param name="productId">Product Id.</param>
        /// <returns>Product entity if it exists.</returns>
        protected virtual Entity GetProductEntity(Guid productId)
        {
            Entity product   = _productSchema.CreateEntity(_userConnection);
            bool   isFetched = product.FetchFromDB(productId);

            return(isFetched ? product : null);
        }
        private void CreateReminding(ImportParameters parameters)
        {
            Guid     contactId            = parameters.AuthorId;
            DateTime dateTime             = TimeZoneInfo.ConvertTimeFromUtc(new DateTimeProvider().UtcNow, parameters.AuthorTimeZone);
            uint     notImportedRowsCount = parameters.NotImportedRowsCount;
            string   description          = string.Format(CompleteRemindingDescriptionTemplate, parameters.ImportedRowsCount,
                                                          parameters.TotalRowsCount, parameters.FileName);

            if (notImportedRowsCount > 0)
            {
                description += string.Format(NotImportedRowsCountMessageTemplate, notImportedRowsCount);
            }
            string caption = string.Format("{0} {1}", CompleteRemindingSubject, description);
            ISchemaManagerItem <EntitySchema> importSessionItem =
                UserConnection.EntitySchemaManager.GetItemByName("ImportSession");
            ISchemaManagerItem <EntitySchema> sysProcessLogItem =
                UserConnection.EntitySchemaManager.GetItemByName("VwSysProcessLog");

            EntitySchema remindingSchema = UserConnection.EntitySchemaManager.GetInstanceByName("Reminding");
            Entity       reminding       = remindingSchema.CreateEntity(UserConnection);

            reminding.SetDefColumnValues();
            reminding.SetColumnValue("AuthorId", contactId);
            reminding.SetColumnValue("ContactId", contactId);
            reminding.SetColumnValue("SourceId", RemindingConsts.RemindingSourceAuthorId);
            reminding.SetColumnValue("RemindTime", dateTime);
            reminding.SetColumnValue("Description", description);
            reminding.SetColumnValue("SubjectId", parameters.ImportSessionId);
            reminding.SetColumnValue("SysEntitySchemaId", sysProcessLogItem.UId);
            reminding.SetColumnValue("SubjectCaption", caption);
            reminding.SetColumnValue("LoaderId", importSessionItem.UId);
            reminding.Save();
        }
Пример #17
0
        private string GetWebPageForRemoteItem(LocalItem localItem, UserConnection userConnection, Guid contactId)
        {
            string result = string.Empty;
            IEnumerable <SyncEntity> webPageEntities = localItem.Entities["ContactCommunication"].Where(e =>
                                                                                                        e.State != SyncState.New && e.State != SyncState.Deleted &&
                                                                                                        e.Entity.GetTypedColumnValue <Guid>("CommunicationTypeId") ==
                                                                                                        Guid.Parse(CommunicationTypeConsts.WebId));

            if (webPageEntities.Any())
            {
                SyncEntity webPageSyncEntity = webPageEntities.First();
                result = webPageSyncEntity.Entity.GetTypedColumnValue <string>("Number");
            }
            else
            {
                Guid id = TryFindWebPageDetailInLocalStore(userConnection, contactId);
                if (id == Guid.Empty)
                {
                    return(result);
                }
                EntitySchema schema   = userConnection.EntitySchemaManager.GetInstanceByName("ContactCommunication");
                var          instance = (ContactCommunication)schema.CreateEntity(userConnection);
                if (instance.FetchFromDB(id, false))
                {
                    localItem.AddOrReplace(schema.Name, SyncEntity.CreateNew(instance));
                    result = instance.Number;
                }
            }
            return(result);
        }
Пример #18
0
        /// <summary>
        /// ######### ###### ################# # ##### "############" #, ####
        /// ### ##### ############, ######### ### # ######### ####.
        /// </summary>
        /// <param name="roleId">####, # ####### ##### ######## ##### ############.</param>
        protected void SaveUser(object roleId)
        {
            bool   isNew = false;
            object primaryColumnValue;

            changedValues.TryGetValue("Id", out primaryColumnValue);
            EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByName("VwSysAdminUnit");
            Entity       entity       = entitySchema.CreateEntity(UserConnection);

            isNew = !entity.FetchFromDB(primaryColumnValue);
            if (isNew)
            {
                entity.SetDefColumnValues();
            }
            foreach (KeyValuePair <string, object> item in changedValues)
            {
                EntitySchemaColumn column      = entitySchema.Columns.GetByName(item.Key);
                object             columnValue = item.Value;
                if ((column.DataValueType is DateTimeDataValueType) && (item.Value != null))
                {
                    columnValue = DataTypeUtilities.ValueAsType <DateTime>(item.Value);
                }
                entity.SetColumnValue(column.ColumnValueName, columnValue);
            }
            entity.Save();
            if (isNew)
            {
                AddUserInRole(entity.PrimaryColumnValue, roleId);
            }
        }
        /// <summary>
        /// Returns <see cref="SyncErrorMessage"/> instance.
        /// </summary>
        /// <param name="messageId"><see cref="SyncErrorMessage"/> instance identifier.</param>
        /// <returns><see cref="SyncErrorMessage"/> instance.</returns>
        protected Entity GetSyncErrorMessage(Guid messageId)
        {
            EntitySchema entitySchema = _schemaManager.GetInstanceByName("SyncErrorMessage");
            Entity       mailbox      = entitySchema.CreateEntity(UserConnection);

            return(mailbox.FetchFromDB(messageId) ? mailbox : null);
        }
Пример #20
0
 /// <summary>
 /// <see cref="ExchangeSyncProvider.OnLocalItemAppliedInRemoteStore"/>
 /// </summary>
 public override void OnLocalItemAppliedInRemoteStore(SyncContext context, IRemoteItem remoteItem,
                                                      LocalItem localItem)
 {
     if (!_userConnection.GetIsFeatureEnabled("SyncDeletedAppointments"))
     {
         return;
     }
     if (remoteItem.Action == SyncAction.Delete && remoteItem.State == SyncState.Deleted)
     {
         EntitySchema       schema    = context.UserConnection.EntitySchemaManager.GetInstanceByName("Activity");
         IEnumerable <Guid> entityIds = localItem.Entities["Activity"]
                                        .Where(se => se.State != SyncState.Deleted).Select(se => se.EntityId).ToList();
         foreach (Guid activityId in entityIds)
         {
             Entity activity = schema.CreateEntity(context.UserConnection);
             if (activity.FetchFromDB(activityId, false))
             {
                 localItem.AddOrReplace("Activity", new SyncEntity(activity, SyncState.Modified)
                 {
                     Action = SyncAction.Delete
                 });
             }
         }
         context.LocalProvider.ApplyChanges(context, localItem);
     }
 }
Пример #21
0
        public virtual IFileUploadInfo LoadFile(Guid entitySchemaUId, Guid fileId,
                                                BinaryWriter binaryWriter)
        {
            EntitySchema entitySchema = UserConnection.EntitySchemaManager.GetInstanceByUId(entitySchemaUId);

            if (!CheckReadFileAccess(entitySchema, fileId))
            {
                Log.Info($"LoadFile: CheckReadFileAccess = false for fileId: ${fileId}");
                return(null);
            }
            Entity entity     = entitySchema.CreateEntity(UserConnection);
            Select selectData = (new Select(UserConnection)
                                 .Column("Name")
                                 .Column(Func.DataLength("Data")).As("Size")
                                 .Column("Data")
                                 .From(entity.SchemaName)
                                 .Where("Id")
                                 .IsEqual(Column.Parameter(fileId))) as Select;

            selectData.SpecifyNoLockHints();
            using (DBExecutor executor = UserConnection.EnsureDBConnection()) {
                using (IDataReader reader = selectData.ExecuteReader(executor, CommandBehavior.SequentialAccess)) {
                    if (reader.Read())
                    {
                        string fileName        = reader["Name"].ToString();
                        int    sizeColumnIndex = reader.GetOrdinal("Size");
                        object sizeValue       = reader[sizeColumnIndex];
                        if (DBNull.Value.Equals(sizeValue))
                        {
                            Log.Info($"LoadFile: file size is null for fileId: ${fileId}");
                            return(null);
                        }
                        int    size         = UserConnection.DBTypeConverter.DBValueToInt(sizeValue);
                        long   offset       = 0;
                        int    bufferOffset = 0;
                        int    chunkSize    = 524288;
                        byte[] buffer       = new byte[chunkSize];
                        long   realBytes    = 0;
                        while (offset < size)
                        {
                            Array.Clear(buffer, 0, buffer.Length);
                            realBytes = reader.GetBytes(2, offset, buffer, bufferOffset, chunkSize);
                            if (realBytes <= 0)
                            {
                                break;
                            }
                            offset += realBytes;
                            binaryWriter.Write(buffer, 0, Convert.ToInt32(realBytes));
                            binaryWriter.Flush();
                        }
                        var feui = new FileEntityUploadInfo(entitySchema.Name, fileId, fileName);
                        feui.TotalFileLength = size;
                        return(feui);
                    }
                }
            }
            Log.Info($"LoadFile: file not found with Id: ${fileId}");
            return(null);
        }
        /// <summary>
        /// Initialize new instance of <see cref="EmailTemplateLanguageHelper" />.
        /// </summary>
        /// <param name="caseId">Case record identifier.</param>
        /// <param name="userConnection">User connection.</param>
        public EmailTemplateLanguageHelper(Guid caseId, UserConnection userConnection)
        {
            UserConnection = userConnection;
            EntitySchema caseSchema = UserConnection.EntitySchemaManager.FindInstanceByName("Case");

            CaseEntity = caseSchema.CreateEntity(UserConnection) as Case;
            CaseEntity.FetchFromDB(caseId);
        }
        protected virtual Entity GetSourceEntity(EntitySchema sourceSchema, Dictionary <string, string> validColumnmap, Guid sourceRowId)
        {
            var entity = sourceSchema.CreateEntity(UserConnection);
            IEnumerable <string> columnsToFetch = validColumnmap.Values.Distinct();

            entity.FetchFromDB(sourceSchema.GetPrimaryColumnName(), sourceRowId, columnsToFetch);
            return(entity);
        }
        /// <summary>
        /// Initialize new instance of <see cref="EmailTemplateCommLangHandler" />.
        /// </summary>
        /// <param name="caseId">Case record identifier.</param>
        /// <param name="userConnection">User connection.</param>
        protected EmailTemplateCommLangHandler(Guid caseId, UserConnection userConnection)
        {
            UserConnection = userConnection;
            EntitySchema caseSchema = UserConnection.EntitySchemaManager.FindInstanceByName("Case");

            CaseEntity = caseSchema.CreateEntity(UserConnection) as Case;
            CaseEntity.FetchFromDB(caseId);
        }
Пример #25
0
        /// <summary>
        /// Returns empty address entity.
        /// </summary>
        /// <returns>Empty address <see cref="Entity"/>.</returns>
        protected virtual Entity GetEmptyAddressEntity()
        {
            EntitySchema schema = UserConnection.EntitySchemaManager.GetInstanceByName(AddressEntity.SchemaName);
            Entity       entity = schema.CreateEntity(UserConnection);

            entity.SetDefColumnValues();
            return(entity);
        }
        /// <summary>
        /// Get entity from DB by id
        /// </summary>
        /// <param name="elementId"></param>
        /// <returns>Return entity</returns>
        private Entity GetEntity(Guid elementId)
        {
            EntitySchema schema = _userConnection.EntitySchemaManager.GetInstanceByName(_entitySchemaName);
            Entity       entity = schema.CreateEntity(_userConnection);

            entity.FetchFromDB(elementId);
            return(entity);
        }
        private Entity GetEntity()
        {
            EntitySchema schema = UserConnection.EntitySchemaManager
                                  .FindInstanceByUId(ForecastSheet.ForecastEntityInCellUId);
            Entity entity = schema.CreateEntity(UserConnection);

            return(entity);
        }
Пример #28
0
        /// <summary>
        /// Fetch <see cref="MailboxSyncSettings"/> instance by <see cref="MailboxSyncSettings.SenderEmailAddress"/> column value,
        /// filtered using <paramref name="senderEmailAddress"/>.
        /// <paramref name="settings"/> would be set with fetched instance.
        /// </summary>
        /// <param name="senderEmailAddress">Sender email address filter value.</param>
        /// <param name="userConnection"><see cref="UserConnection"/> instance.</param>
        /// <param name="settings">Fetched <see cref="MailboxSyncSettings"/> instance.</param>
        /// <returns><c>True</c> if mailbox successfully fetched from database, <c>false</c> otherwise.</returns>
        private bool FetchSettingsEntity(string senderEmailAddress, UserConnection userConnection, out Entity settings)
        {
            EntitySchema schema = userConnection.EntitySchemaManager.GetInstanceByName("MailboxSyncSettings");
            Entity       mailboxSyncSettings = schema.CreateEntity(userConnection);

            settings = mailboxSyncSettings;
            return(mailboxSyncSettings.FetchFromDB("SenderEmailAddress", senderEmailAddress));
        }
Пример #29
0
        /// <summary>
        /// Fills exchange companies to bpmonline account dictionary.
        /// </summary>
        /// <param name="context"><see cref="SyncContext"/> instance.</param>
        /// <param name="exchangeCompanies">Exchange company names.</param>
        private void FillAccountsMap(SyncContext context, List <string> exchangeCompanies)
        {
            if (exchangeCompanies == null || !exchangeCompanies.Any())
            {
                return;
            }
            if (UserSettings.LinkContactToAccountType == ExchangeConsts.NeverLinkContactToAccountId)
            {
                return;
            }
            IEnumerable <string> distinctExchangeCompanies = exchangeCompanies.Distinct();
            int index = 0;

            while (index < distinctExchangeCompanies.Count())
            {
                IEnumerable <string> paramsValue = distinctExchangeCompanies.Skip(index).Take(EsqParamsCount);
                index += EsqParamsCount;
                var accountsEsq = new EntitySchemaQuery(context.UserConnection.EntitySchemaManager, "Account");
                accountsEsq.PrimaryQueryColumn.IsAlwaysSelect = true;
                accountsEsq.AddColumn("Name");
                accountsEsq.Filters.Add(accountsEsq.CreateFilterWithParameters(FilterComparisonType.Equal, false,
                                                                               "Name", paramsValue.ToArray()));
                EntityCollection accounts = accountsEsq.GetEntityCollection(context.UserConnection);
                if (accounts.Any())
                {
                    foreach (Entity account in accounts)
                    {
                        var accountName = account.GetTypedColumnValue <string>("Name");
                        if (!AccountsMap.ContainsKey(accountName))
                        {
                            AccountsMap[accountName] = account.PrimaryColumnValue;
                        }
                    }
                }
            }
            IEnumerable <string> notFoundCompanies = from company in exchangeCompanies
                                                     where AccountsMap.All(am => am.Key != company)
                                                     select company;
            var companies = notFoundCompanies as IList <string> ?? notFoundCompanies.ToList();

            if (!companies.Any() ||
                UserSettings.LinkContactToAccountType != ExchangeConsts.AllwaysLinkContactToAccountId)
            {
                return;
            }
            foreach (string company in companies)
            {
                EntitySchema accountSchema =
                    context.UserConnection.EntitySchemaManager.FindInstanceByName("Account");
                Entity account = accountSchema.CreateEntity(context.UserConnection);
                account.SetDefColumnValues();
                account.SetColumnValue("Name", company);
                AccountsMap[company] = account.GetTypedColumnValue <Guid>("Id");
                account.Save(false);
            }
        }
Пример #30
0
        protected virtual void CreateContactEntity(Guid contactId, FormFieldsData contactNameField)
        {
            EntitySchema contactSchema = _userConnection.EntitySchemaManager.GetInstanceByName(ContactSchemaName);
            Entity       contact       = contactSchema.CreateEntity(_userConnection);

            contact.SetDefColumnValues();
            contact.SetColumnValue("Id", contactId);
            contact.SetColumnValue("Name", contactNameField.value);
            contact.Save(false);
        }