public HomeModule()
 {
     Get["/"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["/contact"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["contact.cshtml", allContacts]);
     };
     Get["/contact/new"] = _ => {
         return(View["contact_new_form.cshtml"]);
     };
     Get["/contact/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         return(View["contact.cshtml", contact]);
     };
     Get["/contact/contact_search"] = _ => {
         return(View["contact_search.cshtml"]);
     };
     Post["/contact/contact_search_form"] = _ => {
         string         searchContact    = Request.Form["searched_contact"];
         List <Contact> allContacts      = Contact.GetAll();
         List <int>     returnedContacts = Contact.ContactExists(searchContact);
         if (returnedContacts.Count > 0)
         {
             List <Contact> foundContact = Contact.SearchContacts(searchContact);
             return(View["contact_search_result.cshtml", foundContact]);
         }
         else
         {
             return(View["no_contacts.cshtml"]);
         }
     };
     Get["/contact/clear"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         Contact.ClearAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["/deletecontact/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         Contact.DeleteContact(contact);
         List <Contact> allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Post["/contact"] = _ => {
         string  newName    = Request.Form["new_contact_name"];
         string  newPhone   = Request.Form["new_phone_number"];
         string  newEmail   = Request.Form["new_email"];
         string  newAddress = Request.Form["new_address"];
         Contact newContact = new Contact(newName, newPhone, newEmail, newAddress);
         return(View["contact.cshtml", newContact]);
     };
 }
Exemple #2
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };
            Get["/contacts/new"] = _ => {
                return(View["new_contact_form.cshtml"]);
            };
            Post["/contacts/added"] = _ => {
                string inputFirstName   = Request.Form["name-first"];
                string inputLastName    = Request.Form["name-last"];
                string inputPhoneNumber = Request.Form["phone-number"];

                string inputAddressStreet = Request.Form["address-street"];
                string inputAddressCity   = Request.Form["address-city"];
                string inputAddressState  = Request.Form["address-state"];
                string inputAddressZip    = Request.Form["address-zip"];

                Address newContactAddress = new Address(inputAddressStreet, inputAddressCity, inputAddressState, inputAddressZip);
                Contact newContact        = new Contact(inputFirstName, inputLastName, inputPhoneNumber, newContactAddress);

                return(View["contact_added.cshtml", newContact]);
            };
            Get["/contacts/{id}"] = parameters => {
                Contact selectedContact = Contact.FindById(parameters.id);
                return(View["contact.cshtml", selectedContact]);
            };
            Get["/contacts/all"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["contacts_all.cshtml", allContacts]);
            };
            Post["/"] = _ => {
                Contact.ClearAll();
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };
            Post["/contacts/deleted"] = _ => {
                int     targetId        = int.Parse(Request.Form["delete"]);
                Contact selectedContact = Contact.FindById(targetId);
                selectedContact.DeleteContact();
                Contact.ResetIds();
                return(View["contact_removed.cshtml"]);
            };
            Get["contacts/search"] = _ => {
                return(View["contacts_search.cshtml"]);
            };
            Get["contacts/search-results"] = _ => {
                string         searchInput      = Request.Query["search-input"];
                string         searchInputLower = searchInput.ToLower();
                List <Contact> searchResults    = Contact.SearchFor(searchInputLower);
                return(View["search_results.cshtml", searchResults]);
            };
        }
 public HomeModule()
 {
     Get["/"] = _ =>
     {
         var viewAll = Contact.GetAllContacts();
         return(View["index.cshtml", viewAll]);
     };
     Get["/contacts/new"]            = _ => View["new-contact-form.cshtml"];
     Post["/contacts/contact-added"] = _ =>
     {
         Contact newContact = new Contact(Request.Form["name"], Request.Form["phone"], Request.Form["details"]);
         Address newAddress = new Address(Request.Form["street"], Request.Form["city"], Request.Form["state"]);
         Dictionary <string, object> model = new Dictionary <string, object>();
         model.Add("contact", newContact);
         model.Add("address", newAddress);
         return(View["contact-added.cshtml", model]);
     };
     Get["/contacts/{id}/view-details"] = parameters =>
     {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var selectedContact = Contact.Find(parameters.id);
         var contactAddress  = Address.Find(parameters.id);
         model.Add("contact", selectedContact);
         model.Add("address", contactAddress);
         return(View["view-details.cshtml", model]);
     };
     Post["/contacts/clear"] = _ =>
     {
         Contact.ClearContacts();
         return(View["cleared.cshtml"]);
     };
     Post["/contacts/{id}/remove"] = parameters =>
     {
         Contact.DeleteContact(parameters.id);
         var viewAll = Contact.GetAllContacts();
         return(View["index.cshtml", viewAll]);
     };
     Post["/search"] = _ =>
     {
         var            search           = Request.Form["searchContact"];
         List <Contact> matchingContacts = Contact.FilterContact(search);
         return(View["index.cshtml", matchingContacts]);
     };
 }
Exemple #4
0
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                if (Contact.GetCounter() == 0)
                {
                    return(View["none.cshtml"]);
                }
                else
                {
                    return(View["index.cshtml", Contact.ContactList()]);
                }
            };

            Get["/contacts-view/{id}"] = parameters =>
            {
                Contact newContact = Contact.Find(parameters.id);
                return(View["view.cshtml", newContact]);
            };

            Post["/contacts-new"] = _ =>
            {
                Contact newContact = new Contact(Request.Form["contact-name"], Request.Form["contact-phone-number"], Request.Form["contact-address"]);
                return(View["new.cshtml"]);
            };

            Post["/contacts-clear"] = _ =>
            {
                int contactIndex = int.Parse(Request.Form["delete-button"]);
                Contact.DeleteContact(contactIndex);

                List <Contact> newList = Contact.ContactList();
                return(View["clear.cshtml", newList]);
            };

            Post["/contacts-clear-all"] = _ =>
            {
                Contact.ClearAll();
                return(View["clearall.cshtml"]);
            };
        }