コード例 #1
0
        public static void AddNew(Field field)
        {
            using (var context = new ShedEntities())
            {
                field.Label = field.Label.Trim();

                if (!NameInUse(context, field.CategoryId, field.Label))
                {
                    context.Fields.InsertOnSubmit(field);
                    context.SubmitChanges();

                    var credentials = new List <Credential>();

                    foreach (Account account in AccountService.GetAccountsByCategoryId(field.CategoryId))
                    {
                        credentials.Add
                            (new Credential {
                            AccountId = account.Id, Created = DateTime.Now, FieldId = field.Id
                        });
                    }

                    CredentialService.AddNew(context, credentials);

                    context.SubmitChanges();
                }
                else
                {
                    throw new ArgumentException("A field with this name already exists.");
                }
            }
        }
コード例 #2
0
        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);
        }