public async Task <ChallengeTask> AddTaskAsync(ChallengeTask task) { int authUserId = GetClaimId(ClaimType.UserId); if (HasPermission(Permission.EditChallenges)) { var newTask = await _challengeTaskRepository.AddSaveAsync(GetClaimId(ClaimType.UserId), task); var challenge = await _challengeRepository.GetByIdAsync(task.ChallengeId); if (challenge.TasksToComplete <= challenge.Tasks.Count() && !challenge.IsValid) { await _challengeRepository.SetValidationAsync(authUserId, challenge.Id, true); } return(newTask); } _logger.LogError($"User {authUserId} doesn't have permission to add a task to challenge {task.ChallengeId}."); throw new Exception("Permission denied."); }
public override async Task <ChallengeTask> UpdateSaveAsync(int userId, ChallengeTask domainEntity) { await LookUpChallengeTaskTypeAsync(domainEntity); return(await base.UpdateSaveAsync(userId, domainEntity)); }
public override async Task UpdateAsync(int userId, ChallengeTask domainEntity) { await LookUpChallengeTaskTypeAsync(domainEntity); await base.UpdateAsync(userId, domainEntity); }
// Processing private void ProcessRequest(object sender, ConfirmationRequest request) { try { using (var db = new SQLite.SQLiteConnection(AppState.State.Instance.DbPath)) { if (request.UserId == AppState.State.Instance.UserDetails.UserId) { throw new ConfirmationException("Nemùžete potvrzovat vlastní požadavky"); } var r = db.Table <Model.User>(); var l = db.Get <Model.User>(request.UserId); var targetUser = db.Find <Model.User>(request.UserId); if (targetUser == null) { throw new ConfirmationException("Vaše zaøízení tohoto uživatele nerozpoznalo. Jeho požadavek nelze potvrdit."); } string dialogText; if (request.Type == ConfirmationType.Challenge) { var challenge = AppState.State.Instance.Challenges.FirstOrDefault((c) => c.Id == request.TargetId); if (challenge == null) { throw new ConfirmationException("Neznámá zkouška"); } dialogText = $"Uživatel { targetUser.Name} žádá o potvrzení zkoušky { challenge.Names[0].Name}. Potvrdit?"; } else { ChallengeTask task = null; foreach (var challenge in AppState.State.Instance.Challenges) { if ((task = challenge.BasicTasks.FirstOrDefault((t) => t.Id == request.TargetId)) != null) { break; } if ((task = challenge.ExtraTasks.FirstOrDefault((t) => t.Id == request.TargetId)) != null) { break; } } if (task == null) { throw new ConfirmationException("Neznámý úkol"); } dialogText = $"Uživatel { targetUser.Name} žádá o potvrzení úkolu { task.Name}. Potvrdit?"; } new AlertDialog.Builder(this) .SetTitle("Požadavek od uživatele") .SetMessage(dialogText) .SetPositiveButton("Ano", (o, e) => GenerateConfirmation(request)) .SetNegativeButton("Ne", CancelAction) .Create() .Show(); } } catch (Exception e) { new AlertDialog.Builder(this) .SetMessage("Pøi ovìøování došlo k chybì: " + e.Message) .SetNeutralButton("Ok", (o, ev) => { SetResult(Android.App.Result.Canceled); Finish(); }) .Create() .Show(); } }