Ejemplo n.º 1
0
        private void CreateUpdate_Button_Click(object sender, RoutedEventArgs e)
        {
            SelectedContact.Name        = NameTextBox.Text;
            SelectedContact.Surname     = SurnameTextBox.Text;
            SelectedContact.PhoneNumber = PhoneNumberTextBox.Text;
            SelectedContact.Sex         = (SexEnum)SexComboBox.SelectedIndex + 1;

            if (SelectedContact.Id == 0)
            {
                var addedContact = contactsDAL.InsertContact(SelectedContact);
                MainTable.ItemsSource = MainTable.ItemsSource.Cast <Contact>().Concat(new List <Contact> {
                    addedContact
                });
            }
            else
            {
                var updatedElement             = contactsDAL.UpdateContact(SelectedContact);
                var actualMainTableItemsSource = MainTable.ItemsSource.Cast <Contact>().ToList();
                var elementInTable             = actualMainTableItemsSource.FirstOrDefault(x => x.Id == updatedElement.Id);
                actualMainTableItemsSource.Remove(elementInTable);
                actualMainTableItemsSource.Add(updatedElement);
                MainTable.ItemsSource = actualMainTableItemsSource;
            }

            ClearContactData();
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Spara en kontaktuppgift i databasen.
        /// </summary>
        /// <param name="customer">KOntaktuppgifter som ska sparas.</param>
        public void SaveContact(Contact contact)
        {
            // Uppfyller inte objektet affärsreglerna...
            ICollection <ValidationResult> validationResults;

            if (!contact.Validate(out validationResults)) // Använder "extension method" för valideringen!
            {                                             // Klassen finns under App_Infrastructure.
                // ...kastas ett undantag med ett allmänt felmeddelande samt en referens
                // till samlingen med resultat av valideringen.
                var ex = new ValidationException("Objektet klarade inte valideringen.");
                ex.Data.Add("ValidationResults", validationResults);
                throw ex;
            }

            // Contact-objektet sparas antingen genom att en ny post
            // skapas eller genom att en befintlig post uppdateras.
            if (contact.ContactId == 0) // Ny post om ContactId är 0!
            {
                ContactDAL.InsertContact(contact);
            }
            else
            {
                ContactDAL.UpdateContact(contact);
            }
        }
Ejemplo n.º 3
0
        public ActionResult <Contact> UpdateContact(int contactId, [FromBody] Contact contact)
        {
            var contactsDAL = new ContactDAL();

            contact.Id = contactId;
            var result = contactsDAL.UpdateContact(contact);

            if (result == null)
            {
                return(BadRequest());
            }
            return(Ok(result));
        }
Ejemplo n.º 4
0
        /// <summary>
        /// Update Contact
        /// </summary>
        /// <param name="contactRequest">contactRequest</param>
        /// <returns>Returns true if updation is successful else false</returns>
        public async Task <bool> UpdateContact(ContactRequest contactRequest)
        {
            ContactValidator contactValidator = new ContactValidator(eHIDemoContext);

            contactValidator.ValidateContactRequest(contactRequest);
            ContactDAL contactDAL = new ContactDAL(eHIDemoContext);

            DBModel.Contact.Contact contact = ContactMapper.MapperForContactUpdate(contactRequest);
            int savedRecordCount            = await contactDAL.UpdateContact(contact).ConfigureAwait(false);

            if (savedRecordCount > 0)
            {
                return(true);
            }
            return(false);
        }
Ejemplo n.º 5
0
 public int EditContact([FromBody] Contact c)
 {
     return(_contactDAL.UpdateContact(c));
 }
Ejemplo n.º 6
0
        protected void Page_Load(object sender, EventArgs e)
        {
            xero = new XeroIntergration();
            ContactDAL contactdal = new ContactDAL(strConnString);
            CompanyDAL companydal = new CompanyDAL(strConnString);

            int    ContactID       = Int32.Parse(Request.Form["ContactID"].ToString());
            String FirstName       = Request.Form["NewFirstName"].ToString();
            String LastName        = Request.Form["NewLastName"].ToString();
            String DefaultAreaCode = Request.Form["NewDefaultAreaCode"].ToString();
            String DefaultNumber   = Request.Form["NewDefaultNumber"].ToString();
            String MobileNumber    = Request.Form["NewMobileNumber"].ToString();
            String EmailAddy       = Request.Form["NewEmailAddy"].ToString();
            String ShipLine1       = Request.Form["NewShipLine1"].ToString();
            String ShipLine2       = Request.Form["NewShipLine2"].ToString();
            String ShipCity        = Request.Form["NewShipCity"].ToString();
            String ShipState       = Request.Form["NewShipState"].ToString();
            String ShipPostcode    = Request.Form["NewShipPostcode"].ToString();
            String BillLine1       = Request.Form["NewBillLine1"].ToString();
            String BillLine2       = Request.Form["NewBillLine2"].ToString();
            String BillCity        = Request.Form["NewBillCity"].ToString();
            String BillState       = Request.Form["NewBillState"].ToString();
            String BillPostcode    = Request.Form["NewBillPostcode"].ToString();
            String PrimaryContact  = Request.Form["PrimaryContact"].ToString();
            String ActINact        = Request.Form["ActInact"].ToString();

            string finalActInact = "";

            if (ActINact == "false")
            {
                finalActInact = "N";
            }
            else
            {
                finalActInact = "Y";
            }

            String finalPrimaryContact = "";

            if (PrimaryContact == "true")
            {
                finalPrimaryContact = "Y";
            }
            else
            {
                finalPrimaryContact = "N";
            }

            var    userId = Convert.ToInt32(Session["LoggedUserID"].ToString());
            String str    = contactdal.UpdateContact(ContactID, FirstName, LastName, DefaultAreaCode,
                                                     DefaultNumber, MobileNumber, EmailAddy, ShipLine1, ShipLine2, ShipCity, ShipState,
                                                     ShipPostcode, BillLine1, BillLine2, BillCity, BillState, BillPostcode, finalPrimaryContact, finalActInact, userId);

            if (Int32.Parse(str) > 0)
            {
                //Ge the XeroGuid and Update the Details in Xero
                String contactGuid = contactdal.getXeroGuid_ForContact(ContactID);
                if (!String.IsNullOrEmpty(contactGuid) && !(DBNull.Value.Equals(contactGuid)))
                {
                    //Fetch the CompanyName for the Contact
                    String strCompanyName        = companydal.GetCompanybyContactID(ContactID);
                    String strDefaultCountryCode = "+61";       //Should have entries in AddContactUI
                    String strDefaultCountry     = "Australia"; //Should have entries in AddContactUI


                    Repository            res        = xero.CreateRepository();//Create the Repository
                    XeroApi.Model.Contact delContact = xero.UpdateContact(res, contactGuid, strCompanyName, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, ShipPostcode, BillState);
                    if (delContact != null)
                    {
                    }

                    // Repository res = xero.CreateRepository();
                    // XeroApi.Model.Contact delContact = xero.CreateContact(res, strCompanyName, FirstName, LastName, DefaultAreaCode, strDefaultCountryCode, DefaultNumber, String.Empty, String.Empty, String.Empty, String.Empty, strDefaultCountryCode, MobileNumber, EmailAddy, ShipLine1, ShipCity, strDefaultCountry, ShipPostcode, ShipState, BillLine1, BillCity, strDefaultCountry, BillPostcode, BillState);
                    //if (delContact != null)
                    // {
                    //Update the ContactGuid in the DataBase Table
                    //    contactdal.UpdateWithXeroDetails(23538, delContact.ContactID.ToString());
                    // }
                }
                else
                {
                    //Entry hasn't been created in the Xero System .Create the Entry and Update the Tables
                }
            }


            Response.Write(str);
        }