Exemplo n.º 1
0
 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());
            }
        }
Exemplo n.º 3
0
        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);
            }
        }
Exemplo n.º 5
0
 public TransactionService(
     BudgetDbContext context,
     IMapper mapper,
     IUserService userService)
 {
     this.context     = context;
     this.mapper      = mapper;
     this.userService = userService;
 }
Exemplo n.º 6
0
        public static void SeedDatabase(BudgetDbContext context, IColorGenerator colorGenerator)
        {
            context.Database.EnsureCreated();
            if (!context.Categories.Any())
            {
                context.Categories.AddRange(GetCategoriesToSeed(colorGenerator));

                context.SaveChanges();
            }
        }
Exemplo n.º 7
0
        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();
        }
Exemplo n.º 8
0
        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);
        }
Exemplo n.º 9
0
        /// <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);
                }
            }
        }
Exemplo n.º 10
0
 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;
 }
Exemplo n.º 11
0
        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);
            }
        }
Exemplo n.º 12
0
        // 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...");
            });
        }
Exemplo n.º 13
0
        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);
            }
        }
Exemplo n.º 14
0
        /// <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);
                }
            }
        }
Exemplo n.º 15
0
        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);
        }
Exemplo n.º 16
0
        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);
        }
Exemplo n.º 17
0
        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!");
        }
Exemplo n.º 18
0
        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!");
        }
Exemplo n.º 19
0
 public BaseRepository(BudgetDbContext dbContext)
 {
     _dbContext = dbContext;
 }
Exemplo n.º 20
0
 public UserRepository(BudgetDbContext context, UserManager <User> userManager)
     : base(context, userManager)
 {
 }
Exemplo n.º 21
0
 public AccountRepository(BudgetDbContext budgetDbContext)
     : base(budgetDbContext)
 {
 }
Exemplo n.º 22
0
 public CategoryService(BudgetDbContext context, UserManager <User> userManager, IMapper mapper)
 {
     this.context     = context;
     this.userManager = userManager;
     this.mapper      = mapper;
 }
Exemplo n.º 23
0
 public BanquesController(BudgetDbContext context)
 {
     _context = context;
 }
Exemplo n.º 24
0
 public BudgetItemTypeRepository(
     BudgetDbContext dbContext)
     : base(dbContext)
 {
 }
Exemplo n.º 25
0
 public AppFeatures(
     BudgetDbContext dbContext)
 {
     DbContext = dbContext;
 }
Exemplo n.º 26
0
 public ScoreRepository(BudgetDbContext db) : base(db)
 {
 }
Exemplo n.º 27
0
 public TransactionRepository(BudgetDbContext db) : base(db)
 {
 }
 public BudgetController(BudgetDbContext db)
 {
     _db = db;
     _mr = new MemberRepository <BudgetDbContext>(db);
 }
Exemplo n.º 29
0
 public RecordRepository(BudgetDbContext budgetDbContext) : base(budgetDbContext)
 {
 }
Exemplo n.º 30
0
 public EcrituresController(BudgetDbContext context)
 {
     _context = context;
 }