func (controller *contactsController) editGet(rw http.ResponseWriter, req *http.Request) (int, error) { vars := mux.Vars(req) contactID, err := strconv.ParseInt(vars["contactID"], 10, 64) if err != nil { return http.StatusInternalServerError, err } // Get the contact to edit contact := new(database.Contact) err = contact.GetContact(controller.DB, contactID) if err != nil { return http.StatusInternalServerError, err } isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer) contactEdit := new(viewmodels.ContactsEditViewModel) contactEdit.Name = contact.Name contactEdit.ContactID = contact.ContactID contactEdit.EmailAddress = contact.EmailAddress contactEdit.SmsNumber = contact.SmsNumber contactEdit.EmailActive = contact.EmailActive contactEdit.SmsActive = contact.SmsActive contactEdit.SelectedSites, err = getContactSiteIDs(controller, contact) if err != nil { return http.StatusInternalServerError, err } sites, errGet := getAllSites(controller) if errGet != nil { return http.StatusInternalServerError, errGet } vm := viewmodels.EditContactViewModel(contactEdit, sites, isAuthenticated, user, make(map[string]string)) vm.CsrfField = csrf.TemplateField(req) return http.StatusOK, controller.editTemplate.Execute(rw, vm) }
func (controller *contactsController) deleteGet(rw http.ResponseWriter, req *http.Request) (int, error) { vars := mux.Vars(req) contactID, err := strconv.ParseInt(vars["contactID"], 10, 64) if err != nil { return http.StatusInternalServerError, err } // Get the contact to edit contact := new(database.Contact) err = contact.GetContact(controller.DB, contactID) if err != nil { return http.StatusInternalServerError, err } isAuthenticated, user := getCurrentUser(rw, req, controller.authorizer) contactDelete := new(viewmodels.ContactsEditViewModel) contactDelete.Name = contact.Name contactDelete.ContactID = contact.ContactID contactDelete.EmailAddress = contact.EmailAddress var noSites = []database.Site{} vm := viewmodels.EditContactViewModel(contactDelete, noSites, isAuthenticated, user, make(map[string]string)) vm.CsrfField = csrf.TemplateField(req) return http.StatusOK, controller.deleteTemplate.Execute(rw, vm) }