Exemple #1
0
        public ActionResult SalesReport(SalesReportVM model)
        {
            if (!ModelState.IsValid)
            {
                model.Referrers = SitesManager.GetReferrers();
                model.Sites     = SitesManager.GetSites();
                return(View(model));
            }

            List <KeyValuePair <string, List <ReferrerSalesInfoDT> > > data = new List <KeyValuePair <string, List <ReferrerSalesInfoDT> > >();

            if (model.ReferrerId != 0)
            {
                if (model.SiteId != 0)
                {
                    ReferrerDT referrer = SitesManager.GetReferrer(model.ReferrerId);
                    List <ReferrerSalesInfoDT> referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), model.ReferrerId, model.SiteId);
                    data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >(referrer.Name + " - " + SitesManager.GetSite(model.SiteId).Name, referrerData));
                }
                else
                {
                    ReferrerDT referrer = SitesManager.GetReferrer(model.ReferrerId);
                    List <ReferrerSalesInfoDT> referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), model.ReferrerId, model.SiteId);
                    data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >(referrer.Name + " - All Sites", referrerData));

                    foreach (var site in SitesManager.GetSites())
                    {
                        referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), model.ReferrerId, site.Id);
                        data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >(referrer.Name + " - " + site.Name, referrerData));
                    }
                }
            }
            else
            {
                if (model.SiteId != 0)
                {
                    string sitenName = SitesManager.GetSite(model.SiteId).Name;
                    List <ReferrerSalesInfoDT> referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), 0, model.SiteId);
                    data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >("All Websites - " + sitenName, referrerData));

                    foreach (ReferrerDT referrer in SitesManager.GetReferrers())
                    {
                        referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), referrer.Id, model.SiteId);
                        data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >(referrer.Name + " - " + sitenName, referrerData));
                    }
                }
                else
                {
                    List <ReferrerSalesInfoDT> referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), 0, model.SiteId);
                    data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >("All Websites - All Sites", referrerData));

                    foreach (var site in SitesManager.GetSites())
                    {
                        foreach (ReferrerDT referrer in SitesManager.GetReferrers())
                        {
                            referrerData = SitesManager.GetReferrerSiteSalesInfo(model.StartDate, model.EndDate, (DateGroupBy)Enum.Parse(typeof(DateGroupBy), model.GroupBy), referrer.Id, site.Id);
                            data.Add(new KeyValuePair <string, List <ReferrerSalesInfoDT> >(referrer.Name + " - " + site.Name, referrerData));
                        }
                    }
                }
            }
            ViewBag.Data = data;

            model.Referrers = SitesManager.GetReferrers();
            model.Sites     = SitesManager.GetSites();
            return(View(model));
        }