public static void Delete(int id) { using (var context = new ShedEntities()) { context.Categories.DeleteOnSubmit(context.Categories.SingleOrDefault(c => c.Id == id)); AccountService.DeleteByCategoryId(context, id); FieldService.DeleteByCategoryId(context, id); CredentialService.DeleteByCategoryId(context, id); context.SubmitChanges(); } }
private void ImportFields() { Log("Processing fields..."); foreach (string s in this.FileLines[0].Split(',')) { try { FieldService.AddNew(new Field { CategoryId = DestinationCategoryId, Label = s.Trim() }); Log("Added field: '" + s + "'"); } catch (ArgumentException) { Log("'" + s + "' field already exists."); } } }
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."); } } }