Beispiel #1
0
        private void ImportCredentials(int rowIndex, int accountId)
        {
            for (int credentialIndex = 0; credentialIndex < ExtractCredentials(rowIndex).Length; credentialIndex++)
            {
                string credentialValue = ExtractCredentials(rowIndex)[credentialIndex].Trim();

                try
                {
                    string fieldName = ExtractFieldNames()[credentialIndex].Trim();

                    CredentialService.Update(accountId, FieldService.GetFieldByName(this.DestinationCategoryId, fieldName).Id,
                                             credentialValue);

                    Log("   " + fieldName + ": '" + credentialValue + "'");
                }
                catch (IndexOutOfRangeException)
                {
                    Log("   '" + credentialValue + "' does not belong to a field and was not added.");
                }
            }
        }
        public static int AddNewWithBlankCredentials(Account account)
        {
            using (var context = new ShedEntities())
            {
                context.Accounts.InsertOnSubmit(account);
                context.SubmitChanges();

                var credentials = new List <Credential>();

                foreach (var field in context.Fields.Where(f => f.CategoryId == account.CategoryId))
                {
                    credentials.Add(new Credential {
                        AccountId = account.Id, FieldId = field.Id, Created = DateTime.Now
                    });
                }

                CredentialService.AddNew(context, credentials);
                context.SubmitChanges();
            }

            return(account.Id);
        }