public HomeModule()
 {
     Get["/"] = _ =>
     {
         return(View["index.cshtml"]);
     };
     Get["/contacts"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["contacts.cshtml", allContacts]);
     };
     Get["/contact/new"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Get["/all_contacts/"] = _ => {
         var allContacts = Contact.GetAll();
         return(View["all_contacts.cshtml", allContacts]);
     };
     Post["/contact_created"] = _ => {
         Contact newContact = new Contact(Request.Form["new-name"], Request.Form["new-address"], Request.Form["new-number"]);
         return(View["contact_created.cshtml", newContact]);
     };
     Get["/contact/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         return(View["/contacts.cshtml", contact]);
     };
     Post["/contacts_deleted/"] = _ => {
         Contact.Clear();
         return(View["contacts_cleared.cshtml"]);
     };
 }
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Get["/contact/detail"] = _ => View["contact-detail.cshtml"];

            Get["/contact/form"] = _ => View["contact-form.cshtml"];

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

            Get["/contact/{id}"] = parameters =>
            {
                Contact person = Contact.Find(parameters.id);
                return(View["contact-detail.cshtml", person]);
            };

            Post["/contacts/clear"] = _ =>
            {
                Contact.ClearAll();
                return(View["clear-all.cshtml"]);
            };
        }
 public HomeModule()
 {
     Get["/"] = _ => {
         return(View["index.cshtml"]);
     };
     Get["/contacts"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["contacts.cshtml", allContacts]);
     };
     Get["/contacts/new"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Get["/contacts/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         return(View["/contact.cshtml", contact]);
     };
     Post["/contacts"] = _ => {
         Contact        newContact  = new Contact(Request.Form["contact-name"], Request.Form["contact-address"], Request.Form["contact-phone"]);
         List <Contact> allContacts = Contact.GetAll();
         return(View["contacts.cshtml", allContacts]);
     };
     Post["/contacts/clear"] = _ => {
         Contact.ClearAll();
         return(View["contacts_cleared.cshtml"]);
     };
 }
示例#4
0
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                List <Contact> allContacts = Contact.DisplayAll();

                return(View["index.cshtml", allContacts]);
            };

            Get["/deleteAll"] = _ =>
            {
                Contact.Empty();
                List <Contact> allContacts = Contact.DisplayAll();
                return(View["index.cshtml", allContacts]);
            };
            Get["/add"] = _ =>
            {
                return(View["add_contact.cshtml"]);
            };
            Post["/new"] = _ =>
            {
                Contact newContact = new Contact(Request.Form["firstN"], Request.Form["lastN"], Request.Form["phone"], Request.Form["address"]);
                return(View["new_contact.cshtml", newContact]);
            };
            Get["/see/{id}"] = parameters =>
            {
                Contact aContact = Contact.Find(parameters.id);
                return(View["see_contact.cshtml", aContact]);
            };
        }
示例#5
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["/contact_details/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         return(View["contact_details.cshtml", contact]);
     };
     Get["/contact_form"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Get["/view_all_contacts"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["view_all_contacts.cshtml", allContacts]);
     };
     Post["/contact_added"] = _ => {
         Contact newContact = new Contact(Request.Form["new-name"], Request.Form["new-phone"], Request.Form["new-address-street"], Request.Form["new-city-state"]);
         return(View["contact_added.cshtml", newContact]);
     };
     Post["/contacts_cleared"] = _ => {
         Contact.ClearAll();
         return(View["contacts_cleared.cshtml"]);
     };
 }
        public HomeModule()
        {
            Get["/"] = _ =>
            {
                List <Contact> allContacts = Contact.GetAllContacts();

                return(View["index.cshtml", allContacts]);
            };
            Post["/contact/new"] = _ =>
            {
                Address newAddress = new Address(Request.Form["street"], Request.Form["city"], Request.Form["state"], Request.Form["zip"]);
                Contact newContact = new Contact(Request.Form["firstName"], Request.Form["lastName"], Request.Form["phone"], Request.Form["email"], newAddress);

                return(View["contact_created.cshtml", newContact]);
            };
            Get["/contact/form"] = _ => View["contact_form.cshtml"];
            Get["/contact/{id}"] = parameters =>
            {
                Contact currentContact = Contact.Find(parameters.id);

                return(View["contact_details.cshtml", currentContact]);
            };
            Post["/contacts/clear"] = _ =>
            {
                Contact.ClearAllContacts();
                return(View["contacts_cleared.cshtml"]);
            };
        }
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.html"]);
            };

            Get["/contacts"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["contacts.cshtml", allContacts]);
            };

            Get["/contacts/new"] = _ => {
                return(View["add_new_contact"]);
            };

            Post["/contacts/added"] = _ => {
                Contact newContact = new Contact((Request.Form["name"]), (Request.Form["phoneNumber"]), (Request.Form["address"]));
                return(View["contact_created.cshtml", newContact]);
            };

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

            Get["/contacts/cleared"] = _ => {
                Contact.ClearAll();
                return(View["contacts_deleted.cshtml"]);
            };
        }
示例#8
0
 public HomeModule()
 {
     Get ["/"]             = _ => View ["index.cshtml"];
     Get ["/contacts/new"] = _ => View ["contact_form.cshtml"];
     Post ["/contact"]     = _ => {
         Contact newContact = new Contact
                              (
             Request.Form ["first-name"],
             Request.Form ["last-name"],
             Request.Form ["phone-number"],
             Request.Form ["email-address"],
             Request.Form ["street-address"],
             Request.Form ["state-address"]
                              );
         return(View ["contact_created.cshtml", newContact]);
     };
     Get ["/contacts"] = _ => {
         List <Contact> newContactList = Contact.GetAll();
         return(View ["contacts.cshtml", newContactList]);
     };
     Get ["/contacts/{id}"] = parameters => {
         Contact newContact = Contact.Find(parameters.id);
         return(View ["/contact_created.cshtml", newContact]);
     };
     Post ["/contacts/deleted"] = _ => {
         Contact.DeleteAll();
         return(View ["contacts_deleted.cshtml"]);
     };
 }
示例#9
0
 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]);
     };
 }
 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]);
     };
 }
示例#11
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["/contact/form"] = _ => View["contact_form.cshtml"];
     Post["/contact/new"] = _ => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         var           newContact          = new Contact(Request.Form["name"]);
         List <Number> contactNumbers      = newContact.GetNumbers();
         var           newNumber           = new Number(Request.Form["number"]);
         contactNumbers.Add(newNumber);
         List <Address> contactAddresses = newContact.GetAddresses();
         var            newAddress       = new Address(Request.Form["first-line"], Request.Form["city"], Request.Form["state"], Request.Form["zip"]);
         contactAddresses.Add(newAddress);
         model.Add("numbers", contactNumbers);
         model.Add("addresses", contactAddresses);
         model.Add("contact", newContact);
         return(View["contact.cshtml", model]);
     };
     //Search functionality does not work, but I would love it to.
     Get["/contacts/search"] = _ => {
         string  searchString        = (Request.Form["search-string"]);
         Contact searchResultContact = Contact.Search(searchString);
         return(View["search_results.cshtml", searchResultContact]);
     };
     Get["/contacts/{id}"] = parameters => {
         Dictionary <string, object> model = new Dictionary <string, object>();
         Contact        selectedContact    = Contact.Find(parameters.id);
         List <Number>  allNumbers         = selectedContact.GetNumbers();
         List <Address> allAddresses       = selectedContact.GetAddresses();
         model.Add("numbers", allNumbers);
         model.Add("addresses", allAddresses);
         model.Add("contact", selectedContact);
         return(View["contact.cshtml", model]);
     };
     Post["/contacts/clear"] = _ => {
         Contact.ClearAll();
         return(View["contacts_clear.cshtml"]);
     };
 }
示例#12
0
        public HomeModule()
        {
            Get["/"] = _ => {
                var allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

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

            Get["/contact/new"] = _ => {
                return(View["add_contact_form.cshtml"]);
            };

            Get["/contact/{id}"] = parameters => {
                Contact contact = Contact.Find(parameters.id);
                return(View["view_contact.cshtml", contact]);
            };

            Post["/contact/clear"] = _ => {
                Contact.ClearAll();
                return(View["contact_clear.cshtml"]);
            };

            Post["/contact/{id}/remove"] = parameters => {
                Contact contact = Contact.Find(parameters.id);
                contact.RemoveContact();
                return(View["remove_contact.cshtml"]);
            };

            Get["/search"] = _ => {
                return(View["search_form.cshtml"]);
            };

            Post["/search_results"] = _ => {
                Contact selectedContact = Contact.SearchContact(Request.Form["search"]);
                return(View["view_contact.cshtml", selectedContact]);
            };
        }
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["address_book.cshtml", allContacts]);
     };
     Get["/new_contact"]   = _ => View["contact.cshtml"];
     Get["/contacts/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         return(View["/view_contact.cshtml", contact]);
     };
     Post["/contact_added"] = _ => {
         Contact newContact = new Contact(Request.Form["firstname"], Request.Form["lastname"], Request.Form["phoneNumber"], Request.Form["address"]);
         return(View["contact_added.cshtml", newContact]);
     };
     Get["/contacts_cleared"] = _ => {
         Contact.ClearAll();
         return(View["contacts_cleared.cshtml"]);
     };
 }
示例#14
0
 public HomeModule()
 {
     Get["/"] = _ => {
         var allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["/contacts/new"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Post["/contact"] = _ => {
         Address newAddress = new Address(Request.Form["street"], Request.Form["city"], Request.Form["state"], Request.Form["zip"]);
         Contact newContact = new Contact(Request.Form["first-name"], Request.Form["last-name"], Request.Form["phone"], newAddress);
         return(View["contact_added.cshtml", newContact]);
     };
     Get["/contacts/{id}"] = parameters => {
         Contact requestedContact = Contact.Find(parameters.id);
         return(View["contact.cshtml", requestedContact]);
     };
     Post["/contacts/clear"] = _ => {
         Contact.ClearAll();
         return(View["address_book_clear.cshtml"]);
     };
     Post["/contacts/search"] = _ => {
         var    allContacts      = Contact.GetAll();
         var    matchingContacts = new List <Contact>();
         string searchString     = Request.Form["search"];
         searchString = searchString.ToLower();
         foreach (var contact in allContacts)
         {
             string firstName = contact.GetFirstName();
             string lastName  = contact.GetLastName();
             lastName  = lastName.ToLower();
             firstName = firstName.ToLower();
             if (firstName.Contains(searchString) || lastName.Contains(searchString))
             {
                 matchingContacts.Add(contact);
             }
         }
         return(View["search_results.cshtml", matchingContacts]);
     };
 }
示例#15
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"]);
            };
        }
示例#16
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml"]);
            };
            Get["/add_new_friend"] = _ => {
                return(View["friend-form.cshtml"]);
            };

            Get["/friends_list"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["friend-list.cshtml", allContacts]);
            };

            Post["/contact_created"] = _ => {
                Contact newContact = new Contact(Request.Form["friend-name"], Request.Form["friend-desc"], Request.Form["friend-address"], Request.Form["friend-phone"], Request.Form["friend-email"]);
                return(View["friend.cshtml", newContact]);
            };

            Post["/friend/new"] = _ => {
                Contact        newContact  = new Contact(Request.Form["friend-name"], Request.Form["friend-desc"], Request.Form["friend-address"], Request.Form["friend-phone"], Request.Form["friend-email"]);
                List <Contact> allContacts = Contact.GetAll();
                return(View["friend-list.cshtml", allContacts]);
            };

            Get["/friend/{id}"] = parameters => {
                Contact selectedContact = Contact.Find(parameters.id);
                return(View["friend.cshtml", selectedContact]);
            };
            Get["/contacts_deleted"] = _ => {
                Contact.ClearAll();
                return(View["friends-cleared.cshtml"]);
            };
            Get["/clear_friend/{id}"] = parameters => {
                List <Contact> allContacts = Contact.GetAll();
                allContacts.RemoveAt(parameters.id - 1);
                Contact.RefreshIds(allContacts);
                return(View["friend-list.cshtml", allContacts]);
            };
        }
示例#17
0
        public HomeModule()
        {
            Get["/"] = _ => {
                var contacts = Contact.GetAll();
                return(View["index.cshtml", contacts]);
            };

            Get["/contacts/new"] = _ => {
                return(View["contact_form.cshtml"]);
            };

            Post["/contacts/new"] = _ => {
                var address = new Address(
                    Request.Form["street"],
                    Request.Form["city"],
                    Request.Form["state"],
                    Request.Form["zip"]
                    );
                var contact = new Contact(
                    Request.Form["name"],
                    Request.Form["phoneNumber"],
                    address
                    );
                Contact.Save(contact);
                return(View["contact-created.cshtml", contact]);
            };
            Get["/contacts/{id}"] = parameters => {
                Contact contact = Contact.Find(parameters.id);
                return(View["contact-details.cshtml", contact]);
            };
            Get["/contacts/deleteAll"] = _ => {
                var contacts = Contact.GetAll();
                return(View["delete-contacts-form.cshtml", contacts]);
            };

            Post["/contacts/deleteAll"] = _ => {
                Contact.DeleteAll();
                return(View["contacts-deleted.cshtml"]);
            };
        }
示例#18
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["/contact/add"] = _ => {
         return(View["add_contact.cshtml"]);
     };
     Post["/contact/add"] = _ => {
         Contact newContact = new Contact(Request.Form["add-contact"], Request.Form["add-phoneNumber"], Request.Form["add-address"]);
         return(View["new_contact_confirmation.cshtml", newContact]);
     };
     Get["/contacts/{id}"] = parameters => {
         Contact contact = Contact.Find(parameters.id);
         return(View["contact_info.cshtml", contact]);
     };
     Post["/contacts/clear"] = _ => {
         Contact.ClearAll();
         return(View["cleared.cshtml"]);
     };
 }
 public HomeModule()
 {
     Get["/"] = _ => {
         var contacts = Contact.GetAll();
         return(View["index.cshtml", contacts]);
     };
     Get["/contact/new"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Get["/contact/{id}"] = parameters => {
         var searchedContact = Contact.Find(parameters.id);
         return(View["contact.cshtml", searchedContact]);
     };
     Post["/contact/new"] = _ => {
         var newContact = new Contact(Request.Form["contact-name"], Request.Form["phone-number"], Request.Form["contact-address"]);
         return(View["new_contact.cshtml", newContact]);
     };
     Post["/contact/clear"] = _ => {
         Contact.DeleteAll();
         return(View["contacts_cleared.cshtml"]);
     };
 }
示例#20
0
 public HomeModule()
 {
     Get["/"] = _ => {
         var allContacts = Contact.GetAll();
         return(View["index.cshtml", allContacts]);
     };
     Get["contact/{id}"] = parameters => {
         var contact = Contact.Find(parameters.id);
         return(View["view_one_contact.cshtml", contact]);
     };
     Get["/contact/new_contact"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Post["/contact/view_new_contact"] = _ => {
         Contact        newContact  = new Contact(Request.Form["new-name"], Request.Form["new-number"], Request.Form["new-address"]);
         List <Contact> allContacts = Contact.GetAll();
         return(View["view_new_contact.cshtml", newContact]);
     };
     Post["/contact/clear_contacts"] = _ => {
         Contact.ClearAll();
         return(View["clear_contacts.cshtml"]);
     };
 }
示例#21
0
        public HomeModule()
        {
            Get["/"] = _ => {
                var allContacts = Contact.GetAll();
                return(View["homepage.cshtml", allContacts]);
            };
            Get["/allcontacts/{id}"] = parameters => {
                Contact contact = Contact.Find(parameters.id);
                return(View["/contacts.cshtml", contact]);
            };

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

            Get["/contact"] = _ => {
                return(View["add_new_contact.cshtml"]);
            };
            Post["/contact/new"] = _ => {
                string inputName    = Request.Form["new-name"];
                int    inputPhone   = int.Parse(Request.Form["new-phone"]);
                string inputAddress = Request.Form["new-address"];

                Contact inputContact = new Contact(inputName, inputPhone, inputAddress);

                return(View["contact_added.cshtml", inputContact]);
            };
            Get["/allcontacts"] = _ => {
                return(View["allcontacts.cshtml", Contact.ViewAllContacts()]);
            };
            Post["/clear"] = _ => {
                Contact.ClearAllContacts();
                return(View["clear"]);
            };
        }
示例#22
0
 public HomeModule()
 {
     Get["/"] = _ => {
         List <Contact> allContacts = Contact.GetAll();
         return(View["contacts.cshtml", allContacts]);
     };
     Get["/contacts/new"] = _ => {
         return(View["contact_form.cshtml"]);
     };
     Get["/contact/{id}"] = parameters => {
         Contact selectedContact = Contact.Find(parameters.id);
         return(View["contact.cshtml", selectedContact]);
     };
     Get["/contact/delete/{id}"] = parameters => {
         Contact.Delete(parameters.id);
         List <Contact> allContacts = Contact.GetAll();
         return(View["contacts.cshtml", allContacts]);
     };
     Get["/contacts/search_form"] = _ => {
         return(View["search_form.cshtml"]);
     };
     Get["/contacts/search/{suggestion}"] = parameters => {
         string         userQuery        = parameters.suggestion;
         List <Contact> searchedContacts = Contact.Search(userQuery);
         if (searchedContacts.Count > 0)
         {
             return(View["contacts_searched.cshtml", searchedContacts]);
         }
         else
         {
             List <string> searchSuggestions = Contact.SuggestSearch(userQuery);
             return(View["search_suggestions.cshtml", searchSuggestions]);
         }
     };
     Post["/contact/new"] = _ => {
         string  contactName  = Request.Form["contact-name"];
         string  contactPhone = Request.Form["contact-phone"];
         Contact newContact   = new Contact(contactName, contactPhone);
         return(View["contact_made.cshtml", newContact]);
     };
     Post["/contacts/new_address_or_not/{id}"] = parameters => {
         string  addressOrNot    = Request.Form["address-or-not"];
         Contact selectedContact = Contact.Find(parameters.id);
         Address noAddress       = new Address("No Address", "", "", "");
         selectedContact.SetAddress(noAddress);
         if (addressOrNot == "return")
         {
             List <Contact> allContacts = Contact.GetAll();
             return(View["contacts.cshtml", allContacts]);
         }
         else
         {
             return(View["contact_address_form.cshtml", selectedContact]);
         }
     };
     Post["/contact/new_address/{id}"] = parameters => {
         string  contactStreet = Request.Form["contact-street"];
         string  contactApt    = Request.Form["contact-apt"];
         string  contactCity   = Request.Form["contact-city"];
         string  contactState  = Request.Form["contact-state"];
         string  contactZip    = Request.Form["contact-zip"];
         Address newAddress    = new Address(contactStreet, contactCity, contactState, contactZip);
         newAddress.AddStreet(contactApt);
         Contact selectedContact = Contact.Find(parameters.id);
         selectedContact.SetAddress(newAddress);
         return(View["address-added.cshtml", selectedContact]);
     };
     Post["/contacts/clear"] = _ => {
         Contact.ClearAll();
         return(View["contacts_clear.cshtml"]);
     };
     Post["/contacts/search"] = _ => {
         string         userQuery        = Request.Form["user-query"];
         List <Contact> searchedContacts = Contact.Search(userQuery);
         if (searchedContacts.Count > 0)
         {
             return(View["contacts_searched.cshtml", searchedContacts]);
         }
         else
         {
             List <string> searchSuggestions = Contact.SuggestSearch(userQuery);
             return(View["search_suggestions.cshtml", searchSuggestions]);
         }
     };
 }
示例#23
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Get["/contact/add"] = _ => {
                return(View["contact_form.cshtml"]);
            };

            Get["/contact/new"] = _ => {
                return(View["new_contact.cshtml"]);
            };

            Get["/contact/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact contact = Contact.Find(parameters.id);
                // List<Address> allAddresses = contact.GetAddress();
                var addressList = contact.GetAddress();
                model.Add("person", contact);
                model.Add("addresses", addressList);
                return(View["contact.cshtml", model]);
            };

            Get["{id}/address/new"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact        contact            = Contact.Find(parameters.id);
                List <Address> allAddresses       = contact.GetAddress();
                model.Add("person", contact);
                model.Add("addresses", allAddresses);
                return(View["add_address.cshtml", model]);
            };

            Post["/contact/new_address"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact        contact            = Contact.Find(Request.Form["contact-id"]);
                List <Address> allAddresses       = contact.GetAddress();
                string         newType            = Request.Form["new-type"];
                string         newStreet          = Request.Form["new-street"];
                string         newCity            = Request.Form["new-city"];
                string         newState           = Request.Form["new-state"];
                string         newZipCode         = Request.Form["new-zip-code"];
                Address        newAddress         = new Address(newType, newStreet, newCity, newState, newZipCode);
                allAddresses.Add(newAddress);
                model.Add("person", contact);
                model.Add("addresses", allAddresses);
                return(View["contact.cshtml", model]);
            };

            Post["/contact/new"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact        newContact         = new Contact(Request.Form["new-name"], Request.Form["new-phone-number"]);
                List <Address> allAddresses       = newContact.GetAddress();
                string         newType            = Request.Form["new-type"];
                string         newStreet          = Request.Form["new-street"];
                string         newCity            = Request.Form["new-city"];
                string         newState           = Request.Form["new-state"];
                string         newZipCode         = Request.Form["new-zip-code"];
                Address        newAddress         = new Address(newType, newStreet, newCity, newState, newZipCode);
                allAddresses.Add(newAddress);
                model.Add("person", newContact);
                model.Add("addresses", allAddresses);
                return(View["contact.cshtml", model]);
            };

            Post["/"] = _ => {
                Contact        newContact  = new Contact(Request.Form["new-name"], Request.Form["new-phone-number"]);
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Post["/"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Get["/contacts/clear"] = _ => {
                return(View["clear.cshtml"]);
            };

            Post["/contacts/clear"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                allContacts.Clear();
                return(View["clear.cshtml"]);
            };

            Post["/contact/delete/{id}"] = parameters => {
                Contact contact = Contact.Find(parameters.id);
                contact.Delete();
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Get["/contact/search"] = _ => {
                return(View["search_form.cshtml"]);
            };

            Post["/contact/search_results"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact selectedContact           = Contact.SearchContact(Request.Form["search-name"]);
                // List<Address> allAddresses = contact.GetAddress();
                var addressList = selectedContact.GetAddress();
                model.Add("person", selectedContact);
                model.Add("addresses", addressList);
                return(View["contact.cshtml", model]);
            };
        }
示例#24
0
        public HomeModule()
        {
            Get["/"] = _ => {
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Get["/add_contact"] = _ => {
                return(View["new_contact_form.cshtml"]);
            };

            Post["/"] = _ => {
                Contact        newContact  = new Contact(Request.Form["contact-name"]);
                List <Contact> allContacts = Contact.GetAll();
                return(View["index.cshtml", allContacts]);
            };

            Get["/contact/{id}"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact        selectedContact    = Contact.Find(parameters.id);
                List <Address> contactAddresses   = selectedContact.GetAddress();
                List <Number>  contactNumber      = selectedContact.GetNumber();
                model.Add("contact", selectedContact);
                model.Add("address", contactAddresses);
                model.Add("number", contactNumber);
                return(View["contact.cshtml", model]);
            };

            Get["/contact/{id}/address/new"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact        selectedContact    = Contact.Find(parameters.id);
                List <Address> allAddresses       = selectedContact.GetAddress();
                model.Add("contact", selectedContact);
                model.Add("address", allAddresses);
                return(View["new_address_form.cshtml", model]);
            };
            Get["/contact/{id}/number/new"] = parameters => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact       selectedContact     = Contact.Find(parameters.id);
                List <Number> allNumbers          = selectedContact.GetNumber();
                model.Add("contact", selectedContact);
                model.Add("number", allNumbers);
                return(View["new_number_form.cshtml", model]);
            };

            //       Post["/contact"] = _ => {
            //         Dictionary<string, object> model = new Dictionary<string, object>();
            //         Contact selectedContact = Contact.Find(Request.Form["contact-id"]);
            //         List<Address> contactAddress = selectedContact.GetAddress();
            //         string addressEntered = Request.Form["contact-address"];
            //         Address newAddress = new Address(addressEntered);
            //         contactAddress.Add(newAddress);
            //         model.Add("contact", selectedContact);
            //         model.Add("address", contactAddress);
            //         return View["contact.cshtml", model];
            //       };

            //       Get["/contact/numbers"] = _ => {
            //         List<Number> allNumbers = Number.GetAll();
            //         return View["contact_number.cshtml", allNumbers];
            //       };
            Post["/contact/"] = _ => {
                Dictionary <string, object> model = new Dictionary <string, object>();
                Contact        selectedContact    = Contact.Find(Request.Form["contact-id"]);
                List <Address> contactAddress     = selectedContact.GetAddress();
                List <Number>  contactNumber      = selectedContact.GetNumber();
                string         addressEntered     = Request.Form["contact-address"];
                string         numberEntered      = Request.Form["contact-number"];
                if (addressEntered != null)
                {
                    Address newAddress = new Address(addressEntered);
                    contactAddress.Add(newAddress);
                }
                if (numberEntered != null)
                {
                    Number newNumber = new Number(numberEntered);
                    contactNumber.Add(newNumber);
                }
                model.Add("contact", selectedContact);
                model.Add("address", contactAddress);
                model.Add("number", contactNumber);
                return(View["contact.cshtml", model]);
            };
        }