示例#1
0
        public ActionResult Index(string sortBy, string searchText, int priceMinRange=0, int priceMaxRange=25000)
        {
            AppDomain.CurrentDomain.UnhandledException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
           // Application.ThreadException += new UnhandledExceptionEventHandler(currentDomain_UnhandledException);
             #region Unhandled Exception Test
            //string testUnhandle = null;
            //testUnhandle.ToString();

            #endregion

            

            #region List to Array
            //List<Product> baseList = db.Products.ToList();
            //// int arraySize= baseList.Count;
            //Product[] productArray = baseList.ToArray();
            //Array productDestinationArray = Array.CreateInstance(typeof(Product), baseList.Count);
            //Array.Copy(productArray, productArray.GetLowerBound(0) + 5
            //    , productDestinationArray, productDestinationArray.GetLowerBound(0), productDestinationArray.GetLowerBound(0) + 25);

            //Array.ConstrainedCopy(productArray, productArray.GetLowerBound(0) + 5
            //  , productDestinationArray, productDestinationArray.GetLowerBound(0), productDestinationArray.GetLowerBound(0) + 5);
             
         

            #endregion

            #region List to XML
            List<Product> xmlList = db.Products.ToList();
            var xmlFromList = new XElement("Products"
                , xmlList.Select(x => new XElement("Product"
                , new  XAttribute("Id", x.ID)
                , new XAttribute("Name", x.Name)
                , new XAttribute("Price", x.Price))));
               
            #endregion
            IQueryable iqueryable;
            oLearner.Equals(oLearner);
            var hashCode= oLearner.GetHashCode();
            var typeCurrentInstance= oLearner.GetType();
            var objStr= oLearner.ToString();

            //FormCollection fc = new FormCollection();
            //fc.Add("oLearner",oLearner.ToString());
           // ArrayList aList = new ArrayList();



             
            Logger.logger.Info("Inside  Store Index Info");
            Logger.logger.Fatal("Inside  Store Index Fatal");
            Logger.logger.Error("Inside  Store Index Error");
            Logger.logger.Debug("Inside  Store Index Debug");
            Logger.logger.Warn("Inside  Store Index Warn");
           
            //string sortBy2= null;
            //if (int id == 1)
            //    sortBy = "Name"; 


            #region Locating Object for an element- IComparable IndexOf has to implement Equals n GetHashCode
            Product prod = new Product();

            prod = db.Products.Find(20);
            int locateName = db.Products.ToList().IndexOf(prod);
            List<Product> productsLambda = db.Products.ToList();
            #endregion





            if (sortBy != null && !"".Equals(sortBy))
            {

                

                PriceComparer pComparer = new PriceComparer();
                NameComparer nComparer = new NameComparer();
                //List<Product> IndexofList = db.Products.ToList();
              



                Product p1; Product p2;
                //Comparator pcomparator = new Comparator(StoresController.compare(p1,p2));

                //test(new Comparator(Compare));
                //test(new Comparator(Compare1));
                //SortedList.Sort(pComparer);
                
                //db.Products.ToList().IndexOf(prod);
                if (sortBy == "ID")
                {
                    List<Product> SortedList = db.Products.ToList();
                    SortedList.Sort();
                    return View(SortedList);
                }
                if (sortBy == "Price")
                {
                    List<Product> SortedList = db.Products.ToList();
                    #region Interface with one method 
                    //SortedList.Sort(pComparer);
                    #endregion
                    #region Anonymous Methods
                    //SortedList.Sort(delegate(Product x, Product y)
                    //                            {
                                                    
                    //                                    if (x.Price > y.Price)
                    //                                         return 1;
                    //                                    else if (x.Price < y.Price)
                    //                                        return -1;
                    //                                    else
                    //                                        return 0;

                    //                            });
                    #endregion
                    #region Named Delegate
                    //SortedList.Sort(Compare);
                    #endregion
                    #region Lambda Expressions
                    SortedList.Sort((p3,p4) => p3.Price.CompareTo(p4.Price));
                    SortedList.OrderByDescending(p => p.Price).ToList();
                    #endregion
                    return View(SortedList);
                }
                else if (sortBy == "Name") 
                {
                    List<Product> SortedList = db.Products.ToList();
                    SortedList.Sort(nComparer);
                    SortedList.Reverse();
                    return View(SortedList);
                }
                else
                {
                    return View(db.Products.ToList());
                }
            }
            else
                {
                    var products = db.Products.ToList();
                    if (searchText != null && !"".Equals(searchText))
                    {
                        products = products
                       .Where(p => p.Name.Contains(searchText) && (p.Price > priceMinRange && p.Price <= priceMaxRange)).ToList();
                        List<Product> prodList = products.ToList();
                        

                        //var productPrice = db.Products.
                        //  Where(p => (p.Price > 0 && p.Price <= 10)).ToList();
                    }
                    else
                    {
                        products = products
                      .Where(p => (p.Price > priceMinRange && p.Price <= priceMaxRange)).ToList();
                        List<Product> prodList = products.ToList();
                        

                    }

                        return View("Index", products);

                }

        }
示例#2
0
        public void test(Comparator comparator)
        {
             List<Product> IndexofList = db.Products.ToList();

             Product p1 = new Product();
             p1.Price = 10;
             Product p2 = new Product();
             p2.Price = 20;
             comparator(p1, p2);

        }
示例#3
0
        public static int Compare1(Product x, Product y)
        {
            Console.Write("Delegate definition2");
            try
            {

                if (x.Price < y.Price)
                    return 1;
                else if (x.Price > y.Price)
                    return -1;
                else
                    return 0;
            }
            catch (ApplicationException appEx)
            {
                throw appEx;
            }
        }
示例#4
0
        public ActionResult SearchIndex(string sortBy, string searchOption ,string searchText,FormCollection formcol)
         {
             
             //string sortBy2= null;
             //if (int id == 1)
             //    sortBy = "Name";


             if (sortBy != null && !"".Equals(sortBy))
             {

                 Product prod = new Product();


                 prod = db.Products.Find(20);


                 PriceComparer pComparer = new PriceComparer();
                 NameComparer nComparer = new NameComparer();
                 List<Product> IndexofList = db.Products.ToList();
                 int locateName = db.Products.ToList().IndexOf(prod);
                 db.Products.ToList().IndexOf(prod);
                 if (sortBy == "ID")
                 {
                     List<Product> SortedList = db.Products.ToList();
                     SortedList.Sort();
                     return View("Index",SortedList);
                 }
                 if (sortBy == "Price")
                 {
                     List<Product> SortedList = db.Products.ToList();
                     SortedList.Sort(pComparer);
                     return View("Index",SortedList);
                 }
                 else if (sortBy == "Name")
                 {
                     List<Product> SortedList = db.Products.ToList();
                     SortedList.Sort(nComparer);
                     return View("Index",SortedList);
                 }
                 else
                 {
                     return View("Index",db.Products.ToList());
                 }
             }
             else
                 if (searchOption != null && searchText != null)
                 {
                     var products = db.Products
                    .Where(p => p.Name.Contains(searchText)).ToList();
                     List<Product> prodList = products.ToList();

                     var productPrice = db.Products.
                       Where(p => (p.Price > 0 && p.Price <= 10)).ToList();

                     return View("Index", productPrice);

                   
                 }
                 else
                 {
                     return View("Index",db.Products.ToList());
                 }

         }