Пример #1
0
        public void InitializeDropDowns(string mode)
        {
            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                if (mode == "edit")
                {
                    Departments = db.Departments
                                  .Select(c => new SelectListItem
                    {
                        Text     = "(" + c.DepartmentNumber + ") " + c.DepartmentName,
                        Value    = c.DepartmentNumber.ToString(),
                        Selected = (c.DepartmentNumber == DepartmentNumber) ? true : false
                    })
                                  .ToList();

                    Custodians = db.Custodians
                                 .Select(c => new SelectListItem
                    {
                        Text     = "(" + c.CustodianNumber + ") " + c.CustodianName,
                        Value    = c.CustodianNumber.ToString(),
                        Selected = c.CustodianNumber == SelectedCustodianNumber ? true : false
                    })
                                 .ToList();
                }
                else
                {
                    Departments = db.Departments
                                  .Select(c => new SelectListItem
                    {
                        Text  = "(" + c.DepartmentNumber + ") " + c.DepartmentName,
                        Value = c.DepartmentNumber.ToString(),
                    })
                                  .ToList();
                }

                if (mode == "create")
                {
                    Suppliers = db.Suppliers
                                .Select(c => new SelectListItem
                    {
                        Text  = "(" + c.SupplierNumber + ") " + c.SupplierName,
                        Value = c.SupplierNumber.ToString()
                    })
                                .ToList();

                    Custodians = db.Custodians
                                 .Select(c => new SelectListItem
                    {
                        Text  = "(" + c.CustodianNumber + ") " + c.CustodianName,
                        Value = c.CustodianNumber.ToString(),
                    })
                                 .ToList();

                    SizeVariations = ProductSize.GetNewProductSizes();
                }
            }
        }
Пример #2
0
        public static Product GetNewProduct()
        {
            Product product = new Product();

            product.DateAdded = DateTime.Now;

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                product.Departments = db.Departments
                                      .Select(c => new SelectListItem
                {
                    Text  = "(" + c.DepartmentNumber + ")" + c.DepartmentName,
                    Value = c.DepartmentNumber.ToString()
                })
                                      .ToList();

                product.Suppliers = db.Suppliers
                                    .Select(c => new SelectListItem
                {
                    Text  = "(" + c.SupplierNumber + ")" + c.SupplierName,
                    Value = c.SupplierNumber.ToString()
                })
                                    .ToList();

                product.Custodians = db.Custodians
                                     .Select(c => new SelectListItem
                {
                    Text  = "(" + c.CustodianNumber + ") " + c.CustodianName,
                    Value = c.CustodianNumber.ToString(),
                })
                                     .ToList();

                product.SizeVariations = ProductSize.GetNewProductSizes();
            }

            return(product);
        }