void checkContact(int type, string name, RepairForm form = null) { if (string.IsNullOrEmpty(name)) { return; } Contact c = Database.QueryOne <Contact>($@"SELECT * FROM Contact WHERE Type = {type} AND RepairCafe = {Cafe} AND Name = {Database.Quote(name)} {(form == null || string.IsNullOrEmpty(form.Email) ? "" : ("AND Email = " + Database.Quote(form.Email)))}"); if (c.idContact == null) { c.Name = name; c.FullName = name; c.Type = type; if (form != null) { c.Email = form.Email; c.Postcode = form.Postcode; c.Phone = form.Phone; } Database.Update(c); } }
public Form EditForm(int id) { if (!GetCurrentCafe()) { return(null); } Form form = new Form(this, typeof(RepairForm), true, RCSession.RepairCafe.FormEntryFields.Split(',')); makeContactAutoComplete(form["Name"], "Name", ContactType.Visitor, "Email", "Phone", "Postcode", "CanContact"); makeContactAutoComplete(form["Email"], "Email", ContactType.Visitor); makeContactAutoComplete(form["Repairer"], "Email", ContactType.Repairer); makeRadio(form["ItemType"], SelectItemType()); makeRadio(form["Repaired"]); RepairForm f; if (id > 0) { Utils.Check(Database.TryGet(id, out f), "Repair Form not found"); form.CanDelete = true; } else { f = new RepairForm(); RepairForm previous = lastForm(); f.Date = previous.Date; f.FormNumber = previous.FormNumber + 1; } form.Data = f; form.Options["saveAndNew"] = true; return(form); }
public AjaxReturn EditFormSave(RepairForm json) { Database.BeginTransaction(); AjaxReturn r = SaveRecord(json); if (r.error == null) { checkContact(ContactType.Visitor, json.Name, json); checkContact(ContactType.Repairer, json.Repairer); Database.Commit(); } return(r); }