コード例 #1
0
        public static Expense ToModel(this IExpenseEntity entity)
        {
            var expense = new Expense
                              {
                                  Id = new StorageKey(KeyGenerator.ExpenseEntitySuffix(entity.RowKey)).InvertedTicks,
                                  Approved = entity.Approved.HasValue ? entity.Approved.Value : false,
                                  CostCenter = entity.CostCenter,
                                  Date = entity.Date.HasValue ? entity.Date.Value : DateTime.UtcNow,
                                  ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), entity.ReimbursementMethod),
                                  Title = entity.Title,
                                  UserName = entity.PartitionKey.DecodePartitionAndRowKey(),
                                  ApproverName = entity.ApproverName
                              };

            return expense;
        }
コード例 #2
0
        private void SaveExpense()
        {
            var userRepository = new UserRepository();
            var user = userRepository.GetUser(this.User.Identity.Name);

            var approverName = this.Approver.Text;

            if (string.IsNullOrEmpty(approverName))
            {
                throw new InvalidOperationException(string.Format(CultureInfo.CurrentCulture, "The approver {0} does not exists", this.Approver.Text));
            }

            var newExpense = new Expense
            {
                Id = StorageKey.Now.InvertedTicks,
                Title = this.ExpenseTitle.Text,
                CostCenter = user.CostCenter,
                Approved = false,
                ReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedItem.Value),
                UserName = user.UserName,
                Date = DateTime.Parse(this.ExpenseDate.Text, CultureInfo.CurrentUICulture),
                ApproverName = approverName
            };
            this.ExpenseItems.ForEach(ei => newExpense.Details.Add(ei));

            var expenseRepository = new ExpenseRepository();
            expenseRepository.SaveExpense(newExpense);

            user.PreferredReimbursementMethod = (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), this.ExpenseReimbursementMethod.SelectedValue);
            userRepository.UpdateUserPreferredReimbursementMethod(user);
        }
コード例 #3
0
        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();
        }
コード例 #4
0
        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
                                         });
                }
            }
        }