public Person GetPersonById(int personID, PersonIncludes personIncludes)
        {
            using (var unitOfWork = unitOfWorkFactory.CreateUnitOfWork())
            {
                var person = unitOfWork.Persons.Find(personID, personIncludes);

                if (person != null)
                { 
                    if (personIncludes.Phones)
                    {
                        // Add home phone if not in the person Object
                        if (!person.Phones.Where(p => p.PhoneTypeID == 1).Any())
                            person.Phones.Add(new Phone { PhoneTypeID = 1, Number = string.Empty, PhoneType = new PhoneType { Name = "Home" } });

                        // Add work phone if not in the person Object
                        if (!person.Phones.Where(p => p.PhoneTypeID == 2).Any())
                            person.Phones.Add(new Phone { PhoneTypeID = 2, Number = string.Empty, PhoneType = new PhoneType { Name = "Work" } });

                        // Add cell phone if not in the person Object
                        if (!person.Phones.Where(p => p.PhoneTypeID == 3).Any())
                            person.Phones.Add(new Phone { PhoneTypeID = 3, Number = string.Empty, PhoneType = new PhoneType { Name = "Cell" } });
                    }

                    if (personIncludes.Addressses)
                    {
                        var emptyAddress = new Address
                        {
                            StreetAddress = string.Empty,
                            City = string.Empty,
                            State = string.Empty,
                            Zip = string.Empty
                        };

                        if (!person.Addresses.Where(a => a.AddressTypeID == 1).Any())
                            person.Addresses.Add(new PersonAddressAssn { AddressTypeID = 1, Address = emptyAddress, AddressType = new AddressType { Name = "Home" } });

                        if (!person.Addresses.Where(a => a.AddressTypeID == 2).Any())
                            person.Addresses.Add(new PersonAddressAssn { AddressTypeID = 2, Address = emptyAddress, AddressType = new AddressType { Name = "Work" } });

                        if (!person.Addresses.Where(a => a.AddressTypeID == 3).Any())
                            person.Addresses.Add(new PersonAddressAssn { AddressTypeID = 3, Address = emptyAddress, AddressType = new AddressType { Name = "Alternate" } });
                    }

                    if (personIncludes.Login && person.Login == null)
                        person.Login = new PersonLogin();
                }

                return person;
            }           
        }
        public ActionResult Edit(int personID)
        {
            // When editing persons from here only include the phones and addresses
            var personIncludes = new PersonIncludes();
            personIncludes.Phones = true;
            personIncludes.Addressses = true;
            personIncludes.Accounts = true;
            personIncludes.Login = true;

            var person = personService.GetPersonById(personID, personIncludes);

            ViewBag.States = stateSelectList();

            return PartialView(person);
        }
Example #3
0
        public Person Find(int personId, PersonIncludes personIncludes)
        {
            var personQueryable = GetQueryable().Where(p => p.PersonID == personId);

            if (personIncludes.Phones)
            {
                personQueryable = personQueryable.Include(p => p.Phones)
                                  .ThenInclude(ph => ph.PhoneType);
            }

            if (personIncludes.Addressses)
            {
                personQueryable = personQueryable.Include(p => p.Addresses)
                                  .ThenInclude(address => address.Address);

                personQueryable = personQueryable.Include(p => p.Addresses)
                                  .ThenInclude(address => address.AddressType);
            }

            if (personIncludes.Accounts)
            {
                personQueryable = personQueryable.Include(p => p.Accounts)
                                  .ThenInclude(accounts => accounts.Account)
                                  .ThenInclude(account => account.AccountType);
            }

            if (personIncludes.Login)
            {
                personQueryable = personQueryable.Include(p => p.Login);
            }

            if (personIncludes.AccountTransactions)
            {
                personQueryable = personQueryable.Include(p => p.Accounts)
                                  .ThenInclude(accounts => accounts.Account)
                                  .ThenInclude(account => account.Transactions)
                                  .ThenInclude(transactions => transactions.TransactionType);
            }

            if (personQueryable.Any())
            {
                return(personQueryable.First());
            }
            else
            {
                return(null);
            }
        }
        public ActionResult Edit(int personID)
        {
            // When editing persons from here only include the phones and addresses
            var personIncludes = new PersonIncludes();

            personIncludes.Phones     = true;
            personIncludes.Addressses = true;
            personIncludes.Accounts   = true;
            personIncludes.Login      = true;

            var person = personService.GetPersonById(personID, personIncludes);

            ViewBag.States = stateSelectList();

            return(PartialView(person));
        }
        public ActionResult Edit(int personID)
        {
            // When editing persons from here only include the phones and addresses
            var personIncludes = new PersonIncludes();
            personIncludes.Phones = true;
            personIncludes.Addressses = true;
            personIncludes.Accounts = true;
            personIncludes.Login = true;

            var person = _footlooseFSService.GetPerson(personID, personIncludes);

            // Add home phone if not in the person Object
            if (!person.Phones.Where(p => p.PhoneTypeID == 1).Any())
                person.Phones.Add(new Phone { PhoneTypeID = 1, Number = string.Empty });

            // Add work phone if not in the person Object
            if (!person.Phones.Where(p => p.PhoneTypeID == 2).Any())
                person.Phones.Add(new Phone { PhoneTypeID = 2, Number = string.Empty });

            // Add cell phone if not in the person Object
            if (!person.Phones.Where(p => p.PhoneTypeID == 3).Any())
                person.Phones.Add(new Phone { PhoneTypeID = 3, Number = string.Empty });

            var emptyAddress = new Address
            {
                StreetAddress = string.Empty,
                City = string.Empty,
                State = string.Empty,
                Zip = string.Empty
            };

            if (!person.Addresses.Where(a => a.AddressTypeID == 1).Any())
                person.Addresses.Add(new PersonAddressAssn { AddressTypeID = 1, Address = emptyAddress });

            if (!person.Addresses.Where(a => a.AddressTypeID == 2).Any())
                person.Addresses.Add(new PersonAddressAssn { AddressTypeID = 2, Address = emptyAddress });

            if (!person.Addresses.Where(a => a.AddressTypeID == 3).Any())
                person.Addresses.Add(new PersonAddressAssn { AddressTypeID = 3, Address = emptyAddress });

            if (person.Login == null)
                person.Login = new PersonLogin();

            ViewBag.States = stateSelectList();

            return PartialView(person);
        }
 public Person GetPersonByUsername(string userName, PersonIncludes personIncludes)
 {
     using (var unitOfWork = unitOfWorkFactory.CreateUnitOfWork())
     {
         var personLoginQueryable = unitOfWork.PersonLogins.GetQueryable().Where(p => p.LoginID == userName);
         if (personLoginQueryable.Any())
         {
             int personId = personLoginQueryable.First().PersonID;
             
             return GetPersonById(personId, personIncludes);
         }
         else
         {
             throw new Exception("Person with given username not found");
         }
     }
 }
Example #7
0
        public Person Find(int personId, PersonIncludes personIncludes)
        {
            var personQueryable = GetQueryable().Where(p => p.PersonID == personId);

            if (personIncludes.Phones)
            {
                personQueryable = personQueryable.Include("Phones");
                personQueryable = personQueryable.Include("Phones.PhoneType");
            }

            if (personIncludes.Addressses)
            {
                personQueryable = personQueryable.Include("Addresses.Address");
                personQueryable = personQueryable.Include("Addresses.AddressType");
            }

            if (personIncludes.Accounts)
            {
                personQueryable = personQueryable.Include("Accounts.Account")
                                  .Include("Accounts.Account.AccountType");
            }

            if (personIncludes.Login)
            {
                personQueryable = personQueryable.Include("Login");
            }

            if (personIncludes.AccountTransactions)
            {
                personQueryable = personQueryable.Include("Accounts.Account.Transactions");
                personQueryable = personQueryable.Include("Accounts.Account.Transactions.TransactionType");
            }

            if (personQueryable.Any())
            {
                return(personQueryable.First());
            }
            else
            {
                return(null);
            }
        }
        public Person GetPersonById(int personID, PersonIncludes personIncludes)
        {
            // Get the person data from the SQL repository
            Person person = null;

            using (var unitOfWork = unitOfWorkFactory.CreateUnitOfWork())
            {
                var personQueryable = unitOfWork.Persons.GetQueryable().Where(p => p.PersonID == personID);

                if (personIncludes.Phones)
                {
                    personQueryable = personQueryable.Include("Phones");
                    personQueryable = personQueryable.Include("Phones.PhoneType");
                }

                if (personIncludes.Addressses)
                {
                    personQueryable = personQueryable.Include("Addresses.Address");
                    personQueryable = personQueryable.Include("Addresses.AddressType");
                }

                if (personIncludes.Accounts)
                {
                    personQueryable = personQueryable.Include("Accounts.Account")
                                                    .Include("Accounts.Account.AccountType");
                }

                if (personIncludes.Login)
                    personQueryable = personQueryable.Include("Login");

                if (personIncludes.AccountTransactions)
                {
                    personQueryable = personQueryable.Include("Accounts.Account.Transactions");
                    personQueryable = personQueryable.Include("Accounts.Account.Transactions.TransactionType");
                }

                if (personQueryable.Any())
                    person = personQueryable.First();
            }

            return person;
        }
 public Person GetPersonById(int personID, PersonIncludes personIncludes)
 {
     return footlooseService.GetPersonById(personID, personIncludes);
 }
 Person IPersonRepository.Find(int personId, PersonIncludes personIncludes)
 {
     return(repository.Where(p => p.PersonID == personId).FirstOrDefault());
 }
Example #11
0
        public ActionResult Edit(int personID)
        {
            // When editing persons from here only include the phones and addresses
            var personIncludes = new PersonIncludes();

            personIncludes.Phones     = true;
            personIncludes.Addressses = true;
            personIncludes.Accounts   = true;
            personIncludes.Login      = true;

            var person = _footlooseFSService.GetPerson(personID, personIncludes);

            // Add home phone if not in the person Object
            if (!person.Phones.Where(p => p.PhoneTypeID == 1).Any())
            {
                person.Phones.Add(new Phone {
                    PhoneTypeID = 1, Number = string.Empty
                });
            }

            // Add work phone if not in the person Object
            if (!person.Phones.Where(p => p.PhoneTypeID == 2).Any())
            {
                person.Phones.Add(new Phone {
                    PhoneTypeID = 2, Number = string.Empty
                });
            }

            // Add cell phone if not in the person Object
            if (!person.Phones.Where(p => p.PhoneTypeID == 3).Any())
            {
                person.Phones.Add(new Phone {
                    PhoneTypeID = 3, Number = string.Empty
                });
            }

            var emptyAddress = new Address
            {
                StreetAddress = string.Empty,
                City          = string.Empty,
                State         = string.Empty,
                Zip           = string.Empty
            };

            if (!person.Addresses.Where(a => a.AddressTypeID == 1).Any())
            {
                person.Addresses.Add(new PersonAddressAssn {
                    AddressTypeID = 1, Address = emptyAddress
                });
            }

            if (!person.Addresses.Where(a => a.AddressTypeID == 2).Any())
            {
                person.Addresses.Add(new PersonAddressAssn {
                    AddressTypeID = 2, Address = emptyAddress
                });
            }

            if (!person.Addresses.Where(a => a.AddressTypeID == 3).Any())
            {
                person.Addresses.Add(new PersonAddressAssn {
                    AddressTypeID = 3, Address = emptyAddress
                });
            }

            if (person.Login == null)
            {
                person.Login = new PersonLogin();
            }

            ViewBag.States = stateSelectList();

            return(PartialView(person));
        }
 Person IPersonRepository.Find(int personId, PersonIncludes personIncludes)
 {
     throw new NotImplementedException();
 }
Example #13
0
 public Person GetPersonById(int personID, PersonIncludes personIncludes)
 {
     return(footlooseService.GetPersonById(personID, personIncludes));
 }