Beispiel #1
0
        private static void ImportLenses(PhotographyWorkshopsContext context)
        {
            string json       = File.ReadAllText(LensesPath);
            var    lensesDtos = JsonConvert.DeserializeObject <IEnumerable <LensDto> >(json);

            foreach (var lensesDto in lensesDtos)
            {
                if (lensesDto.Make == null || lensesDto.FocalLength == 0 || lensesDto.MaxAperture == 0 || lensesDto.CompatibleWith == null)
                {
                    Console.WriteLine(Error);
                    continue;
                }

                Lens lens = new Lens()
                {
                    Make           = lensesDto.Make,
                    FocalLength    = lensesDto.FocalLength,
                    MaxAperture    = lensesDto.MaxAperture,
                    CompatibleWith = lensesDto.CompatibleWith
                };

                context.Lenses.Add(lens);
                Console.WriteLine($"Successfully imported {lens.Make} {lens.FocalLength}mm f{lens.MaxAperture}");
            }

            context.SaveChanges();
        }
Beispiel #2
0
        private static void Importhotographers(PhotographyWorkshopsContext context)
        {
            string json = File.ReadAllText(PhotographersPath);
            var    photographersDtos = JsonConvert.DeserializeObject <IEnumerable <PhotographerDto> >(json);

            foreach (var photographersDto in photographersDtos)
            {
                if (photographersDto.FirstName == null || photographersDto.LastName == null || photographersDto.Phone == null || photographersDto.Lenses.Count == 0)
                {
                    Console.WriteLine(Error);
                    continue;
                }

                Photographer photographer = new Photographer()
                {
                    FirstName = photographersDto.FirstName,
                    LastName  = photographersDto.LastName,
                    Phone     = photographersDto.Phone
                };

                if (photographer.FirstName == null || photographer.LastName == null || photographer.Phone == null)
                {
                    Console.WriteLine(Error);
                    continue;
                }

                context.Photographers.Add(photographer);

                Console.WriteLine($"Successfully imported {photographer.FirstName} {photographer.LastName} | Lenses: {photographer.Lenses.Count}");
            }

            context.SaveChanges();
        }
Beispiel #3
0
        private static void ImportCameras(PhotographyWorkshopsContext context)
        {
            string json        = File.ReadAllText(CamerasPath);
            var    camerasDtos = JsonConvert.DeserializeObject <IEnumerable <CameraDto> >(json);

            foreach (var camerasDto in camerasDtos)
            {
                if (camerasDto.Make == null || camerasDto.MinIso == 0 || camerasDto.Model == null)
                {
                    Console.WriteLine(Error);
                    continue;
                }

                Camera camera = new Camera()
                {
                    CameraType      = camerasDto.Type,
                    Make            = camerasDto.Make,
                    Model           = camerasDto.Model,
                    MaxIso          = camerasDto.MaxIso,
                    MinIso          = camerasDto.MinIso,
                    MaxShutterSpeed = camerasDto.MaxShutterSpeed,
                };

                context.Cameras.Add(camera);
                Console.WriteLine($"Successfully imported {camera.CameraType} {camera.Make} {camera.Model}");
            }

            context.SaveChanges();
        }
        private static void ImportLensesFromJSON(PhotographyWorkshopsContext context)
        {
            var json   = File.ReadAllText(ImportLensesPath);
            var lenses = JsonConvert.DeserializeObject <IEnumerable <LensDTO> >(json);

            foreach (var lens in lenses)
            {
                if ((lens.Make == null) ||
                    (lens.FocalLength == null) ||
                    (lens.MaxAperture == null) ||
                    (lens.CompatibleWith == null))
                {
                    Console.WriteLine("Error. Invalid data provided");
                    continue;
                }

                var lensEntity = new Lens()
                {
                    Make           = lens.Make,
                    FocalLength    = IfNoIntValueReturnNull(lens.FocalLength),
                    MaxAperture    = IfNoFloatValueReturnNull(lens.MaxAperture),
                    CompatibleWith = lens.CompatibleWith
                };

                context.Lenses.Add(lensEntity);
                Console.WriteLine($"Successfully imported {lens.Make} {lens.FocalLength}mm f{lens.MaxAperture}");
            }

            context.SaveChanges();
        }
        private static void ImportAccessoriesFromXML(PhotographyWorkshopsContext context)
        {
            var    xml         = XDocument.Load(ImportAccessoriesPath);
            var    accessories = xml.XPathSelectElements("accessories/accessory");
            Random rng         = new Random();

            foreach (var accessory in accessories)
            {
                var accessoryName = accessory.Attribute("name");

                if ((String.IsNullOrWhiteSpace(accessoryName.Value)) ||
                    (accessoryName == null))
                {
                    Console.WriteLine("Error. Invalid data provided");
                    continue;
                }

                int randomPhotographerId = rng.Next(1, context.Photographers.Count());

                var accessoryEntity = new Accessory()
                {
                    Name  = accessoryName.Value,
                    Owner = context.Photographers.Where(i => i.Id == randomPhotographerId).SingleOrDefault()
                };

                context.Accessories.Add(accessoryEntity);
                Console.WriteLine($"Successfully imported {accessoryName.Value}");
            }

            context.SaveChanges();
        }
        private static void ImportCamerasFromJSON(PhotographyWorkshopsContext context)
        {
            var json    = File.ReadAllText(ImportCamerasPath);
            var cameras = JsonConvert.DeserializeObject <IEnumerable <CameraDTO> >(json);

            foreach (var camera in cameras)
            {
                if ((camera.Type == null) ||
                    (camera.Make == null) ||
                    (camera.Model == null) ||
                    (camera.MinISO == null))
                {
                    Console.WriteLine("Error. Invalid data provided");
                    continue;
                }

                if (int.Parse(camera.MinISO) < 100)
                {
                    camera.MinISO = null;
                }

                if (camera.Type == "DSLR")
                {
                    var cameraEntity = new Camera()
                    {
                        Type            = camera.Type,
                        Make            = camera.Make,
                        Model           = camera.Model,
                        MinISO          = IfNoIntValueReturnNull(camera.MinISO),
                        MaxISO          = IfNoIntValueReturnNull(camera.MaxISO),
                        MaxShutterSpeed = IfNoIntValueReturnNull(camera.MaxShutterSpeed)
                    };

                    context.Cameras.Add(cameraEntity);
                    Console.WriteLine($"Successfully imported {camera.Type} {camera.Make} {camera.Model}");
                }
                else if (camera.Type == "Mirrorless")
                {
                    var cameraEntity = new Camera()
                    {
                        Type               = camera.Type,
                        Make               = camera.Make,
                        Model              = camera.Model,
                        IsFullFrame        = IfNoBoolValueReturnNull(camera.IsFullFrame),
                        MinISO             = IfNoIntValueReturnNull(camera.MinISO),
                        MaxISO             = IfNoIntValueReturnNull(camera.MaxISO),
                        MaxVideoResolution = camera.MaxVideoResolution,
                        MaxFrameRate       = IfNoIntValueReturnNull(camera.MaxFrameRate)
                    };

                    context.Cameras.Add(cameraEntity);
                    Console.WriteLine($"Successfully imported {camera.Type} {camera.Make} {camera.Model}");
                }
            }

            context.SaveChanges();
        }
        private static void ImportPhotographersFromJSON(PhotographyWorkshopsContext context)
        {
            var    json          = File.ReadAllText(ImportPhotographersPath);
            var    photographers = JsonConvert.DeserializeObject <IEnumerable <PhotographerDTO> >(json);
            Random rng           = new Random();

            foreach (var photographer in photographers)
            {
                if ((photographer.FirstName == null) ||
                    (photographer.LastName == null) ||
                    (photographer.Phone == null) ||
                    (photographer.Lenses == null))
                {
                    Console.WriteLine("Error. Invalid data provided");
                    continue;
                }

                HashSet <Lens> lenses = new HashSet <Lens>();

                foreach (var lensId in photographer.Lenses)
                {
                    var lens = context.Lenses.Where(i => i.Id == lensId).SingleOrDefault();

                    if (lens == null)
                    {
                        continue;
                    }

                    lenses.Add(lens);
                }

                var photographerEntity = new Photographer()
                {
                    FirstName       = photographer.FirstName,
                    LastName        = photographer.LastName,
                    Phone           = photographer.Phone,
                    Lenses          = lenses,
                    PrimaryCamera   = context.Cameras.Find(rng.Next(1, context.Cameras.Count())),
                    SecondaryCamera = context.Cameras.Find(rng.Next(1, context.Cameras.Count()))
                };

                context.Photographers.Add(photographerEntity);
                Console.WriteLine($"Successfully imported {photographer.FirstName} {photographer.LastName} | {lenses.Count()}");
            }

            context.SaveChanges();
        }
Beispiel #8
0
        private static void ImportWorkshops(PhotographyWorkshopsContext context)
        {
            XDocument xmlDocument = XDocument.Load(WorkshopsPath);

            var workshopsXmls = xmlDocument.XPathSelectElements("workshops/workshop");

            foreach (var workshopsXml in workshopsXmls)
            {
                var             workshopName        = workshopsXml.Attribute("name").Value;
                var             workshopStartDate   = DateTime.Parse(workshopsXml.Attribute("start-date").Value);
                var             workshopEndDate     = DateTime.Parse(workshopsXml.Attribute("end-date").Value);
                var             workshopLocation    = workshopsXml.Attribute("location").Value;
                var             workshopPrice       = decimal.Parse(workshopsXml.Attribute("price").Value);
                var             trainer             = workshopsXml.Element("trainer").Value;
                List <XElement> participants        = new List <XElement>();
                var             participant         = workshopsXml.XPathSelectElement("participants/participant");
                var             participantFullName = participant.Attribute("first-name") + " " +
                                                      participant.Attribute("last-name");

                participants.Add(participant);

                if (workshopName == null || workshopPrice == null || workshopLocation == null || trainer == null)
                {
                    Console.WriteLine(Error);
                    continue;
                }

                Workshop workshop = new Workshop()
                {
                    Name                = workshopName,
                    StartDate           = workshopStartDate,
                    EndDate             = workshopEndDate,
                    Location            = workshopLocation,
                    PricePerParticipant = workshopPrice,
                };

                context.Workshops.Add(workshop);
                Console.WriteLine($"Successfully imported {workshop.Name}");
            }

            context.SaveChanges();
        }
Beispiel #9
0
        private static void ImportAccessoires(PhotographyWorkshopsContext context)
        {
            XDocument xmlDocument = XDocument.Load(AccessoiresPath);

            var accessoriesXmls = xmlDocument.XPathSelectElements("accessories/accessory");

            foreach (var accessoriesXml in accessoriesXmls)
            {
                var accessoryName = accessoriesXml.Attribute("name").Value;

                Accessory accessory = new Accessory()
                {
                    Name = accessoryName
                };

                context.Accessories.Add(accessory);

                Console.WriteLine($"Successfully imported {accessory.Name}");
            }

            context.SaveChanges();
        }
        private static void ImportWorkshopsFromXML(PhotographyWorkshopsContext context)
        {
            var xml       = XDocument.Load(ImportWorkshopsPath);
            var workshops = xml.XPathSelectElements("workshops/workshop");

            foreach (var workshop in workshops)
            {
                var workshopName      = workshop.Attribute("name");
                var workshopStartDate = workshop.Attribute("start-date");
                var workshopEndDate   = workshop.Attribute("end-date");
                var workshopLocation  = workshop.Attribute("location");
                var workshopPrice     = workshop.Attribute("price");
                var workshopTrainer   = workshop.Element("trainer");

                if ((workshopName == null) ||
                    (workshopLocation == null) ||
                    (workshopPrice == null) ||
                    (workshopTrainer == null))
                {
                    Console.WriteLine("Error. Invalid data provided");
                    continue;
                }

                string[] workshopTrainerNames     = workshopTrainer.Value.Trim().Split(' ').ToArray();
                string   workshopTrainerFirstName = workshopTrainerNames[0].ToString();
                string   workshopTrainerLastName  = workshopTrainerNames[1].ToString();

                var workshopParticipants            = workshop.XPathSelectElements("participants/participant");
                HashSet <Photographer> participants = new HashSet <Photographer>();

                foreach (var workshopParticipant in workshopParticipants)
                {
                    string firstName = workshopParticipant.Attribute("first-name").Value;
                    string lastName  = workshopParticipant.Attribute("last-name").Value;

                    var participant = context.Photographers
                                      .Where(fn => fn.FirstName == firstName)
                                      .Where(ln => ln.LastName == lastName)
                                      .FirstOrDefault();

                    if (participant == null)
                    {
                        continue;
                    }

                    participants.Add(participant);
                }

                var workshopEntity = new Workshop()
                {
                    Name                = workshopName.Value,
                    StartDate           = IfNoDateTimeValueReturnNull(workshopStartDate.Value),
                    EndDate             = IfNoDateTimeValueReturnNull(workshopEndDate.Value),
                    Location            = workshopLocation.Value,
                    PricePerParticipant = decimal.Parse(workshopPrice.Value),
                    Trainer             = context.Photographers.Where(n => n.FirstName == workshopTrainerFirstName)
                                          .Where(ln => ln.LastName == workshopTrainerLastName).FirstOrDefault(),
                    Participants = participants
                };

                context.Workshops.Add(workshopEntity);
                Console.WriteLine($"Successfully imported {workshopName.Value}");
            }

            context.SaveChanges();
        }