public HomeModule() { //routes go here Get["/"] = _ => { return View["index.cshtml"]; }; Get["/contacts"] = _ => { var allContacts = Contact.GetAll(); return View["contacts.cshtml", allContacts]; }; Get["/contacts/new"] = _ => { return View["contact_form.cshtml"]; }; Post["/contacts"] = _ => { var name = Request.Form["contact-name"]; var phoneNumber = Request.Form["contact-phone-number"]; var address = Request.Form["contact-address"]; var newContact = new Contact(name, phoneNumber, address); newContact.Save(); return View["contact_created.cshtml", newContact]; }; Post["/contacts_cleared"] = _ => { Contact.DeleteAll(); return View["contacts_cleared.cshtml"]; }; }
protected void Page_Load(object sender, EventArgs e) { if (Request.QueryString["ID"] != null && Request.QueryString["ID"] != "") { string id = Request.QueryString["ID"].ToString(); ContactList.Contact tmp = (ContactManager.GetContactInfoById(id, CON_STR)); fullName.Text = tmp.FirstName + " " + tmp.LastName; adressList = ContactManager.GetAdressesOfContact(id, CON_STR); phoneList = ContactManager.GetPhoneOfContact(id, CON_STR); loadInfo(); } else { for (int i = 0; i < 1000; i++) { fullName.Text += "ERROR!1!11!!"; } } }
public ContactEditorViewModel(Contact model) : base(model) { ProjectModel(); }
protected void btnSave_Click(object sender, EventArgs e) { if (tbSSNtmp.Text == "") { if (tbFName.Text != "" && tbLName.Text != "" && tbSSN.Text != "") { ContactManager.AddContact(tbFName.Text, tbLName.Text, tbSSN.Text, CON_STR); Response.Redirect("~/Main.aspx"); } else { Response.Write($"<script('#MyErrormessagescript>').style='display=block'</script>"); } } else { string ssn = tbSSNtmp.Text; string id = ContactManager.GetContactId(ssn, CON_STR); ContactList.Contact tmpContact = ContactManager.GetContactInfoById(id, CON_STR); if (id != "" && tmpContact != null) { string fname = ""; string lname = ""; string newSSN = ssn; if (tbFName.Text != "") { fname = tbFName.Text; } else { fname = tmpContact.FirstName; } if (tbLName.Text != "") { lname = tbLName.Text; } else { lname = tmpContact.LastName; } if (tbSSN.Text != "") { newSSN = tbSSN.Text; } else { newSSN = ssn; } int test = 0; Contact tmpCon = new Contact(fname, lname, newSSN); try { DateTime de = new DateTime(); if (DateTime.TryParse(tmpCon.PersonNr.Substring(0, 4) + "-" + tmpCon.PersonNr.Substring(4, 2) + "-" + tmpCon.PersonNr.Substring(6, 2), out de)) { test = 1; } } catch (Exception ex) { Response.Write(ex); } if (test == 1) { ContactManager.EditContact(id, fname, lname, newSSN, CON_STR); } } } Response.Redirect("~/Main.aspx"); }