public void SaveExpense(Expense expense)
        {
            var           context    = new ExpenseDataContext(this.account);
            ExpenseEntity expenseRow = expense.ToTableEntity();

            foreach (var expenseItem in expense.Details)
            {
                var expenseItemRow = expenseItem.ToTableEntity(expenseRow.PartitionKey, expense.Id);
                context.AddObject(AzureStorageNames.ExpenseTable, expenseItemRow);
            }

            context.AddObject(AzureStorageNames.ExpenseTable, expenseRow);
            context.SaveChanges(SaveChangesOptions.Batch);

            foreach (var expenseItem in expense.Details)
            {
                // save receipt image if any
                if (expenseItem.Receipt != null && expenseItem.Receipt.Length > 0)
                {
                    this.receiptStorage.AddReceipt(expenseItem.Id, expenseItem.Receipt, string.Empty);

                    var queue = new AzureQueue <NewReceiptMessage>(this.account, AzureStorageNames.NewReceiptMessage);
                    queue.AddMessage(new NewReceiptMessage
                    {
                        ExpenseItemId = expenseItem.Id,
                        ExpenseId     = expense.Id,
                        Username      = expense.UserName
                    });
                }
            }
        }
Beispiel #2
0
        public void Save(ExpenseExport expenseExport)
        {
            var context = new ExpenseDataContext(this.account);
            ExpenseExportEntity entity = expenseExport.ToTableEntity();

            context.AddObject(AzureStorageNames.ExpenseExportTable, entity);
            context.SaveChanges();
        }
        public void Save(ExpenseExport expenseExport)
        {
            var context = new ExpenseDataContext(this.account);
            ExpenseExportEntity entity = expenseExport.ToTableEntity();

            context.AddObject(AzureStorageNames.ExpenseExportTable, entity);
            context.SaveChanges();
        }
        public void UpdateApproved(Expense expense)
        {
            var context = new ExpenseDataContext(this.account);

            IExpenseEntity expenseRow = GetExpenseRowById(context, expense.UserName, expense.Id);

            expenseRow.Approved = expense.Approved;

            var queue = new AzureQueue <ApprovedExpenseMessage>(this.account, AzureStorageNames.ApprovedExpenseMessage);

            queue.AddMessage(new ApprovedExpenseMessage {
                ExpenseId = expense.Id, ApproveDate = DateTime.UtcNow, Username = expense.UserName
            });

            context.UpdateObject(expenseRow);
            context.SaveChanges();
        }
        public void Delete(ExpenseExport expenseExport)
        {
            var context = new ExpenseDataContext(this.account);
            var query = (from export in context.ExpenseExport
                         where
                             export.PartitionKey.CompareTo(expenseExport.ApproveDate.ToExpenseExportKey()) == 0 &&
                             export.RowKey.CompareTo(expenseExport.Id) == 0
                         select export).AsTableServiceQuery();
            ExpenseExportEntity entity = query.Execute().SingleOrDefault();
            if (entity == null)
            {
                return;
            }

            context.DeleteObject(entity);
            context.SaveChanges();
        }
Beispiel #6
0
        public void Delete(ExpenseExport expenseExport)
        {
            var context = new ExpenseDataContext(this.account);
            var query   = (from export in context.ExpenseExport
                           where
                           export.PartitionKey.CompareTo(expenseExport.ApproveDate.ToExpenseExportKey()) == 0 &&
                           export.RowKey.CompareTo(expenseExport.Id) == 0
                           select export).AsTableServiceQuery();
            ExpenseExportEntity entity = query.Execute().SingleOrDefault();

            if (entity == null)
            {
                return;
            }

            context.DeleteObject(entity);
            context.SaveChanges();
        }
        public void UpdateExpenseItemImages(string username, string expenseId, string expenseItemId, string imageUri, string thumbnailUri)
        {
            var context = new ExpenseDataContext(this.account);

            // this query would work faster if we specify PartitionKey and RowKey
            // For simplicity we'll just do a table scan by expense item id
            var query = (from expenseItemRow in context.ExpenseExpenseItem
                         where expenseItemRow.PartitionKey == username.EncodePartitionAndRowKey() &&
                         expenseItemRow.RowKey == KeyGenerator.ExpenseItemEntityRowKey(expenseId, expenseItemId)
                         select expenseItemRow).AsTableServiceQuery();

            var item = query.Execute().SingleOrDefault();

            item.ReceiptUrl          = imageUri;
            item.ReceiptThumbnailUrl = thumbnailUri;

            context.UpdateObject(item);
            context.SaveChanges();
        }
        public void UpdateExpenseItemImages(string username, string expenseId, string expenseItemId, string imageUri, string thumbnailUri)
        {
            var context = new ExpenseDataContext(this.account);

            // this query would work faster if we specify PartitionKey and RowKey
            // For simplicity we'll just do a table scan by expense item id
            var query = (from expenseItemRow in context.ExpenseExpenseItem
                         where expenseItemRow.PartitionKey == username.EncodePartitionAndRowKey()
                               && expenseItemRow.RowKey == KeyGenerator.ExpenseItemEntityRowKey(expenseId, expenseItemId)
                         select expenseItemRow).AsTableServiceQuery();

            var item = query.Execute().SingleOrDefault();

            item.ReceiptUrl = imageUri;
            item.ReceiptThumbnailUrl = thumbnailUri;

            context.UpdateObject(item);
            context.SaveChanges();
        }
        public void UpdateApproved(Expense expense)
        {
            var context = new ExpenseDataContext(this.account);

            IExpenseEntity expenseRow = GetExpenseRowById(context, expense.UserName, expense.Id);
            expenseRow.Approved = expense.Approved;

            var queue = new AzureQueue<ApprovedExpenseMessage>(this.account, AzureStorageNames.ApprovedExpenseMessage);
            queue.AddMessage(new ApprovedExpenseMessage { ExpenseId = expense.Id, ApproveDate = DateTime.UtcNow, Username = expense.UserName });

            context.UpdateObject(expenseRow);
            context.SaveChanges();
        }
        public void SaveExpense(Expense expense)
        {
            var context = new ExpenseDataContext(this.account);
            ExpenseEntity expenseRow = expense.ToTableEntity();

            foreach (var expenseItem in expense.Details)
            {
                var expenseItemRow = expenseItem.ToTableEntity(expenseRow.PartitionKey, expense.Id);
                context.AddObject(AzureStorageNames.ExpenseTable, expenseItemRow);
            }

            context.AddObject(AzureStorageNames.ExpenseTable, expenseRow);
            context.SaveChanges(SaveChangesOptions.Batch);

            foreach (var expenseItem in expense.Details)
            {
                // save receipt image if any
                if (expenseItem.Receipt != null && expenseItem.Receipt.Length > 0)
                {
                    this.receiptStorage.AddReceipt(expenseItem.Id, expenseItem.Receipt, string.Empty);

                    var queue = new AzureQueue<NewReceiptMessage>(this.account, AzureStorageNames.NewReceiptMessage);
                    queue.AddMessage(new NewReceiptMessage
                                         {
                                             ExpenseItemId = expenseItem.Id,
                                             ExpenseId = expense.Id,
                                             Username = expense.UserName
                                         });
                }
            }
        }