Exemple #1
0
        public async Task <IActionResult> AssignUser([FromRoute] Guid id, [FromBody] AttachUserWithTaskCommand command /*,[FromRoute] Guid profileId*/)
        {
            try
            {
                command.TaskId = id;
                if (!ModelState.IsValid)
                {
                    return(base.BadRequest(ModelState));
                }

                //var result = await _mediator.Send(new AttachUserWithTaskCommand() { TaskId = taskId/*, UserId = profileId*/ });
                //var result = await _mediator.Send(new AttachUserWithTaskCommandResult());
                var result = await _mediator.Send <AttachUserWithTaskCommandResult>(command);

                return(base.Ok(result));
            }
            catch (NotFoundException)
            {
                return(base.NotFound());
            }
        }
        public async Task AssignUserWithTask(Guid id, AttachUserWithTaskCommand command)
        {
            try
            {
                _httpClient.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Bearer", await _authHandler.GetAuthAccessToken());
                var task = await GetById(id);

                var response = await _httpClient.PutAsJsonAsync <AttachUserWithTaskCommand>($"api/Tasks/{id}/AssignUser", command);

                if (response.IsSuccessStatusCode)
                {
                    var commandResult = await response.Content.ReadFromJsonAsync <AttachUserWithTaskCommandResult>();

                    var tasks = new List <TaskDto>(_tasksSubject.Value);

                    //For replacing the object
                    var idx = tasks.IndexOf(task);
                    if (idx >= 0)
                    {
                        tasks[idx] = commandResult.Payload;
                    }

                    _tasksSubject.OnNext(tasks);
                    _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                    {
                        IsSucceed = true,
                        Operation = "AttachUserWithTask"
                    });
                }
            }
            catch (Exception ex)
            {
                _apiCallResultSubject.OnNext(new ApiCallResult <string>()
                {
                    IsSucceed    = false,
                    Operation    = "AttachUserWithTask",
                    ErrorMessage = ex.Message
                });
            }
        }