Ejemplo n.º 1
0
        public ActionResult Index(DateTime? start, DateTime? end, string sort)
        {
            QuoteHome quoteHome = new QuoteHome
            {
                QuoteFilterFrom = start ?? DateTime.Today.AddMonths(-3),
                QuoteFilterTo = end ?? DateTime.Today.AddDays(1)
            };

            quoteHome.Quotes = _quoteManager.GetQuotes(quoteHome.QuoteFilterFrom, quoteHome.QuoteFilterTo)
                .Select(i => Mapper.Map<Models.Quote.Quote>(i))
                .OrderByDescending(i => i.QuoteId)
                .ToList();

            if (!string.IsNullOrEmpty(sort))
            {
                if (sort == "client")
                {
                    quoteHome.Quotes = quoteHome.Quotes.OrderBy(i => i.ClientName).ToList();
                }
                else if (sort == "price")
                {
                    quoteHome.Quotes = quoteHome.Quotes.OrderByDescending(i => i.EstimatedPrice).ToList();
                }
                else if (sort == "awarded")
                {
                    quoteHome.Quotes = quoteHome.Quotes.OrderByDescending(i => i.Awarded)
                        .ThenBy(i => i.QuoteId)
                        .ToList();
                }
                else
                {
                    quoteHome.Quotes = quoteHome.Quotes.OrderByDescending(i => i.QuoteId).ToList();
                }
            }

            quoteHome.TagFrequency = Mapper.Map<List<QuoteTagFrequency>>(_quoteManager.GetTagFrequency(20));

            ClientManager clientManager = new ClientManager();
            quoteHome.Clients = Mapper.Map<List<Models.Client.Client>>(clientManager.GetClients())
                .OrderBy(i => i.ClientName)
                .ToList();

            return View(quoteHome);
        }