Ejemplo n.º 1
0
        public HomeModule()
        {
            Get["/"] = _ => {
                return(View["index.cshtml", Contact.GetAll()]);
            };

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

            Post["/contact/new"] = _ => {
                if (Request.Form["name"] == "")
                {
                    string  noName     = "No Name";
                    Contact newContact = new Contact(noName, Request.Form["phone"], Request.Form["address"]);
                    return(View["new_contact.cshtml", newContact]);
                }
                else
                {
                    Contact newContact = new Contact(Request.Form["name"], Request.Form["phone"], Request.Form["address"]);
                    return(View["new_contact.cshtml", newContact]);
                }
            };

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

            Post["/{action}"] = parameters => {
                if (parameters.action == "clear")
                {
                    Contact.ClearAll();
                }
                return(View["clear.cshtml"]);
            };

            Post["/contact/"] = _ => {
                int contactId = Request.Form["contact-id"];
                Contact.RemoveContact(contactId);
                return(View["removed.cshtml"]);
            };

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

            Post["/contact/search_result"] = _ => {
                string searchName    = Request.Form["search"];
                var    searchResults = Contact.SearchContact(searchName);
                return(View["results.cshtml", searchResults]);
            };
        }
Ejemplo n.º 2
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]);
            };
        }