Beispiel #1
0
        private static void ImportParts(CarDealerContext context)
        {
            var xml = XDocument.Load(PartsPath);

            var parts = xml.XPathSelectElements("parts").Elements("part");

            Random rnd = new Random();

            foreach (var part in parts)
            {
                string name = part.Attribute("name").Value;

                decimal price = decimal.Parse(part.Attribute("price").Value);

                int quantity = int.Parse(part.Attribute("quantity").Value);

                int supplierId = rnd.Next(1, context.PartSuppliers.Count() + 1);

                PartSupplier supplier = context.PartSuppliers.FirstOrDefault(x => x.Id == supplierId);


                Part newPart = new Part()
                {
                    Name         = name,
                    Price        = price,
                    Quantity     = quantity,
                    PartSupplier = supplier
                };


                context.Parts.Add(newPart);
            }

            context.SaveChanges();
        }
Beispiel #2
0
        private static void ImportParts(CarDealerContext context)
        {
            var json = File.ReadAllText(PartsPath);

            var parts = JsonConvert.DeserializeObject <IEnumerable <PartDTO> >(json);

            Random rnd = new Random();

            foreach (var element in parts)
            {
                int supplierId = rnd.Next(1, context.PartSuppliers.Count() + 1);

                PartSupplier partSupplier = context.PartSuppliers.FirstOrDefault(x => x.Id == supplierId);


                Part part = new Part()
                {
                    Name         = element.Name,
                    Price        = element.Price,
                    Quantity     = element.Quantity,
                    PartSupplier = partSupplier
                };

                context.Parts.Add(part);
            }

            context.SaveChanges();
        }
        public bool DeletePartSupplier(int partSupplierId)
        {
            PartSupplier partSupplier = GetPartSupplier(partSupplierId);

            dataContext.PartSuppliers.DeleteOnSubmit(partSupplier);
            dataContext.SubmitChanges();
            return(dataContext.ChangeConflicts != null && dataContext.ChangeConflicts.Count == 0);
        }
        public bool AddNewPartSupplier(int supplierId, string partSku)
        {
            Part     part         = GetPart(partSku);
            Supplier supplier     = GetSupplier(supplierId);
            var      partSupplier = new PartSupplier
            {
                Part     = part,
                Supplier = supplier
            };

            dataContext.PartSuppliers.InsertOnSubmit(partSupplier);
            dataContext.SubmitChanges();
            return(dataContext.ChangeConflicts != null && dataContext.ChangeConflicts.Count == 0);
        }
Beispiel #5
0
        private static void ImportSuppliers(CarDealerContext context)
        {
            var json = File.ReadAllText(SuppliersPath);

            var suppliers = JsonConvert.DeserializeObject <IEnumerable <PartSupplierDTO> >(json);

            foreach (var element in suppliers)
            {
                PartSupplier partSupplier = new PartSupplier()
                {
                    Name       = element.Name,
                    IsImporter = element.IsImporter
                };

                context.PartSuppliers.Add(partSupplier);
            }

            context.SaveChanges();
        }
Beispiel #6
0
        private static void ImportSuppliers(CarDealerContext context)
        {
            var xml = XDocument.Load(SuppliersPath);

            var suppliers = xml.XPathSelectElements("suppliers").Elements("supplier");

            foreach (var supplier in suppliers)
            {
                string name       = supplier.Attribute("name").Value;
                bool   isImporter = bool.Parse(supplier.Attribute("is-importer").Value);

                PartSupplier supplierToAdd = new PartSupplier()
                {
                    Name       = name,
                    IsImporter = isImporter
                };

                context.PartSuppliers.Add(supplierToAdd);
            }


            context.SaveChanges();
        }