Exemple #1
0
        public ActionResult Index(String name)
        {
            var suppliername          = name;
            var supplierServiceClient = new ServiceReference1.SupplierServiceClient();

            List <SupplierTypeModel> response = new List <SupplierTypeModel>();

            List <ServiceReference1.SupplierType> listSuppliers = supplierServiceClient.GetSupplierByName(suppliername);

            if (listSuppliers == null)
            {
                Session["SupplierFound"] = 0;
                return(View("Index"));
            }
            else
            {
                foreach (var s in listSuppliers)
                {
                    SupplierTypeModel supplier = new SupplierTypeModel()
                    {
                        CompanyName   = s.CompanyName,
                        SupplierId    = s.SupplierId,
                        ContactName   = s.ContactName,
                        ContactTitle  = s.ContactTitle,
                        Country       = s.Country,
                        ExtensionData = s.ExtensionData
                    };
                    response.Add(supplier);
                }
                Session["SupplierFound"] = 1;
                return(View("Index", response));
            }
        }
Exemple #2
0
        public ActionResult Index(string name, String listCategories, String listSuppliers, bool inStock, bool discontinued)
        {
            var productServiceClient = new ServiceReference3.ProductServiceClient();

            var response = new List <ProductDetailModel>();


            var supplierServiceClient = new ServiceReference1.SupplierServiceClient();

            var  categoryServiceClient = new ServiceReference2.CategoryServiceClient();
            long?supplierId;
            long?categoryId;

            try
            {
                supplierId = supplierServiceClient.GetSupplierByName(listCategories).Single().SupplierId;
            }
            catch (Exception e)
            {
                supplierId = null;
            }

            try
            {
                categoryId = categoryServiceClient.GetCategoryByName(listSuppliers).Single().CategoryId;
            }
            catch (Exception e)
            {
                categoryId = null;
            }

            var listProducts = productServiceClient.GetProducts(name, supplierId, categoryId, inStock, discontinued);

            if (!listProducts.Any())
            {
                Session["ProductFound"] = 0;
                return(View("Index"));
            }

            response.AddRange(listProducts.Select(s => new ProductDetailModel()
            {
                UnitsInStock = s.UnitsInStock, CategoryId = s.CategoryId, Discontinued = s.Discontinued, ProductName = s.ProductName, QuantityPerUnit = s.QuantityPerUnit,
                SupplierId   = s.SupplierId, ReorderLevel = s.ReorderLevel, UnitPrice = s.UnitPrice, UnitsOnOrder = s.UnitsOnOrder
            }));
            Session["ProductFound"] = 1;



            List <string> listcategories = new List <string>();
            var           lc             = categoryServiceClient.GetCategories();

            foreach (var c in lc)
            {
                listcategories.Add(c.CategoryName);
            }

            if (listcategories.Count == 0)
            {
                listcategories.Add("no categories");
            }

            List <string> listSuppliers2 = new List <string>();
            var           ls             = supplierServiceClient.GetSuppliers();

            foreach (var c in ls)
            {
                listSuppliers2.Add(c.CompanyName);
            }

            if (listSuppliers2.Count == 0)
            {
                listSuppliers2.Add("no categories");
            }

            ViewBag.categories = listcategories;
            ViewBag.suppliers  = listSuppliers2;


            return(View("Index", response));
        }