Esempio n. 1
0
        public PrintObject GetDataForPrint(int caseId)
        {
            PrintObject printObject = new PrintObject();
            CalculateAverageWithIntegerInput calc = new CalculateAverageWithIntegerInput(_caseCRUD);

            Entities.Case workingCase = _caseCRUD.ReadCase(caseId);

            Entities.Realtor workingRealtor = _realtorCRUD.ReadRealtor(_caseCRUD.ReturnRealtorIDOnCase(caseId));

            Entities.Property workingProperty = _propertyCRUD.ReadPropertyFromCaseID(caseId);

            Entities.Address workingAddress = _addressCRUD.ReadAddress(workingProperty.PostalCode, workingProperty.AddressLine1);

            printObject.RealtorName  = workingRealtor.Name;
            printObject.RealtorPhone = workingRealtor.PhoneNR;

            printObject.CaseID       = workingCase.CaseID;
            printObject.CreationDate = workingCase.CreationDate;
            if (workingCase.ClosedDate != null)
            {
                printObject.ClosedDate = (DateTime)workingCase.ClosedDate;
            }
            printObject.Price = workingCase.Price;

            printObject.PostalCode     = workingProperty.PostalCode;
            printObject.AddressLine1   = workingProperty.AddressLine1;
            printObject.EstimatedPrice = workingProperty.EstimatedPrice;


            printObject.AddressLine2 = workingAddress.AddressLine2;
            printObject.ExteriorArea = workingAddress.ExteriorArea;
            printObject.InteriorArea = workingAddress.InteriorArea;
            printObject.BuildYear    = workingAddress.BuildYear;

            printObject.AverageAreaPrice = calc.Calculate(workingProperty.PostalCode);

            return(printObject);
        }
        static void Main(string[] args)
        {
            var context = new BestPracticesDbContext();

            context.Database.Initialize(true);

            var account = new Account()
            {
                AccountName = "El Al Cargo",
                Settings = new Settings()
                {
                    MaxPickupsPerCar = 3,
                    MaxTripDuration = 75,
                    MinPickupsPerCar = 2
                }
            };
            context.Accounts.Add(account);
            context.SaveChanges();

            var user = new User()
            {
                Username = "******",
                LastLogin = DateTime.Now,
                Email = "*****@*****.**",
                AccessibleAccounts = new List<AccountUsers>()
                        {
                            new AccountUsers()
                            {
                                AuthorizationLevel = new AuthorizationLevel()
                                {
                                    Description = "admin"
                                },
                                AccountId = account.Id
                            }
                        }
            };
            context.Users.Add(user);
            context.SaveChanges();

            var destinationAddress = new Address()
            {
                IsArchived = false,
                FirstLine = "502 Shoreham Rd",
                SecondLine = "London Heatrow Airport , Hounslow",
                PostCode = "TW6 3UA",
                City = "London",
                Country = "United Kingdom"
            };
            context.Addresses.Add(destinationAddress);
            context.SaveChanges();

            var contactAddress = new Address()
            {
                FirstLine = "6 Bridgeman House",
                SecondLine = "Pump House Crescent",
                PostCode = "TW8 0FX",
                City = "London",
                Country = "United Kingdom",
            };
            context.Addresses.Add(contactAddress);
            context.SaveChanges();

            var contact = new Contact()
            {
                FirstName = "Chen",
                LastName = "Keren Kaminsky",
                Email = "*****@*****.**",
                Phone = "07474772070",
                IsArchived = false,
                PrimaryAddressId = contactAddress.Id
            };
            context.Contacts.Add(contact);
            context.SaveChanges();

            contact.ContactAddresses.Add(new ContactAddresses()
            {
                Contact = contact,
                Address = contactAddress
            });

            var mailingContact = new Contact()
            {
                FirstName = "Dina",
                LastName = "Barel",
                Email = "*****@*****.**",
                Phone = "0208000000",
                IsArchived = false,
                PrimaryAddressId = null,
            };
            context.Contacts.Add(mailingContact);
            context.SaveChanges();

            var mailingList = new MailingList()
            {
                Name = "Default"
            };
            context.MailingLists.Add(mailingList);
            context.SaveChanges();

            mailingList.MailingListContacts.Add(new MailingListContact()
            {
                Contact = mailingContact,
                MailingList = mailingList
            });

            account.AccountDestinations.Add(new AccountDestinations()
            {
                Account = account,
                Address = destinationAddress,
                AddressNickname = "Cargo Warehouse"
            });

            account.MailingLists.Add(mailingList);

            context.SaveChanges();




            var storedAccount = context.Accounts.FirstOrDefault();

            if (storedAccount != null)
            {
                Console.WriteLine(storedAccount.AccountName);
                Console.WriteLine("Settings:\n{0}\n{1}\n{2}", storedAccount.Settings.MaxPickupsPerCar, storedAccount.Settings.MaxTripDuration,
                    storedAccount.Settings.MinPickupsPerCar);
                Console.WriteLine("Contacts:");
                foreach (var cnt in storedAccount.Contacts)
                {
                    Console.WriteLine(cnt.FirstName + " " + cnt.LastName);
                    Console.WriteLine("Primary Address:");
                    Console.WriteLine(cnt.ContactAddresses.FirstOrDefault(a => a.Address.Id == cnt.PrimaryAddressId).Address.FirstLine);
                }
                Console.WriteLine("Destinations: ");
                foreach (var dst in storedAccount.AccountDestinations)
                {
                    Console.WriteLine(dst.AddressNickname + ": " + dst.Address.FirstLine);
                }
                Console.WriteLine("Mailing Lists:");
                foreach (var mailList in storedAccount.MailingLists)
                {
                    Console.WriteLine(mailList.Name + ": ");
                    foreach (var mcnt in mailList.MailingListContacts)
                    {
                        Console.WriteLine(mcnt.Contact.FirstName + ": " + mcnt.Contact.Email);
                    }
                }
            }
            else
            {
                Console.WriteLine("No recordes found");
            }


            Console.WriteLine("Done! Press any key to exit.");
            Console.ReadKey();
        }