コード例 #1
0
        public Dictionary <string, int> GetCountPerDateBy(string productType, DateTime? @from = null, DateTime?to = null)
        {
            if (to == null)
            {
                to = DateTime.Now;
            }

            if (from == null)
            {
                from = DateTime.Now.AddDays(-9);
            }


            var response = _receiptRepository.GetCountPerDateBy(productType, from, to);

            DateTime aux = DateTime.Now;

            if (from == null)
            {
                string strfrom = response.Min(r => r.Key) ?? DateTime.Now.ToString("yyyy-MM-dd");
                aux = new DateTime(Convert.ToInt32(strfrom.Split('-')[0]), Convert.ToInt32(strfrom.Split('-')[1]), Convert.ToInt32(strfrom.Split('-')[2]));
            }
            else
            {
                aux = new DateTime(from.Value.Year, from.Value.Month, from.Value.Day);
            }

            while (aux < to)
            {
                if (response.ContainsKey(aux.ToString("yyyy-MM-dd")))
                {
                }
                else
                {
                    response.Add(aux.ToString("yyyy-MM-dd"), 0);
                }

                aux = aux.AddDays(1);
            }

            return(response);
        }