public async Task <IActionResult> Edit(int id, [Bind("ID,pFirstName,pLastName,cEmail,cNumber,pNumber,fAddress,sAddress,pCity,personalPostCode")] PersonalContact personalContact)
        {
            if (id != personalContact.ID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(personalContact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonalContactExists(personalContact.ID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(personalContact));
        }
Esempio n. 2
0
        protected override void Initialize()
        {
            pc_id = 1;
            a1_id = 10;
            a2_id = 100;

            var pc = new PersonalContact {
                Id = pc_id, Email = "e", FirstName = "f"
            };
            var a1 = new Address {
                Id = a1_id, Address1 = "a1", Contact = pc
            };

            //rev1
            using (var tx = Session.BeginTransaction())
            {
                pc_id = (long)Session.Save(pc);
                a1_id = (long)Session.Save(a1);
                tx.Commit();
            }

            //rev2
            using (var tx = Session.BeginTransaction())
            {
                var a2 = new Address {
                    Id = a2_id, Address1 = "a2", Contact = pc
                };
                a2_id = (long)Session.Save(a2);
                tx.Commit();
            }
        }
        public async Task <IActionResult> Edit(int id, [Bind("PersonalContactID,PersonalFame,PersonalLname,PersonalEmail,PersonalAddress1,PersonalAddress2,PersonalCity,PersonalPostCode,PersonalTel")] PersonalContact personalContact)
        {
            if (id != personalContact.PersonalContactID)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(personalContact);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException)
                {
                    if (!PersonalContactExists(personalContact.PersonalContactID))
                    {
                        return(NotFound());
                    }
                    else
                    {
                        throw;
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(personalContact));
        }
        private void btnSave_Click(object sender, EventArgs e)
        {
            var isValid = ValidateInput();

            if (isValid)
            {
                try
                {
                    Address address = new Address
                    {
                        AddressLine1 = tbAddressLine1.Text,
                        AddressLine2 = tbAddressLine2.Text,
                        City         = tbCity.Text,
                        State        = tbState.Text,
                        Country      = tbCountry.Text,
                        PostalCode   = tbPostalCode.Text
                    };
                    _context.Addresses.Add(address);
                    _context.SaveChanges();
                    int addressID = _context.Addresses.Select(i => i.AddressID).Max();

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

                    Client client = new Client()
                    {
                        FirstName         = tbFirstName.Text,
                        LastName          = tbLastName.Text,
                        BirthDate         = tbBirthDate.Value,
                        FirstContactDate  = DateTime.Now,
                        LastContactDate   = null,
                        PersonalContactID = contactID
                    };
                    _context.Clients.Add(client);
                    _context.SaveChanges();
                    MessageBox.Show("New Client Added!", "New Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please fill in the required fields.", "New Client", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
        public async Task <IActionResult> Create([Bind("PersonalContactID,PersonalFame,PersonalLname,PersonalEmail,PersonalAddress1,PersonalAddress2,PersonalCity,PersonalPostCode,PersonalTel")] PersonalContact personalContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personalContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(personalContact));
        }
Esempio n. 6
0
        public async Task <IActionResult> Create([Bind("PersonalContactID,PFname,PLname,PEmail,PerTel,PAddr1,PAddr2,PAddr3,PPostcode,PCity")] PersonalContact personalContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personalContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(personalContact));
        }
        public async Task <IActionResult> Create([Bind("ID,pFirstName,pLastName,cEmail,cNumber,pNumber,fAddress,sAddress,pCity,personalPostCode")] PersonalContact personalContact)
        {
            if (ModelState.IsValid)
            {
                _context.Add(personalContact);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index)));
            }
            return(View(personalContact));
        }
Esempio n. 8
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));
        }
Esempio n. 9
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));
        }
Esempio n. 10
0
        private void btnSave_Click(object sender, EventArgs e)
        {
            var isValid = ValidateInput();

            if (isValid)
            {
                try
                {
                    Client client = _context.Clients.Find(_clientID);
                    client.FirstName = tbFirstName.Text;
                    client.LastName  = tbLastName.Text;
                    client.BirthDate = tbBirthDate.Value;
                    _context.Clients.Update(client);

                    PersonalContact contact = _context.PersonalContacts.Find(client.PersonalContactID);
                    contact.EmailAddress  = tbEmail.Text;
                    contact.Telephone     = tbTelephone.Text;
                    contact.HomeTelephone = tbHomeTelephone.Text;
                    _context.PersonalContacts.Update(contact);

                    Address address = _context.Addresses.Find(contact.AddressID);
                    address.AddressLine1 = tbAddressLine1.Text;
                    address.AddressLine2 = tbAddressLine2.Text;
                    address.City         = tbCity.Text;
                    address.State        = tbState.Text;
                    address.Country      = tbCountry.Text;
                    address.PostalCode   = tbPostalCode.Text;
                    _context.Addresses.Update(address);
                    _context.SaveChanges();
                    MessageBox.Show("Client Updated!", "Edit Client", MessageBoxButtons.OK, MessageBoxIcon.Information);
                }
                catch (Exception ex)
                {
                    MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                }
            }
            else
            {
                MessageBox.Show("Please fill in the required fields.", "Edit Client", MessageBoxButtons.OK, MessageBoxIcon.Warning);
            }
        }
Esempio n. 11
0
        public ActionResult AdminPersonalContactCreate([Bind(Include = "Id,Firstname,Lastname,PhoneNumber,Address, Email,Relation,OtherInfo")] PersonalContact personalContact)

        {
            return(View());
        }