public IActionResult SaveEntryTrg([FromForm] string entryId, [FromForm] string trg, [FromForm] string note) { if (entryId == null || trg == null || note == null) { return(StatusCode(400, "Missing parameter(s).")); } // Must be authenticated user int userId; string userName; auth.CheckSession(HttpContext.Request.Headers, out userId, out userName); if (userId < 0) { return(StatusCode(401, "Request must contain authentication token.")); } EditEntryResult res = new EditEntryResult(); int idVal = EntryId.StringToId(entryId); trg = trg.Replace("\r\n", "\n"); trg = trg.Replace('/', '\\'); trg = trg.Replace('\n', '/'); trg = "/" + trg + "/"; using (SqlDict.SimpleBuilder builder = dict.GetSimpleBuilder(userId)) { builder.ChangeTarget(userId, idVal, trg, note); } // Refresh cached contrib score auth.RefreshUserInfo(userId); // Tell our caller we dun it res.Success = true; return(new ObjectResult(res)); }
public IActionResult SaveFullEntry([FromForm] string entryId, [FromForm] string hw, [FromForm] string trg, [FromForm] string note, [FromForm] string lang) { if (entryId == null || hw == null || trg == null || note == null || lang == null) { return(StatusCode(400, "Missing parameter(s).")); } // Must be authenticated user int userId; string userName; auth.CheckSession(HttpContext.Request.Headers, out userId, out userName); if (userId < 0) { return(StatusCode(401, "Request must contain authentication token.")); } EditEntryResult res = new EditEntryResult(); int idVal = EntryId.StringToId(entryId); trg = trg.Replace("\r\n", "\n"); trg = trg.Replace('/', '\\'); trg = trg.Replace('\n', '/'); trg = "/" + trg + "/"; CedictParser parser = new CedictParser(); CedictEntry entry = null; try { entry = parser.ParseEntry(hw + " " + trg, 0, null); } catch { } if (entry == null) { res.Error = TextProvider.Instance.GetString(lang, "editEntry.badDataOnSave"); return(new ObjectResult(res)); } bool persisted; using (SqlDict.SimpleBuilder builder = dict.GetSimpleBuilder(userId)) { persisted = builder.ChangeHeadAndTarget(userId, idVal, hw, trg, note); } // Not persisted: violates uniqueness constraint if (!persisted) { res.Error = TextProvider.Instance.GetString(lang, "editEntry.duplicateOnSave"); return(new ObjectResult(res)); } // Refresh cached contrib score auth.RefreshUserInfo(userId); // Tell our caller we dun it res.Success = true; return(new ObjectResult(res)); }