public BillingCycleSummary GetBillingCycleSummary(Guid orderId, int year, int month)
        {
            string partitionKey = DalBillingCycle.RowKeyGenerator(year, month);
            string rowKey       = orderId.ToString();

            try
            {
                BillingCycleSummaryEntity summary = (from e in this.tableContext.CreateQuery <BillingCycleSummaryEntity>(BillingCycleSummaryTableName)
                                                     where e.PartitionKey == partitionKey && e.RowKey == rowKey
                                                     select e).FirstOrDefault();
                if (summary != null)
                {
                    BillingCycleSummary ret = BillingCycleSummaryEntity.RetreiveOBillingCycleSummaryFromString(summary.BillingCycleSummaryAsString);
                    return(ret);
                }

                else
                {
                    return(null);
                }
            }

            catch
            {
                return(null); //TODO cleanse the code
            }
        }
        public bool SaveOrUpdateBillingCycleSummary(BillingCycleSummary summary)
        {
            int statusCode = 0;

            summary.Id = summary.OrderId;

            BillingCycleSummaryEntity entity = new BillingCycleSummaryEntity(summary);

            entity.PartitionKey = DalBillingCycle.RowKeyGenerator(summary.BillingCycleYear, summary.BillingCycleMonth);
            entity.RowKey       = summary.OrderId.ToString();



            try
            {
                this.tableContext.AddObject(BillingCycleSummaryTableName, entity);
                DataServiceResponse response = this.tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch);
                statusCode = response.BatchStatusCode;
            }

            catch //assuming this is the case where summary already exists
            {
                //TODO - error case when bill generation failed in the middle

                /*
                 * BillingCycleSummary existingSummary = GetBillingCycleSummary(summary.OrderId, summary.BillingCycleYear, summary.BillingCycleMonth);
                 * if (existingSummary != null)
                 * {
                 *  //copy over existing properties
                 *  existingSummary.Total = summary.Total;
                 *  existingSummary.Paid = summary.Paid;
                 *  existingSummary.BillingLineItems.AddRange(summary.BillingLineItems);
                 *  this.tableContext.UpdateObject(existingSummary);
                 *  DataServiceResponse response = this.tableContext.SaveChangesWithRetries(SaveChangesOptions.Batch);
                 *  statusCode = response.BatchStatusCode;
                 * }
                 */
            }

            return(statusCode == Http200);
        }