public AjaxReturn DetailSave(Full_Member json) { Utils.Check(json.MemberTypeId > 0, "Must choose membership type"); Utils.Check(!string.IsNullOrWhiteSpace(json.Name), "Name must be filled in"); Utils.Check(json.MemberNo > 0, "Must assign a membership number"); Utils.Check(json.PaymentAmount >= 0, "Payment amount may not be negative"); if (json.idMember == null && json.PaymentAmount == 0 && json.NumberOfPayments > 0) { json.PaymentAmount = Math.Round(json.AnnualSubscription / json.NumberOfPayments); } Database.BeginTransaction(); // Record contains most of the data from the associated NameAddress record - save that first JObject nameAddress = json.ToJObject(); if (json.NameAddressId > 0) { nameAddress["idNameAddress"] = json.NameAddressId; } nameAddress["Type"] = "M"; Database.Update("NameAddress", nameAddress); json.NameAddressId = nameAddress.AsInt("idNameAddress"); AjaxReturn r = SaveRecord(json, true); if (r.error == null) { Database.Commit(); } return(r); }
/// <summary> /// Get record for editing /// </summary> public void Detail(int id) { Full_Member record = Database.Get <Full_Member>(id); if (record.Id == null) { JObject r = Database.QueryOne("SELECT MAX(MemberNo) AS MaxMemberNo FROM Member"); record.MemberNo = r == null ? 1 : r.AsInt("MaxMemberNo") + 1; } else { Title += " - " + record.Name; } Form form = new CodeFirstWebFramework.Form(this, typeof(Full_Member), true); form.Remove("NameAddressId"); form.Remove("MemberTypeName"); form["MemberTypeId"].MakeSelectable(SelectMemberTypes()); Form = form; form.Data = record.ToJToken(); }