Beispiel #1
0
 public EditClient(int id)
 {
     _clientID = id;
     _data     = _context.vwPersonalContactDetails.Find(_clientID);
     InitializeComponent();
     InitializeFields();
 }
Beispiel #2
0
        public async Task <IActionResult> Edit(int id, [Bind("ClientID,FirstName,LastName,BirthDate,EmailAddress,Telephone,HomeTelephone,AddressLine1,AddressLine2,City,State,Country,PostalCode")] vwPersonalContactDetail vwPersonalContactDetail)
        {
            if (id != vwPersonalContactDetail.ClientID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                var model = vwPersonalContactDetail;

                try
                {
                    Client client = _context.Clients.Find(id);
                    client.FirstName = model.FirstName;
                    client.LastName  = model.LastName;
                    client.BirthDate = model.BirthDate;
                    _context.Clients.Update(client);

                    PersonalContact contact = _context.PersonalContacts.Find(client.PersonalContactID);
                    contact.EmailAddress  = model.EmailAddress;
                    contact.Telephone     = model.Telephone;
                    contact.HomeTelephone = model.HomeTelephone;
                    _context.PersonalContacts.Update(contact);

                    Address address = _context.Addresses.Find(contact.AddressID);
                    address.AddressLine1 = model.AddressLine1;
                    address.AddressLine2 = model.AddressLine2;
                    address.City         = model.City;
                    address.State        = model.State;
                    address.Country      = model.Country;
                    address.PostalCode   = model.PostalCode;
                    _context.Addresses.Update(address);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!vwPersonalContactDetailExists(vwPersonalContactDetail.ClientID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(vwPersonalContactDetail));
        }
Beispiel #3
0
        public async Task <IActionResult> Create([Bind("ClientID,FirstName,LastName,BirthDate,EmailAddress,Telephone,HomeTelephone,AddressLine1,AddressLine2,City,State,Country,PostalCode")] vwPersonalContactDetail vwPersonalContactDetail)
        {
            if (ModelState.IsValid)
            {
                var model = vwPersonalContactDetail;

                Address address = new Address
                {
                    AddressLine1 = model.AddressLine1,
                    AddressLine2 = model.AddressLine2,
                    City         = model.City,
                    State        = model.State,
                    Country      = model.Country,
                    PostalCode   = model.PostalCode
                };
                _context.Addresses.Add(address);
                _context.SaveChanges();
                int addressID = _context.Addresses.Select(i => i.AddressID).Max();

                PersonalContact contact = new PersonalContact
                {
                    EmailAddress  = model.EmailAddress,
                    Telephone     = model.Telephone,
                    HomeTelephone = model.HomeTelephone,
                    AddressID     = addressID
                };
                _context.PersonalContacts.Add(contact);
                _context.SaveChanges();
                int contactID = _context.PersonalContacts.Select(i => i.PersonalContactID).Max();

                Client client = new Client()
                {
                    FirstName         = model.FirstName,
                    LastName          = model.LastName,
                    BirthDate         = model.BirthDate,
                    FirstContactDate  = DateTime.Now,
                    LastContactDate   = null,
                    PersonalContactID = contactID
                };
                _context.Clients.Add(client);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(vwPersonalContactDetail));
        }