Ejemplo n.º 1
0
        public async Task <List <ProductModel> > GetProductsAsync(string part, string brand, string car, string search, int page)
        {
            var partsQuery = _context.Products
                             .Include(x => x.Brand).Include(x => x.CarProducts).ThenInclude(x => x.Car)
                             .Where(x => x.Price > 0m);

            if (car != "All")
            {
                partsQuery = partsQuery.Where(x => x.CarProducts.Any(c => c.Car.Model.ToUpper() == car.ToUpper()));
            }
            if (part != "All")
            {
                PartTypeEnum partType = (PartTypeEnum)Enum.Parse(typeof(PartTypeEnum), part);
                partsQuery = partsQuery.Where(x => x.PartType == partType);
            }
            if (brand != "All")
            {
                partsQuery = partsQuery.Where(x => x.Brand.Name.ToUpper() == brand.ToUpper());
            }
            if (!string.IsNullOrEmpty(search))
            {
                partsQuery = await SearchProductsAsync(search, partsQuery);
            }

            var products = partsQuery
                           .OrderBy(x => x.Name).ThenBy(x => x.Brand.Name)
                           .ThenBy(x => x.CarProducts.Select(c => c.Car).OrderBy(c => c.Make).FirstOrDefault())
                           .ThenBy(x => x.CarProducts.Select(c => c.Car).OrderBy(c => c.Model).FirstOrDefault())
                           .ThenBy(x => x.Years)
                           .ThenBy(x => x.Price);

            ViewData["partCount"] = products.Count();

            return(products.Page(page, 33).ToList());
        }
        /// <summary>
        /// Initializes a new instance of the <see cref="PartType"/> class.
        /// </summary>
        /// <param name="partType">A <see cref="PartTypeEnum"/> value that indicates the part type.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="partType"/> has an illegal value.</exception>
        /// <remarks>See Documentation/DocCLSIDs.h for the GUIDs that identify a document's SubType.</remarks>
        public PartType(PartTypeEnum partType)
        {
            Type = partType;

            switch (partType)
            {
                case PartTypeEnum.Generic:
                    Id = "4D29B490-49B2-11D0-93C3-7E0706000000";
                    Name = "Autodesk Inventor Part";
                    break;
                case PartTypeEnum.SheetMetal:
                    Id = "9C464203-9BAE-11D3-8BAD-0060B0CE6BB4";
                    Name = "Autodesk Inventor Sheet Metal Part";
                    break;
                case PartTypeEnum.GenericProxy:
                    Id = "92055419-B3FA-11D3-A479-00C04F6B9531";
                    Name = "Autodesk Inventor Generic Proxy Part";
                    break;
                case PartTypeEnum.CompatibilityProxy:
                    Id = "9C464204-9BAE-11D3-8BAD-0060B0CE6BB4";
                    Name = "Autodesk Inventor Compatibility Proxy Part";
                    break;
                case PartTypeEnum.CatalogProxy:
                    Id = "{9C88D3AF-C3EB-11D3-B79E-0060B0F159EF}";
                    Name = "Autodesk Inventor Catalog Proxy Part";
                    break;
                case PartTypeEnum.Molded:
                    Id = "4D8D80D4-F5B0-4460-8CEA-4CD222684469";
                    Name = "Autodesk Inventor Molded Part Document";
                    break;
                default:
                    throw new ArgumentOutOfRangeException("partType", string.Format(CultureInfo.InvariantCulture, "Illegal enum value {0}.", partType));
            }
        }
Ejemplo n.º 3
0
        public List <PartModel> GetParts(PartTypeEnum partTypeEnum)
        {
            var db = new StoreProcdureManagement();

            db.AddParameter("@PartTypeId", (int)partTypeEnum);
            return(db.RunSp <PartModel>(ConnectionString, "sp_Parts"));
        }
Ejemplo n.º 4
0
 public SubPart(string name, int partNumber, PartTypeEnum partype, CycleType cycleType, int month)
 {
     SubPartName   = name;
     SubPartNumber = partNumber;
     PartType      = partype;
     CycleType     = cycleType;
     CycleInMonth  = month;
 }
        /// <summary>
        /// Initializes a new instance of the <see cref="PartType"/> class.
        /// </summary>
        /// <param name="partType">A <see cref="PartTypeEnum"/> value that indicates the part type.</param>
        /// <exception cref="ArgumentOutOfRangeException"><paramref name="partType"/> has an illegal value.</exception>
        /// <remarks>See Documentation/DocCLSIDs.h for the GUIDs that identify a document's SubType.</remarks>
        public PartType(PartTypeEnum partType)
        {
            Type = partType;

            switch (partType)
            {
            case PartTypeEnum.Generic:
                Id   = "4D29B490-49B2-11D0-93C3-7E0706000000";
                Name = "Autodesk Inventor Part";
                break;

            case PartTypeEnum.SheetMetal:
                Id   = "9C464203-9BAE-11D3-8BAD-0060B0CE6BB4";
                Name = "Autodesk Inventor Sheet Metal Part";
                break;

            case PartTypeEnum.GenericProxy:
                Id   = "92055419-B3FA-11D3-A479-00C04F6B9531";
                Name = "Autodesk Inventor Generic Proxy Part";
                break;

            case PartTypeEnum.CompatibilityProxy:
                Id   = "9C464204-9BAE-11D3-8BAD-0060B0CE6BB4";
                Name = "Autodesk Inventor Compatibility Proxy Part";
                break;

            case PartTypeEnum.CatalogProxy:
                Id   = "{9C88D3AF-C3EB-11D3-B79E-0060B0F159EF}";
                Name = "Autodesk Inventor Catalog Proxy Part";
                break;

            case PartTypeEnum.Molded:
                Id   = "4D8D80D4-F5B0-4460-8CEA-4CD222684469";
                Name = "Autodesk Inventor Molded Part Document";
                break;

            default:
                throw new ArgumentOutOfRangeException("partType", string.Format(CultureInfo.InvariantCulture, "Illegal enum value {0}.", partType));
            }
        }
Ejemplo n.º 6
0
 public PartType(PartTypeEnum typeId, string name, string url)
 {
     TypeId         = typeId;
     TypeName       = name;
     TypePictureUrl = url;
 }
Ejemplo n.º 7
0
 public Part(string name, string description, PartTypeEnum type)
 {
     Name        = name;
     Description = description;
     Type        = type;
 }
Ejemplo n.º 8
0
 public Part()
 {
     Name        = "";
     Description = "";
     Type        = PartTypeEnum.ptNone;
 }
Ejemplo n.º 9
0
        public async Task <IActionResult> AddMultipleProducts()
        {
            var productList = new List <ProductModel>();

            var excelFile = Request.Form.Files.FirstOrDefault(x => x.FileName.Contains(".xlsx"));

            if (excelFile != null)
            {
                var package   = new ExcelPackage(excelFile.OpenReadStream());
                var worksheet = package.Workbook.Worksheets.FirstOrDefault();

                for (int i = worksheet.Dimension.Start.Row + 1; i < worksheet.Dimension.End.Row + 1; i++)
                {
                    var row = worksheet.Cells[i, 1, i, 9].ToArray();

                    if (row != null && row.Length > 0)
                    {
                        string PartNumber   = row[0].Text;
                        var    existingPart = await _context.Products.FirstOrDefaultAsync(x => x.PartNumber == PartNumber);

                        if (existingPart == null)
                        {
                            string     Name        = row[1].Text;
                            string     Description = row[2].Value.ToString();
                            BrandModel Brand       = await _context.Brand.FirstOrDefaultAsync(x => x.Name.Replace(" ", "").ToUpper() == row[3].Text.Replace(" ", "").ToUpper());

                            PartTypeEnum PartType = (PartTypeEnum)Enum.Parse(typeof(PartTypeEnum), row[4].Text);
                            decimal      Price    = decimal.Parse(row[5].Text);

                            string CarMake  = row[6].Text;
                            string CarModel = row[7].Text;
                            var    carFound = await _context.Car.FirstOrDefaultAsync(x => x.Make.Replace(" ", "").Replace("-", "").ToUpper() == CarMake.Replace(" ", "").Replace("-", "").ToUpper() &&
                                                                                     x.Model.Replace(" ", "").Replace("-", "").ToUpper() == CarModel.Replace(" ", "").Replace("-", "").ToUpper());

                            CarModel Car = null;

                            if (carFound != null)
                            {
                                Car = carFound;
                            }
                            else
                            {
                                Car = new CarModel
                                {
                                    Make  = CarMake,
                                    Model = CarModel
                                };
                                _context.Car.Add(Car);
                                await _context.SaveChangesAsync();
                            }

                            string Years = (string.IsNullOrEmpty(row[8].Text) || row[8].Text.ToUpper() == "ALL") ? null : row[8].Text.ToUpper().Replace(" ", "").Replace("-", " - ").Replace("UP", "Present");

                            var Product = new ProductModel
                            {
                                PartNumber  = PartNumber,
                                Name        = Name,
                                Description = Description,
                                Brand       = Brand,
                                PartType    = PartType,
                                Price       = Price,
                                Years       = Years,
                                Shipping    = await CalculateShippingAsync(Price)
                            };

                            CarProduct CarProduct = new CarProduct
                            {
                                CarId     = Car.CarId,
                                Car       = Car,
                                ProductId = Product.PartId,
                                Product   = Product
                            };

                            Product.CarProducts = new List <CarProduct>();
                            Product.CarProducts.Add(CarProduct);

                            Product.DateAdded = DateTime.UtcNow;

                            productList.Add(Product);
                        }
                    }
                    else
                    {
                        i = 999999;
                    }
                }
                _context.Products.AddRange(productList);
            }

            var imagesUploaded = 0;
            var allImages      = Request.Form.Files.Where(x => !x.FileName.Contains(".xlsx"));
            var productNumbers = allImages.Select(x => x.FileName.Split('(')[0]).Distinct();
            var products       = new List <ProductModel>();

            foreach (var productNumber in productNumbers)
            {
                var product = await _context.Products.Include(x => x.Images).FirstOrDefaultAsync(x => x.PartNumber.ToUpper() == productNumber.ToUpper());

                if (product != null)
                {
                    var newImageList = new List <ImageModel>();

                    foreach (var image in allImages.Where(x => x.FileName.ToUpper().Contains(product.PartNumber.ToUpper())))
                    {
                        newImageList.Add(new ImageModel
                        {
                            Name        = image.FileName.Split('.')[0],
                            Description = image.FileName,
                            Bytes       = ConvertToBytes(image)
                        });
                    }

                    product.Images = newImageList;
                }
            }

            await _context.SaveChangesAsync();

            TempData["Message"] = $"Successfully added {productList.Count} products to the store. Successfully uploaded {imagesUploaded} images.";

            return(RedirectToAction("AddProduct", new { section = "PART" }));
        }