Example #1
0
        public IActionResult AddContact(Contact model)
        {
            int id;

            try
            {
                id = cBuss.AddContact(model);
                return(Ok("Exito! -- id " + id + " agregardo."));
            }
            catch (Exception ex)
            {
                throw new Exception(ex.Message);
            }
        }
        static void Main(string[] args)
        {
            try
            {
                ContactBusiness objBusiness = Bootstrapper.Init();

                Contact c = new Contact
                {
                    ContactType  = ContactType.Business,
                    BusinessName = "Object Frontier Software"
                };

                var addContactResult = objBusiness.AddContact(c);
                Console.WriteLine("Add Contact result: " + addContactResult);

                var exisitngContacts = objBusiness.GetContacts();

                var contactID = exisitngContacts.Select(con => con.ContactID).FirstOrDefault();

                ContactAddress ca = new ContactAddress
                {
                    ContactID = contactID,
                    City      = "ROCHESTER",
                    State     = "NY",
                    Street    = "Monroe Road",
                    ZipCode   = "32345"
                };

                var addContactAddressResult = objBusiness.AddAddress(ca);
                Console.WriteLine("Add Contact address result: " + addContactAddressResult);

                var contactDetail = objBusiness.GetContactDetail(contactID);
                Console.WriteLine("Get Contact detail result: " + Constants.Common.Success);

                var contactByZipCode = objBusiness.GetContactByZipCode(ca.ZipCode);
                Console.WriteLine("Get Contact by Zip Code result: " + Constants.Common.Success);

                //Add Contact
                c.ContactID   = Guid.Empty;
                c.ContactType = ContactType.Person;
                c.FirstName   = "Ruban";
                c.LastName    = "Stephen";

                var addContactWithAddressResult = objBusiness.AddContact(c);
                Console.WriteLine("Add Contact with address result: " + addContactWithAddressResult);

                exisitngContacts = objBusiness.GetContacts();

                foreach (var address in contactDetail.ContactAddress)
                {
                    var deleleAddress = objBusiness.DeleteAddress(address.ContactAddressID);
                    Console.WriteLine("Delete address for ContactID: " + contactDetail.ContactID.ToString() + deleleAddress);
                }

                foreach (var contact in exisitngContacts)
                {
                    var deleleStatus = objBusiness.DeleteContact(contact.ContactID);
                    Console.WriteLine("Delete contact for ContactID: " + contact.ContactID.ToString() + deleleStatus);
                }

                Console.ReadLine();
            }
            catch (Exception ex)
            {
                Console.WriteLine("DAL Test failed due to: " + ex.Message);
                Console.ReadLine();
            }
        }
        public void AddContact_WithContactTypePerson_Should_Succeed()
        {
            Contact contact = new Contact(_emptyGUID,
                                          ContactType.Person,
                                          "First Name",
                                          "Last Name",
                                          "",
                                          DateTime.Now,
                                          DateTime.Now,
                                          new List <ContactAddress>());

            Assert.AreEqual(_mock.AddContact(contact), Constants.Common.Success);
        }