Пример #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);
        }
Пример #3
0
        public static Product GetShallowProduct(int productNumber, int supplierNumber)
        {
            Product product = new Product();

            using (FreeMarketEntities db = new FreeMarketEntities())
            {
                var productInfo = db.GetShallowProduct(productNumber, supplierNumber)
                                  .FirstOrDefault();

                product = new Product
                {
                    Activated           = productInfo.Activated,
                    DateAdded           = productInfo.DateAdded,
                    DateModified        = productInfo.DateModified,
                    DepartmentName      = productInfo.DepartmentName,
                    DepartmentNumber    = productInfo.DepartmentNumber,
                    Description         = productInfo.Description,
                    PricePerUnit        = productInfo.PricePerUnit,
                    ProductNumber       = productInfo.ProductNumber,
                    Size                = "",
                    SupplierName        = productInfo.SupplierName,
                    SupplierNumber      = productInfo.SupplierNumberID,
                    SpecialPricePerUnit = productInfo.SpecialPricePerUnit ?? productInfo.PricePerUnit,
                    RetailPricePerUnit  = productInfo.RetailPricePerUnit ?? productInfo.PricePerUnit,
                    Weight              = 0,
                    LongDescription     = productInfo.LongDescription,
                    IsVirtual           = productInfo.IsVirtual
                };

                product.SelectedCustodianNumber = db.ProductCustodians
                                                  .Where(c => c.ProductNumber == product.ProductNumber && c.SupplierNumber == product.SupplierNumber)
                                                  .FirstOrDefault()
                                                  .CustodianNumber;

                product.MainImageNumber = db.ProductPictures
                                          .Where(c => c.ProductNumber == product.ProductNumber && c.Dimensions == PictureSize.Medium.ToString())
                                          .Select(c => c.PictureNumber)
                                          .FirstOrDefault();

                product.SecondaryImageNumber = db.ProductPictures
                                               .Where(c => c.ProductNumber == product.ProductNumber && c.Dimensions == PictureSize.Small.ToString())
                                               .Select(c => c.PictureNumber)
                                               .FirstOrDefault();

                product.AdditionalImageNumber = db.ProductPictures
                                                .Where(c => c.ProductNumber == product.ProductNumber && c.Dimensions == PictureSize.Large.ToString())
                                                .Select(c => c.PictureNumber)
                                                .FirstOrDefault();

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

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

                product.SizeVariations = ProductSize.GetExistingProductSizes(productNumber, supplierNumber);
            }

            return(product);
        }