Hourly, Daily, Monthly Helper+Model methods

You can create daily,monthly and yearly data by using the same logic. You just have to replace Hour with Day,Month or Year.

List<dynamic> dailyData = new List<dynamic>();
        DateTime dayIterator = StartDate.Value;
        while (dayIterator.Hour <= ddvm.CurrentDay)
        {
            if (ddvm.DailyPaymentTotal != null && ddvm.DailyPaymentTotal.Count() > 0 )
            {
                DailyPaymentTotalModel day = ddvm.DailyPaymentTotal.FirstOrDefault(hpt => hpt.DateTimeStamp == dayIterator);
                if (day == null) { hour = new DailyPaymentTotalModel() { DateTimeStamp = dayIterator }; };
                dailyData.Add(new List<dynamic> {dayIterator.Day,
                                                    day.Amount, 
                                                    new { tooltip = String.Format("{0} : {1}", day.Count, day.Amount.ToString("C")) } });
            }
            dayIterator = dayIterator.AddDays(1);
        }

        ddvm.GraphData.LineChart_DailyTotal.Add(new
        {
            data = dailyData,
            color = "#A1345E",
            label = "Total Amount Paid"
        });

And this will be your DailyModel.

public class DailyPaymentTotalModel : ViewModelBase
{
    public int Day 
    {
        get { return DateTimeStamp.Day; }
        set { DateTimeStamp  = new DateTime(1, 1, value, 0, 0, 0); } 
    }

    public DateTime DateTimeStamp { get; set; }
    public decimal Amount { get; set; }
    public int Count { get; set; }
}

}

And you data fetching logic looks to be in this function you need to make changes in it accordingly to make it work with day,month,year

transactionRepository.GetAllPayments(startDate, endDate, merchantID);

Leave a Comment

tech