protected void AddBtn_Click(object sender, EventArgs e) { var usr = (User)Session["LoggedInUser"]; try { using (var ctx = new BudgetContext()) { ctx.Users.Attach(usr); var incom = new FixIncom { Amount = float.Parse(AmntTxt.Text), Concept = ConceptTxt.Text }; usr.FixIncoms.Add(incom); ctx.SaveChanges(); ctx.Entry(usr).State = System.Data.Entity.EntityState.Detached; ConceptTxt.Text = ""; AmntTxt.Text = ""; } GridView1.DataBind(); } catch (Exception ex) { throw; } }
public SpendingsPageViewModel() { bCon = new BudgetContext(); bCon.Posts.Load(); dataGrid = new BindableCollection <Posts>(bCon.Posts.Local.ToBindingList()); }
private static void ParsDocumentArray() { var parser = new JsonParser(); // var path = @"..\..\..\..\..\Resources\JsonData\28_07_2019_03_07_065945492267877694613.json"; var path = @"..\..\..\..\..\Resources\JsonData\document-array.json"; // var path = @"..\..\..\..\..\Resources\JsonData\test.json"; var model = parser.ParseDocumentArrayFile(path); using (var context = new BudgetContext()) { foreach (var receiptModel in model) { var receipt = ReceiptWtapper.Create(receiptModel, context); var current = context.GetReceipt(receiptModel.FiscalDriveNumber, receiptModel.FiscalDocumentNumber, receiptModel.FiscalSign, receiptModel.DateTime, receiptModel.TotalSum); if (current == null) { context.Receipts.Add(receipt); context.SaveChanges(); } } } }
public async Task SearchBills_ShouldReturnBills_OrderedByDateDescending() { // Arrange var billEntities = CreateBillEntitiesWithRandomDates(); var context = BudgetContext.CreateInMemoryDataContext(db => { foreach (var billEntity in billEntities) { db.Bill.Add(billEntity); } }); var sut = SetupSystemUnderTest(context); // Act var result = await sut.SearchBillsAsync(user.Id); // Assert DateTime previousDate = result.Value.First().Date; foreach (var bill in result.Value) { Assert.True(bill.Date <= previousDate); previousDate = bill.Date; } }
public static void Initialize(BudgetContext context) { context.Database.EnsureCreated(); // Look for any Categories. if (context.Categories.Any()) { return; // DB has been seeded } Random rand = new Random(); for (int i = 0; i < 8; i++) { context.Categories.Add(new Category { Name = GetRandomDescr(2) }); } context.SaveChanges(); //for (int i = 0; i < 50; i++) //{ // context.Movements.Add(new Movement { // Amount = (decimal)Math.Round(rand.NextDouble() * (double)rand.Next(-400, 400), 2), // Description = GetRandomDescr(), // MovementDate = DateTime.Now.AddDays(rand.Next(-300, 1)), // }); //} //context.SaveChanges(); }
public HomeController(ILogger <HomeController> logger, ILoginService login, ICredentialHoldingService creds, BudgetContext context) { _login = login; _logger = logger; _creds = creds; _context = context; }
public ActionResult ChangeCostCenter(string costcenterid) { try { using (var db = new BudgetContext()) { var costcenter = db.CostCenters.Where(c => c.CostCenterID == costcenterid).FirstOrDefault(); AuthManager.ChangeWorkingCostcenter(costcenter); // Save history to database CurrentWorkingCC current = new CurrentWorkingCC(); current.Id = Guid.NewGuid(); current.WorkingCostCenterID = costcenter.CostCenterID; current.EmployeeID = AuthManager.GetCurrentUser().EmployeeID; current.NewCreateTimeStamp(); db.CurrentWorkingCCs.Add(current); db.SaveChanges(); returnobj.SetSuccess(AuthManager.GetAuthentication()); } } catch (Exception ex) { returnobj.SetError(ex.Message); } return(Content(returnobj.ToJson(), "application/json")); }
//[ClassCleanup] public void DeleteSampleBudget() { using (var budget = new BudgetContext()) { foreach (var transaction in budget.Transactions) { budget.Transactions.Remove(transaction); } foreach (var category in budget.Categories) { budget.Categories.Remove(category); } foreach (var account in budget.Accounts) { budget.Accounts.Remove(account); } foreach (var payee in budget.Payees) { budget.Payees.Remove(payee); } budget.SaveChanges(); } }
protected void AddBtn_Click(object sender, EventArgs e) { var usr = (User)Session["LoggedInUser"]; if (TypeDropDn.SelectedIndex == 0) { TypeDropDn.Focus(); return; } using (var ctx = new BudgetContext()) { ctx.Users.Attach(usr); Alarm neo = new Alarm { Active = true, AlarmType = (AlarmType)Enum.Parse(typeof(AlarmType), TypeDropDn.Text), Amount = float.Parse(AmntTxt.Text), Message = MsgTxt.Text, Tag = ctx.ExpenseTags.Find(TagDropDn.Text) }; usr.Alarms.Add(neo); ctx.SaveChanges(); ctx.Entry(usr).State = System.Data.Entity.EntityState.Detached; } AmntTxt.Text = MsgTxt.Text = ""; TagDropDn.SelectedIndex = 0; GridView1.DataBind(); }
//[ClassCleanup] public void DeleteSampleBudget() { using (var budget = new BudgetContext()) { foreach (var transaction in budget.Transactions) { budget.Transactions.Remove(transaction); } foreach (var category in budget.Categories) { budget.Categories.Remove(category); } foreach (var account in budget.Accounts) { budget.Accounts.Remove(account); } foreach(var payee in budget.Payees) { budget.Payees.Remove(payee); } budget.SaveChanges(); } }
public OperationTypeFamilyRepository(BudgetContext context, IOperationRepository operationRepository, IOperationTypeRepository operationTypeRepository) : base(context) { _operationRepository = operationRepository; _operationTypeRepository = operationTypeRepository; }
// This method gets called by the runtime. Use this method to configure the HTTP request pipeline. // ReSharper disable once UnusedMember.Global public void Configure( IApplicationBuilder app, IHostingEnvironment env, BudgetContext dbContext, IApiVersionDescriptionProvider provider) { dbContext.Database.Migrate(); if (env.IsDevelopment()) { app.UseDeveloperExceptionPage(); } app.UseMvc(); app.UseSwagger(); app.UseSwaggerUI( options => { foreach (var description in provider.ApiVersionDescriptions) { options.SwaggerEndpoint( $"/swagger/{description.GroupName}/swagger.json", description.GroupName.ToUpperInvariant()); } }); }
public User GetUserByUsername(string username) { using (BudgetContext ctx = new BudgetContext()) { User user = ctx.Users.Where(x => x.Username == username).FirstOrDefault(); return(user); } }
public void Update(TransactionCategory entity) { using (var context = new BudgetContext()) { context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); } }
public IncomeUpdater(BudgetContext context, ISourceResolver sourceResolver, IClientSourceResolver clientSourceResolver, IMapper mapper) { _context = context; _sourceResolver = sourceResolver; _mapper = mapper; _clientSourceResolver = clientSourceResolver; }
public Category GetCategoryByName(string categoryName) { using (BudgetContext ctx = new BudgetContext()) { Category category = ctx.Categories.Where(x => x.Name == categoryName).FirstOrDefault(); return(category); } }
public Category GetCategory(int categoryId) { using (BudgetContext ctx = new BudgetContext()) { Category category = ctx.Categories.Where(x => x.CategoryId == categoryId).FirstOrDefault(); return(category); } }
public List <Category> GetAllCategories() { using (BudgetContext ctx = new BudgetContext()) { var categories = ctx.Categories; return(categories.ToList()); } }
public IncomeAdder(BudgetContext context, ISourceResolver sourceResolver, IClientSourceResolver clientSourceReolver, IUserAccessor userAccessor) { _context = context; _sourceResolver = sourceResolver; _userAccessor = userAccessor; _clientSourceResolver = clientSourceReolver; }
public Item GetItem(int itemId) { using (BudgetContext ctx = new BudgetContext()) { Item item = ctx.Items.Where(x => x.ItemId == itemId).FirstOrDefault(); return(item); } }
static void Main(string[] args) { using (BudgetContext context = new BudgetContext(@"Data Source=FG-DUNIN\WS100500;Initial Catalog=BudgetModel.DataContext.BudgetContext;Integrated Security=True;MultipleActiveResultSets=True")) { var vv = context.Goods.ToList(); context.SaveChanges(); } }
public User GetUser(int userId) { using (BudgetContext ctx = new BudgetContext()) { User user = ctx.Users.Where(x => x.UserId == userId).FirstOrDefault(); return(user); } }
public void Update(User entity) { using (var context = new BudgetContext()) { context.Entry(entity).State = EntityState.Modified; context.SaveChanges(); } }
public void CreateData() { var days = 30; var from = DateTime.Today.AddDays(-1 * days); var to = DateTime.Today.AddDays(days); var receiptGenerator = new ReceiptGenerator(); var goodGenerator = new GoodGenerator(); var shopGenerator = new ShopGenerator(); var receipts = new List <Receipt>(); var context = new BudgetContext(); for (DateTime currentDate = from; currentDate < to; currentDate = currentDate.AddDays(1)) { var baseTime = DateTime.Today.TimeOfDay.Ticks; var receiptPerDay = RandomUtils.Number(1, 11); var deltaTime = TimeSpan.TicksPerDay / receiptPerDay; for (int i = 0; i < receiptPerDay; i++) { var dayTicks = baseTime + i * deltaTime; var date = currentDate.AddTicks(dayTicks); var receipt = receiptGenerator.GetReceipt(); receipt.Date = date; receipt.Items = Enumerable.Range(1, RandomUtils.Number(2, 5)) .Select(el => goodGenerator.GetGood(context)) .ToList(); receipt.Shop = shopGenerator.GetShop(context); receipt.TotalSum = receipt.Items.Sum(el => el.Sum); receipt.Nds18 = receipt.Items.Sum(el => el.Nds18); receipt.Nds10 = receipt.Items.Sum(el => el.Nds10); receipt.Nds0 = receipt.Items.Sum(el => el.Nds0); receipt.NdsCalculated18 = receipt.Items.Sum(el => el.NdsCalculated18); receipt.NdsCalculated10 = receipt.Items.Sum(el => el.NdsCalculated10); receipt.NdsNo = receipt.Items.Sum(el => el.NdsNo); var totalQuantity = 100; var splitter = new AmountSplitter(receipt.TotalSum, totalQuantity); var cashPercents = RandomUtils.PositiveNumber(totalQuantity); receipt.CashTotalSum = splitter.Get(cashPercents); receipt.EcashTotalSum = splitter.Get(totalQuantity - cashPercents); receipts.Add(receipt); } } // using (var context = new BudgetContext()) // { // context.Products.AsNoTracking(); // context.Shops.AsNoTracking(); context.Receipts.AddRange(receipts); context.SaveChanges(); // } }
public async Task <IEnumerable <Shop> > GetAllShops() { using (var context = new BudgetContext()) { var receipts = await context.Shops.ToListAsync(); return(receipts); } }
private void RunMigrations(BudgetContext context) { var pendingMigrations = context.Database.GetPendingMigrations(); if (pendingMigrations.Any()) { context.Database.Migrate(); } }
public async Task <IEnumerable <Product> > GetAllProducts() { using (var context = new BudgetContext()) { var receipts = await context.Products.ToListAsync(); return(receipts); } }
public async Task <Good> GetGood(int id) { using (var context = new BudgetContext()) { var receipt = await context.Goods .FirstOrDefaultAsync(el => el.Id == id); return(receipt); } }
public User GetByName(string userName) { User user; using (var context = new BudgetContext()) { user = context.Users.Where(z => z.Name == userName).FirstOrDefault(); } return(user); }
public List <User> GetAll() { List <User> entityList; using (var context = new BudgetContext()) { entityList = context.Users.Include(z => z.Transactions.Select(x => x.TransactionCategory)).ToList(); } return(entityList); }
public User Get(int key) { User entity; using (var context = new BudgetContext()) { entity = context.Users.Where(z => z.UserId == key).FirstOrDefault(); } return(entity); }
public void CategoriesCreatedSuccessfully() { this.CreateSampleBudget(); using (var budget = new BudgetContext()) { Assert.AreEqual(budget.Accounts.ToString(), "Budget"); } this.DeleteSampleBudget(); }
//[ClassInitialize] public void CreateSampleBudget() { using (var budget = new BudgetContext()) { budget.Database.Migrate(); var checking = new Account(AccountType.Checking, "Test Checking Account"); budget.Accounts.Add(checking); var savings = new Account(AccountType.Savings, "Test Savings Account"); budget.Accounts.Add(savings); var creditCard = new Account(AccountType.CreditCard, "Test Credit Card"); budget.Accounts.Add(creditCard); var housing = new Category(null, "Housing", null); budget.Categories.Add(housing); var mortgage = new Category(housing, "Mortgage", null); budget.Categories.Add(mortgage); var propertyTax = new Category(housing, "Property Tax", null); budget.Categories.Add(propertyTax); var insurance = new Category(housing, "Insurance", null); budget.Categories.Add(insurance); var transportation = new Category(null, "Transportation", null); budget.Categories.Add(transportation); var everydayExpenses = new Category(null, "Everyday Expenses", null); budget.Categories.Add(everydayExpenses); var savingsGoals = new Category(null, "Savings Goals", null); budget.Categories.Add(savingsGoals); var chaseBank = new Payee("Chase Bank"); budget.Payees.Add(chaseBank); budget.Payees.Add(new Payee("Citibank")); budget.Payees.Add(new Payee("Bank of America")); budget.Payees.Add(new Payee("Shell")); budget.Payees.AddRange(new Payee[] { new Payee("Texaco"), new Payee("Chevrolet"), new Payee("PEMCO Insurance"), new Payee("Safeway"), new Payee("Target"), new Payee("New York Times"), new Payee("Microsoft Corporation") }); budget.SaveChanges(); } }