public async Task SetPreference(string userId, UserPreferenceType type, string value) { var existing = await _entities.UserPreferences.SingleOrDefaultAsync(x => x.UserId == userId && x.Key == type); var existed = existing != null; if (String.IsNullOrEmpty(value)) { if (existed) { _entities.UserPreferences.Remove(existing); await _entities.SaveChangesSafe(); } } else { existing = existing ?? new UserPreference { UserId = userId, Key = type }; existing.Value = value; if (!existed) { _entities.UserPreferences.Add(existing); } await _entities.SaveChangesSafe(); } }
private async Task ReceivedPreferenceAsync(IDialogContext context, IAwaitable <UserPreferenceType> result) { var prefType = await result; _prefType = prefType; await CommandPreferenceMenu(context, prefType); }
private async Task CommandPreferenceMenu(IDialogContext context, UserPreferenceType prefType) { try { var option = string.Empty; switch (prefType) { case UserPreferenceType.NickName: break; case UserPreferenceType.EndOfWorkTime: option = " hhmm の形式で"; break; case UserPreferenceType.EndOfConfirmTime: option = " hhmm の形式で"; break; case UserPreferenceType.DayOfWeekEnables: option = " 土日 のような形式で"; break; case UserPreferenceType.TimeZoneId: break; case UserPreferenceType.Cancel: default: context.Fail(new OperationCanceledException($"Unsuported prefType - {prefType}")); return; } var prompt = $"{prefType.ToAlias()} を{option}入力して下さい。" + "中止する場合は「中止」、「やめる」または「cancel」とタイプしてください。"; PromptDialog.Text(context, ReceivedPreferenceTextAsync, prompt); } catch (Exception ex) { Trace.WriteLine($"ReceivedPreferenceAsync failed - {ex.Message} - {ex.StackTrace}"); context.Fail(new OperationCanceledException($"ReceivedPreferenceAsync failed - {prefType}", ex)); } }
public async Task <User> Update(User user, UserPreferenceType prefType, string text) { var userEntity = await _userRepo.GetUserEntityById(user.UserId); switch (prefType) { case UserPreferenceType.NickName: userEntity.NickName = text; break; case UserPreferenceType.EndOfWorkTime: userEntity.AskEndOfWorkStartTime = text; break; case UserPreferenceType.EndOfConfirmTime: userEntity.AskEndOfWorkEndTime = text; break; case UserPreferenceType.DayOfWeekEnables: { // 有効な曜日群の抽出(例: 日火土→ 0101110) var dayOfWeelEnables = User.WEEKDAYS.Select(d => text.Contains(d) ? "0" : "1").Aggregate((x, y) => x + y); userEntity.DayOfWeekEnables = dayOfWeelEnables; } break; case UserPreferenceType.TimeZoneId: userEntity.TimeZoneId = text; break; case UserPreferenceType.Cancel: default: return(user); } await _userRepo.UpdateUser(userEntity); return(userEntity.ToModel()); }
public async Task ClearPreference(string userId, UserPreferenceType type) { await SetPreference(userId, type, null); }
internal Result(UserPreferenceType prefType, string text) { this.PrefType = prefType; this.Text = text; }