C# 我的对象值在迭代中如何变化?

C# 我的对象值在迭代中如何变化?,c#,asp.net-mvc,c#-4.0,C#,Asp.net Mvc,C# 4.0,如果这是个愚蠢的问题,请原谅 我正在努力做到以下几点 这是我的行动: public JsonResult CumLeadsParameters(CumLeadsReport cumLeads) { var weeks = (cumLeads.EndDate - cumLeads.StartDate).TotalDays / 7; if (!(weeks > 0)) { // means I have less than a week so calc

如果这是个愚蠢的问题,请原谅 我正在努力做到以下几点

这是我的行动:

public JsonResult CumLeadsParameters(CumLeadsReport cumLeads)
{
    var weeks = (cumLeads.EndDate - cumLeads.StartDate).TotalDays / 7;

    if (!(weeks > 0))
    {
        // means I have less than a week so calculate days and make it as a weeek and 
        var startDate = new DateTime(cumLeads.StartDate.Year,
                                     cumLeads.StartDate.Month,
                                     cumLeads.StartDate.Day, 0, 0, 0, 0);
        var ts = new TimeSpan(23, 59, 59);
        var endDate = startDate.AddDays(6.0).Date + ts;
        var x = _retailerStatsRepository.GetAllRetailersForManufacturerCountrySelectedDates(
                    manufacturer.Id,
                    country.Id,
                    startDate,
                    endDate);
    }
    else
    {
        cumLeads.StartDate = new DateTime(cumLeads.StartDate.Year,
                                          cumLeads.StartDate.Month,
                                          cumLeads.StartDate.Day, 0, 0, 0, 0);
        while (weeks > 0)
        {
            weekCounter++;
            var ts = new TimeSpan(23, 59, 59);
            cumLeads.EndDate = cumLeads.StartDate.AddDays(6.0).Date + ts;
            var x = _retailerStatsRepository.GetAllRetailersForManufacturerCountrySelectedDates(
                        manufacturer.Id,
                        country.Id,
                        cumLeads.StartDate,
                        cumLeads.EndDate);

            tuple.Add(new Tuple<int, IQueryable<RetailerStat>, DateTime, DateTime>(
                weekCounter,
                x,
                cumLeads.StartDate,
                cumLeads.EndDate));
        }
    }
}
public JsonResult CumLeadsParameters(CumLeadsReport cumLeads)
{
变量周=(cumLeads.EndDate-cumLeads.StartDate)。总天数/7;
如果(!(周>0))
{
//这意味着我只有不到一周的时间,所以计算天数,并将其作为一周和一周
var startDate=新日期时间(cumLeads.startDate.Year,
开始日期,月份,
cumLeads.StartDate.Day,0,0,0);
var ts=新的时间跨度(23,59,59);
var endDate=startDate.AddDays(6.0)。日期+ts;
var x=\u retailerStatsRepository.GetAllRetailerFormanFactoryCountrySelectedDates(
制造商Id,
国家Id,
开始日期,
结束日期);
}
其他的
{
cumLeads.StartDate=新日期时间(cumLeads.StartDate.Year,
开始日期,月份,
cumLeads.StartDate.Day,0,0,0);
而(周数>0)
{
weekCounter++;
var ts=新的时间跨度(23,59,59);
cumLeads.EndDate=cumLeads.StartDate.AddDays(6.0).Date+ts;
var x=\u retailerStatsRepository.GetAllRetailerFormanFactoryCountrySelectedDates(
制造商Id,
国家Id,
开始日期,
截止日期);
添加(新的元组)(
weekCounter,
x,,
开始日期,
截止日期);
}
}
}
/*注*/

例如,我已将日期
cumLeads.StartDate
cumLeads.EndDate
as
2013-08-01至2013-08-12
然后我的while条件满足两次,当第二次进入循环时,我不希望将日期设置回
01/08/2013
作为我的
startdate
我希望它作为
08/08/2013 00:00:000


任何建议都会有帮助。

我注意到的清理工作很少。请注意,我格式化了您的代码,使其在本网站上看起来更清晰,我并不是要暗示您应该做上述更改(以下是我的建议)

  • !(周数>0)
    会更好,因为
    周数>0)
    {
    //这意味着我只有不到一周的时间,所以计算天数,并将其作为一周和一周
    var startDate=cumLeads.startDate.Date;
    var endDate=startDate.AddDays(7.AddSeconds(-1);
    var x=\u retailerStatsRepository.GetAllRetailerFormanFactoryCountrySelectedDates(
    制造商Id,
    国家Id,
    开始日期,
    结束日期);
    }
    其他的
    {
    cumLeads.StartDate=cumLeads.StartDate.Date;
    而(周数>0)
    {
    weekCounter++;
    cumLeads.EndDate=cumLeads.StartDate.AddDays(7.AddSeconds(-1);
    var x=\u retailerStatsRepository.GetAllRetailerFormanFactoryCountrySelectedDates(
    制造商Id,
    国家Id,
    开始日期,
    截止日期);
    添加(新的元组)(
    weekCounter,
    x,,
    开始日期,
    截止日期);
    }
    }
    }
    
    我注意到几乎没有清理东西。请注意,我格式化了您的代码,使其在本网站上看起来更清晰,我并不是要暗示您应该做上述更改(以下是我的建议)

    • !(周数>0)
      会更好,因为
      周数>0)
      {
      //这意味着我只有不到一周的时间,所以计算天数,并将其作为一周和一周
      var startDate=cumLeads.startDate.Date;
      var endDate=startDate.AddDays(7.AddSeconds(-1);
      var x=\u retailerStatsRepository.GetAllRetailerFormanFactoryCountrySelectedDates(
      制造商Id,
      国家Id,
      开始日期,
      结束日期);
      }
      其他的
      {
      cumLeads.StartDate=cumLeads.StartDate.Date;
      而(周数>0)
      {
      weekCounter++;
      cumLeads.EndDate=cumLeads.StartDate.AddDays(7.AddSeconds(-1);
      var x=\u retailerStatsRepository.GetAllRetailerFormanFactoryCountrySelectedDates(
      制造商Id,
      国家Id,
      开始日期,
      截止日期);
      添加(新的元组)(
      weekCounter,
      x,,
      开始日期,
      截止日期);
      }
      }
      }
      
      cumLeads.StartDate=cumLeads.StartDate.AddDays(6.0).Date+ts
      放在循环末尾不起作用吗?不清楚您在这里问什么。似乎没有问题。将
      cumLeads.StartDate=cumLeads.StartDate.AddDays(6.0).Date+ts
      放在循环末尾不起作用吗?不清楚你在问什么。似乎没有问题。
      public JsonResult CumLeadsParameters(CumLeadsReport cumLeads)
      {
          var weeks = (cumLeads.EndDate - cumLeads.StartDate).TotalDays / 7;
      
          if (!(weeks > 0))
          {
              // means I have less than a week so calculate days and make it as a weeek and 
              var startDate = cumLeads.StartDate.Date;
              var endDate = startDate.AddDays(7).AddSeconds(-1);
              var x = _retailerStatsRepository.GetAllRetailersForManufacturerCountrySelectedDates(
                          manufacturer.Id,
                          country.Id,
                          startDate,
                          endDate);
          }
          else
          {
              cumLeads.StartDate = cumLeads.StartDate.Date;
              while (weeks > 0)
              {
                  weekCounter++;
                  cumLeads.EndDate = cumLeads.StartDate.AddDays(7).AddSeconds(-1);
                  var x = _retailerStatsRepository.GetAllRetailersForManufacturerCountrySelectedDates(
                              manufacturer.Id,
                              country.Id,
                              cumLeads.StartDate,
                              cumLeads.EndDate);
      
                  tuple.Add(new Tuple<int, IQueryable<RetailerStat>, DateTime, DateTime>(
                      weekCounter,
                      x,
                      cumLeads.StartDate,
                      cumLeads.EndDate));
              }
          }
      }