public void Save(ExpenseExport expenseExport)
        {
            var context = new ExpenseDataContext(this.account);
            ExpenseExportEntity entity = expenseExport.ToTableEntity();

            context.AddObject(AzureStorageNames.ExpenseExportTable, entity);
            context.SaveChanges();
        }
 public static string ToCsvLine(this ExpenseExport model)
 {
     return(string.Format(
                "{0},{1},{2},{3},{4},{5},{6}",
                model.ApproveDate,
                model.Id,
                model.ApproverName,
                model.UserName,
                model.CostCenter,
                Enum.GetName(
                    typeof(ReimbursementMethod),
                    model.ReimbursementMethod),
                model.TotalAmount));
 }
        public static ExpenseExportEntity ToTableEntity(this ExpenseExport model)
        {
            var expenseExport = new ExpenseExportEntity
            {
                PartitionKey        = model.ApproveDate.ToExpenseExportKey(),
                RowKey              = model.Id,
                ApproverName        = model.ApproverName,
                CostCenter          = model.CostCenter,
                ReimbursementMethod = Enum.GetName(typeof(ReimbursementMethod), model.ReimbursementMethod),
                UserName            = model.UserName,
                TotalAmount         = model.TotalAmount
            };

            return(expenseExport);
        }
        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 static ExpenseExport ToModel(this ExpenseExportEntity entity)
 {
     var expenseReport = new ExpenseExport
                             {
                                 ApproveDate = Convert.ToDateTime(entity.PartitionKey),
                                 ApproverName = entity.ApproverName,
                                 CostCenter = entity.CostCenter,
                                 Id = entity.RowKey ?? StorageKey.Now.InvertedTicks,
                                 ReimbursementMethod =
                                     entity.ReimbursementMethod == null
                                         ? ReimbursementMethod.NotSet
                                         : (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), entity.ReimbursementMethod),
                                 TotalAmount = entity.TotalAmount,
                                 UserName = entity.UserName
                             };
     return expenseReport;
 }
        public static ExpenseExport ToModel(this ExpenseExportEntity entity)
        {
            var expenseReport = new ExpenseExport
            {
                ApproveDate         = Convert.ToDateTime(entity.PartitionKey),
                ApproverName        = entity.ApproverName,
                CostCenter          = entity.CostCenter,
                Id                  = entity.RowKey ?? StorageKey.Now.InvertedTicks,
                ReimbursementMethod =
                    entity.ReimbursementMethod == null
                                                ? ReimbursementMethod.NotSet
                                                : (ReimbursementMethod)Enum.Parse(typeof(ReimbursementMethod), entity.ReimbursementMethod),
                TotalAmount = entity.TotalAmount,
                UserName    = entity.UserName
            };

            return(expenseReport);
        }