public async Task NewEmail(string id) { // 根据id获取组 var group = LiteDb.SingleOrDefault <Group>(g => g._id == id); if (group == null) { await ResponseErrorAsync($"未通过{id}找到组"); return; } // 根据key来进行实例化 EmailInfo res; if (group.groupType == "send") { var emailInfo = Body.ToObject <SendBox>(); res = LiteDb.Upsert2(g => g.email == emailInfo.email, emailInfo); } else { var emailInfo = Body.ToObject <ReceiveBox>(); res = LiteDb.Upsert2(g => g.email == emailInfo.email, emailInfo); } await ResponseSuccessAsync(res); }
public async Task UpdateGroup(string id) { // 获取所有待更新的key List <string> keys = (Body as JObject).Properties().ToList().ConvertAll(p => p.Name); Group group = Body.ToObject <Group>(); var res = LiteDb.Upsert2(g => g._id == id, group, new Database.Definitions.UpdateOptions(keys)); await ResponseSuccessAsync(res); }
public async Task SendWithImageAndHtmlChanged() { var body = JObject.Parse(await HttpContext.GetRequestBodyAsStringAsync()); bool sendWithImageAndHtml = body.SelectToken("sendWithImageAndHtml").ValueOrDefault(false); // 判断是否存在设置项 LiteDb.Upsert2(s => s.userId == Token.UserId, new Setting() { userId = Token.UserId, sendWithImageAndHtml = sendWithImageAndHtml, }, new UpdateOptions() { "sendWithImageAndHtml" }); // 返回成功 await ResponseSuccessAsync("success"); }
public async Task IsAutoResendChanged() { var body = JObject.Parse(await HttpContext.GetRequestBodyAsStringAsync()); bool isAutoResend = body.SelectToken("isAutoResend").ValueOrDefault(true); // 判断是否存在设置项 LiteDb.Upsert2(s => s.userId == Token.UserId, new Setting() { userId = Token.UserId, isAutoResend = isAutoResend, }, new UpdateOptions() { "isAutoResend" }); // 返回成功 await ResponseSuccessAsync("success"); }
public async Task MaxEmailsPerDay() { var body = JObject.Parse(await HttpContext.GetRequestBodyAsStringAsync()); var value = body.SelectToken("maxCount").ValueOrDefault(0); // 判断是否存在设置项 LiteDb.Upsert2(s => s.userId == Token.UserId, new Setting() { userId = Token.UserId, maxEmailsPerDay = value, }, new UpdateOptions() { "maxEmailsPerDay" }); // 返回成功 await ResponseSuccessAsync("success"); }
public async Task SendIntervalChanged() { var body = JObject.Parse(await HttpContext.GetRequestBodyAsStringAsync()); double max = body.SelectToken("sendInterval.max").ValueOrDefault(8d); double min = body.SelectToken("sendInterval.min").ValueOrDefault(3d); // 判断是否存在设置项 LiteDb.Upsert2(s => s.userId == Token.UserId, new Setting() { userId = Token.UserId, sendInterval_max = max, sendInterval_min = min, }, new UpdateOptions() { "sendInterval_max", "sendInterval_min" }); // 返回成功 await ResponseSuccessAsync("success"); }
public async Task UpdateUserAvatar() { // 获取 body 传输的 url var avatarUrl = Body.SelectToken(Fields.avatar).ValueOrDefault(string.Empty); var userId = Body.SelectToken(Fields.userId).ValueOrDefault(string.Empty); if (string.IsNullOrEmpty(avatarUrl)) { await ResponseErrorAsync("请在 data 中传入 avatarUrl"); return; } if (string.IsNullOrEmpty(userId)) { await ResponseErrorAsync("请在 data 中传入 userName"); return; } var user = LiteDb.Fetch <User>(u => u.userId == userId).FirstOrDefault(); if (user == null) { await ResponseErrorAsync("用户不存在"); return; } // 更新头像 LiteDb.Upsert2(s => s.userId == Token.UserId, new User() { avatar = avatarUrl, }, new UpdateOptions() { Fields.avatar }); await ResponseSuccessAsync("success"); }
public async Task ModifyEmail(string id) { // 根据id判断属于发件还是收件 var sendbox = LiteDb.FirstOrDefault <SendBox>(s => s._id == id); if (sendbox != null) { var updateData1 = Body.ToObject <SendBox>(); var result1 = LiteDb.Upsert2(e => e._id == id, updateData1, new UpdateOptions(true) { "_id", "groupId" }); await ResponseSuccessAsync(result1); return; } // 收件情况 var receiveBox = LiteDb.FirstOrDefault <ReceiveBox>(r => r._id == id); if (receiveBox == null) { await ResponseErrorAsync($"未找到id:{id}对应的邮箱"); return; } var updateData2 = Body.ToObject <ReceiveBox>(); // 更新 var result2 = LiteDb.Upsert2(e => e._id == id, updateData2, new UpdateOptions(true) { "_id", "groupId" }); ResponseSuccessAsync(result2); }