public UserService( BudgetDbContext context, IMapper mapper) { this.context = context; this.mapper = mapper; }
public IEnumerable <TransDetail> GetTransactions() { using (var ctx = new BudgetDbContext()) { var query = ctx .Transactions .Select( e => new TransDetail { Id = e.Id, Date = e.Date, Account = e.Account, //displaying the reference # in the enum now Category = e.Category, //displaying the reference # in the enum now Description = e.Description, Value = e.Value, CreatedUtc = e.CreatedUtc, ModifiedUtc = e.ModifiedUtc } ); return(query.ToArray()); } }
public UserService() { string connectionName = ConfigurationManager.ConnectionStrings["BudgetManagerContext"].ConnectionString; context = new BudgetDbContext(connectionName); repo = new Repository <User>(context); }
private void UsingManager(Action <BudgetClassManager> action) { using (BudgetDbContext dbContext = DbSetupHelper.GetDbContext()) { var manager = new BudgetClassManager(dbContext); action.Invoke(manager); } }
public TransactionService( BudgetDbContext context, IMapper mapper, IUserService userService) { this.context = context; this.mapper = mapper; this.userService = userService; }
public static void SeedDatabase(BudgetDbContext context, IColorGenerator colorGenerator) { context.Database.EnsureCreated(); if (!context.Categories.Any()) { context.Categories.AddRange(GetCategoriesToSeed(colorGenerator)); context.SaveChanges(); } }
private static async Task SeedAsync(this BudgetDbContext context, RoleManager <IdentityRole> roleManager) { await context.AddRolesAsync(roleManager); await context.AddCurrenciesAsync(); await context.AddPaymentTypesAsync(); await context.AddCategoriesAsync(); await context.SaveChangesAsync(); }
public static async Task <BudgetDbContext> AddRolesAsync(this BudgetDbContext context, RoleManager <IdentityRole> roleManager) { if (!await roleManager.RoleExistsAsync(Roles.Administrator)) { await roleManager.CreateAsync(new IdentityRole(Roles.Administrator)); } if (!await roleManager.RoleExistsAsync(Roles.User)) { await roleManager.CreateAsync(new IdentityRole(Roles.User)); } return(context); }
/// <summary> /// Asserts that entities with the supplied key data values do not exist /// </summary> /// <param name="dataSet">Data for the entities to be searched for</param> public void AssertEntitiesDoNotExist(params BudgetClassData[] dataSet) { using (BudgetDbContext dbContext = BudgetDbSetupHelper.GetDbContext()) { var manager = new BudgetClassManager(dbContext); foreach (BudgetClassData data in dataSet) { BudgetClass entity = manager.SingleOrDefault(e => e.Name == data.Name); entity.Should().BeNull(@"because BudgetClass ""{0}"" MUST NOT EXIST!", data.Name); } } }
public UnitOfWork(BudgetDbContext context, UserManager <User> userManager, ISubscriptionRepository subscriptionRepository, ITransactionRepository transactionRepository, ICompanyRepository companyRepository, IUserRepository userRepository) { _context = context; _userManager = userManager; Subscriptions = subscriptionRepository; Transactions = transactionRepository; Companies = companyRepository; Users = userRepository; }
private static string GetValueFromKeyValuePairs(string key) { BudgetDbContext db = new BudgetDbContext(); var query = from kvp in db.KeyValuePairs where kvp.Key == key select kvp; try { return(query.Single().Value); } catch { return(null); } }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. public void Configure(IApplicationBuilder app, IHostingEnvironment env, BudgetDbContext budgetDbContext) { if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseCors("CorsPolicyBudgetApi"); budgetDbContext.EnsureSeedDataForContext(); app.UseMvc(); // Status message app.Run(async(context) => { await context.Response.WriteAsync("WebApi Up and Spinning..."); }); }
public bool EnterTransaction(EnterTransaction transaction) { var newTransaction = new Transaction() { Date = transaction.Date, Account = transaction.Account, Category = transaction.Category, Description = transaction.Description, Value = transaction.Value, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new BudgetDbContext()) { ctx.Transactions.Add(newTransaction); return(ctx.SaveChanges() == 1); } }
/// <summary> /// Asserts that entities equivalent to the supplied input data classes exist /// </summary> /// <param name="dataSet">Data for the entities to be searched for</param> public void AssertEntitiesExist(params BudgetClassData[] dataSet) { using (BudgetDbContext dbContext = BudgetDbSetupHelper.GetDbContext()) { var manager = new BudgetClassManager(dbContext); var mapper = new BudgetClassDataMapper(); foreach (BudgetClassData data in dataSet) { BudgetClass entity = manager.SingleOrDefault(e => e.Name == data.Name); entity.Should().NotBeNull(@"because BudgetClass ""{0}"" MUST EXIST!", data.Name); BudgetClassData entityData = mapper.CreateData(entity); entityData.ShouldBeEquivalentTo(data); } } }
public static async Task <BudgetDbContext> AddPaymentTypesAsync(this BudgetDbContext context) { if (!await context.PaymentTypes.AnyAsync()) { context.Add(new PaymentType() { Name = "Cash" }); context.Add(new PaymentType() { Name = "Debit Card" }); context.Add(new PaymentType() { Name = "Credit Card" }); } return(context); }
public static async Task <BudgetDbContext> AddCurrenciesAsync(this BudgetDbContext context) { if (!await context.Currencies.AnyAsync()) { context.Add(new Currency() { Name = "Bulgarian lev", Abbreviation = "BGN" }); context.Add(new Currency() { Name = "European Euro", Abbreviation = "EUR" }); context.Add(new Currency() { Name = "U.S. Dollar", Abbreviation = "USD" }); } return(context); }
private static void Main(string[] args) { Console.WriteLine("Host for EF scripts"); string connectionString = "Server=(localdb)\\MSSQLLocalDB; Database=MicroFlow.Scripts.App; Trusted_Connection=true; MultipleActiveResultSets=true;"; var optionsBuilder = new DbContextOptionsBuilder <BudgetDbContext>(); optionsBuilder.UseSqlServer(connectionString); Console.WriteLine($"Connection String: {connectionString}"); Console.WriteLine("Creating database / applying migrations..."); using (var dbContext = new BudgetDbContext(optionsBuilder.Options)) { dbContext.Database.Migrate(); } Console.WriteLine("Done!"); }
static void Main(string[] args) { Console.WriteLine("Host for EF scripts"); // 1-2. Initialize DbContext and apply migration to verify it's working //--------------------------------------------------------------------- string connectionString = "Server=localhost; Initial Catalog=SpecFlowEFCore2.Cli; Trusted_Connection=true; MultipleActiveResultSets=true;"; var optionsBuilder = new DbContextOptionsBuilder <BudgetDbContext>(); optionsBuilder.UseSqlServer(connectionString); Console.WriteLine("Creating database / applying migrations..."); using (var dbContext = new BudgetDbContext(optionsBuilder.Options)) { dbContext.Database.Migrate(); } Console.WriteLine("Done!"); }
public BaseRepository(BudgetDbContext dbContext) { _dbContext = dbContext; }
public UserRepository(BudgetDbContext context, UserManager <User> userManager) : base(context, userManager) { }
public AccountRepository(BudgetDbContext budgetDbContext) : base(budgetDbContext) { }
public CategoryService(BudgetDbContext context, UserManager <User> userManager, IMapper mapper) { this.context = context; this.userManager = userManager; this.mapper = mapper; }
public BanquesController(BudgetDbContext context) { _context = context; }
public BudgetItemTypeRepository( BudgetDbContext dbContext) : base(dbContext) { }
public AppFeatures( BudgetDbContext dbContext) { DbContext = dbContext; }
public ScoreRepository(BudgetDbContext db) : base(db) { }
public TransactionRepository(BudgetDbContext db) : base(db) { }
public BudgetController(BudgetDbContext db) { _db = db; _mr = new MemberRepository <BudgetDbContext>(db); }
public RecordRepository(BudgetDbContext budgetDbContext) : base(budgetDbContext) { }
public EcrituresController(BudgetDbContext context) { _context = context; }