コード例 #1
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));
        }