public static async Task RunAsync(
            [QueueTrigger("userUpdatesQueue")] string user,
            [Table("Costs")] CloudTable costsTable,
            [Table("CostsByMonth")] CloudTable costsByMonthTable,
            ILogger log)
        {
            log.LogInformation($"Regenerating Read Models for User '{user}'");

            var costs = await CostTable.GetCostsForUser(user, costsTable);

            var monthlyUserCosts =
                costs
                .GroupBy(cost => cost.Date.Year.ToString() + "-" + cost.Date.Month.ToString("D2"))
                .Select(monthGroup =>
                        new MonthlySummaryTableEntity {
                PartitionKey = user,
                RowKey       = monthGroup.Key,
                Month        = monthGroup.Key,
                User         = user,
                ValuePence   = (int)(monthGroup.Sum(cost => cost.Value) * 100)
            });

            foreach (var monthlyUserCost in monthlyUserCosts)
            {
                await costsByMonthTable.ExecuteAsync(TableOperation.InsertOrReplace(monthlyUserCost));
            }
        }
Ejemplo n.º 2
0
        //Adds element to the database (used in command)
        private async Task <Page> Add()
        {
            INavigation Nav = Application.Current.MainPage.Navigation;

            //Constructing "Sharable" table item
            CostTable TableItem = new CostTable
            {
                Date       = PostDate,
                CostItemId = SelectedCost.Id,
                Value      = sum
            };

            //Check existence of a table
            if (DBController.TableExists(nameof(CostTable)))
            {
                //Insertion table item into the table
                DBController.InsertItem(TableItem);

                // Go To Expense list page
                return(await Nav.PopAsync());
            }
            else
            {
                //Creation of a table then insertion item into it
                DBController.AddTable(TableItem);
                DBController.InsertItem(TableItem);

                //Create and GO To Expense list page
                Nav.InsertPageBefore(new SpendsListPage(), Nav.NavigationStack[Nav.NavigationStack.Count - 1]);
                return(await Nav.PopAsync());
            }
        }
        private void ConstantlyRefresh()
        {
            do
            {
                InvokeOnMainThread(
                    delegate {
                    var costManager  = CostManager.Create();
                    CostTable.Source = new CostResource(costManager.Costs, this);

                    CostTable.ReloadData();
                });
                Thread.Sleep(10000);
            } while (true);
        }
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "MonthlyCosts/{User}")] HttpRequest req,
            [Table("CostsByMonth")] CloudTable costsTable,
            string user,
            ILogger log)
        {
            {
                log.LogInformation($"Get MonthlyCosts/{user} Called");

                var monthlyCosts = await CostTable.GetCostsByMonth(user, costsTable);

                return(new JsonResult(monthlyCosts));
            }
        }
Ejemplo n.º 5
0
        public static async Task <IActionResult> Run(
            [HttpTrigger(AuthorizationLevel.Function, "get", Route = "Costs/{User}")] HttpRequest req,
            [Table("Costs")] CloudTable costsTable,
            string User,
            ILogger log)
        {
            log.LogInformation($"Get Costs/{User} Called");

            var costs = await CostTable.GetCostsForUser(User, costsTable);

            var sortedCosts = costs.OrderByDescending(cost => cost.Date);

            var outputCosts = sortedCosts.Select(cost => new CostOutputModel {
                Item  = cost.Item,
                Value = cost.Value,
                Date  = cost.Date.LocalDateTime.ToString("dd-MMM-yyyy")
            });

            return(new JsonResult(outputCosts));
        }
Ejemplo n.º 6
0
        public async Task <bool> AddCost(CostViewModel model, string subGroupId, string AddedBy)
        {
            var user = await userManager.FindByNameAsync(AddedBy);

            var subGroups = context.subGroups.Where(x => x.Id.ToString() == subGroupId).FirstOrDefault();

            if (user == null || subGroups == null)
            {
                return(false);
            }
            CostTable costTable = new CostTable()
            {
                description  = model.Descriptions,
                IdentityUser = user,
                Date         = DateTime.UtcNow,
                SubGroups    = subGroups,
                Taka         = model.Taka
            };

            context.costTables.Add(costTable);
            await context.SaveChangesAsync();

            return(true);
        }