<% Option Explicit %> <% Class ContactsController Public Model Public Sub Index dim page_size : page_size = 10 dim page_num : page_num = Choice(Len(Request.Querystring("page_num")) > 0, Request.Querystring("page_num"), 1) dim page_count, record_count set Model = new PagedIndex_ViewModel_Class Model.Title = "Contacts" set Model.Contacts = ContactsRepository.FindPaged(empty, "ID", page_size, page_num, page_count, record_count) Model.CurrentPageNumber = page_num Model.PageSize = page_size Model.PageCount = page_count Model.RecordCount = record_count %> <% End Sub Public Sub Search dim searchValue:searchValue = Choice(Request.Form.Count = 0,Request.QueryString("q"),Request.Form("q")) dim page_size : page_size = 10 dim page_num : page_num = Choice(Len(Request.Querystring("page_num")) > 0, Request.Querystring("page_num"), 1) dim page_count, record_count set Model = new PagedIndex_ViewModel_Class Model.Title = "Contacts" set Model.Contacts = ContactsRepository.SearchTablePaged(Array("ID","%" & searchValue & "%","JURISCODE","%" & searchValue & "%","TownshipName","%" & searchValue & "%","CONTACT_NAME","%" & searchValue & "%","TownshipNum","%" & searchValue & "%","BUSINESS_ADDRESS","%" & searchValue & "%","TITLE","%" & searchValue & "%","BUSINESS_ADDRESS2","%" & searchValue & "%","BUSINESS_ADDRESS3","%" & searchValue & "%","MAILING_ADDRESS","%" & searchValue & "%","MAILING_ADDRESS2","%" & searchValue & "%","MAILING_ADDRESS3","%" & searchValue & "%","RESIDENTIAL_ADDRESS","%" & searchValue & "%","RESIDENTIAL_ADDRESS2","%" & searchValue & "%","PHONENUM1","%" & searchValue & "%","RESIDENTIAL_ADDRESS3","%" & searchValue & "%","FAXNUM","%" & searchValue & "%","PHONENUM2","%" & searchValue & "%","EMAIL","%" & searchValue & "%"),"ID", page_size, page_num, page_count, record_count) Model.CurrentPageNumber = page_num Model.PageSize = page_size Model.PageCount = page_count Model.RecordCount = record_count %> <% End Sub Public Sub Edit dim id : id = Request.QueryString("Id") set Model = new Edit_ViewModel_Class set Model.Contacts = ContactsRepository.FindByID(id) Model.Title = "Edit Contacts" HTMLSecurity.SetAntiCSRFToken "ContactsEditForm" %> <% Flash.Success = "Contacts Updated." End Sub Public Sub EditPost MVC.RequirePost HTMLSecurity.OnInvalidAntiCsrfTokenRedirectToActionExt "ContactsEditForm", Request.Form("nonce"), "Edit", Array("Id", Request.Form("Id")) dim ID : ID = Request.Form("Id") dim model : set model = ContactsRepository.FindByID(ID) set model = Automapper.AutoMap(Request.Form, model) 'model.Validate 'If model.Validator.HasErrors then FormCache.SerializeForm "EditContacts", Request.Form ' Flash.Errors = model.Validator.Errors ' MVC.RedirectToActionExt "Edit", Array("Id",ID) 'Else ContactsRepository.Update model FormCache.ClearForm "EditContacts" Flash.Success = "Contacts updated." MVC.RedirectToAction "Index" 'End If End Sub Public Sub Create dim form_params : set form_params = FormCache.DeserializeForm("NewContacts") If Not form_params Is Nothing then set Model = Automapper.AutoMap(form_params, New Create_ViewModel_Class) Else set Model = new Create_ViewModel_Class End If HTMLSecurity.SetAntiCSRFToken "ContactsCreateForm" %> <% End Sub Public Sub CreatePost MVC.RequirePost HtmlSecurity.OnInvalidAntiCSRFTokenRedirectToAction "ContactsCreateForm", Request.Form("nonce"), "Create" dim new_Contacts_model : set new_Contacts_model = Automapper.AutoMap(Request.Form, new ContactsModel_Class) 'new_Contacts_model.Validator.Validate 'If new_Contacts_model.Validator.HasErrors then ' FormCache.SerializeForm "NewContacts", Request.Form ' Flash.Errors = new_Contacts_model.Validator.Errors ' MVC.RedirectToAction "Create" 'Else ContactsRepository.AddNew new_Contacts_model ' FormCache.ClearForm "NewContacts" Flash.Success = "Contacts added." MVC.RedirectToAction "Index" 'End If End Sub Public Sub Delete dim id : id = Request.QueryString("Id") set Model = new Delete_ViewModel_Class set Model.Contacts = ContactsRepository.FindByID(id) Model.Title = "Delete Contacts" HTMLSecurity.SetAntiCSRFToken "ContactsDeleteForm" %> <% End Sub Public Sub DeletePost MVC.RequirePost HtmlSecurity.OnInvalidAntiCSRFTokenRedirectToAction "ContactsDeleteForm", Request.Form("nonce"), "Create" dim id : id = Request.Form("Id") ContactsRepository.Delete id Flash.Success = "Contacts deleted." MVC.RedirectToAction "Index" End Sub End Class MVC.Dispatch %>