public object GetEdit(string personId) { Person person = null; if (personId.IsNotNullOrWhiteSpace()) { var query = new Query("Data.Scripts.GetPersonByID", typeof(Person)) { new Query.Param("id", personId) }; person = AppContext.DataStore.LoadOneRow(query) as Person; } if (person == null) person = new Person { ID = Guid.NewGuid().ToString("N") }; return new Edit { Person = person }; }
public object SaveEdit(Person person) { if (person == null) person = new Person { ID = Guid.NewGuid().ToString("N") }; var error = person.Validate(); if (error == null) { AppContext.DataStore.Upsert(person); if (WorkContext.RequestedJSON) return new ClientRecord(person, null); else return new Redirect("/"); } if (WorkContext.RequestedJSON) return new ClientRecord(person, error); else return new Edit { Person = person, ValidationError = error }; }
public static string FormJSON(Person person, Exception validationError = null) { return RecordModelGenerator.RowToRecordInitJSON(person, validationError).ToJSON(); }