public static Models.Tasks.TaskCreationInfo Convert(string clientUserId, ClientModels.Tasks.TaskCreationInfo clientCreationInfo)
        {
            if (clientUserId == null)
            {
                throw new ArgumentNullException(nameof(clientUserId));
            }

            if (clientCreationInfo == null)
            {
                throw new ArgumentNullException(nameof(clientCreationInfo));
            }

            if (!Guid.TryParse(clientUserId, out var modelUserId))
            {
                throw new ArgumentException($"The client user id \"{clientUserId}\" is invalid.", nameof(clientUserId));
            }

            var modelPriority = TaskPriorityConverter.Convert(clientCreationInfo.Priority);

            var modelCreationInfo = new Models.Tasks.TaskCreationInfo(
                modelUserId,
                clientCreationInfo.Title,
                clientCreationInfo.Text, clientCreationInfo.DeadLine, modelPriority);

            return(modelCreationInfo);
        }
Example #2
0
        public async Task <IActionResult> CreateTaskAsync([FromBody] ClientModels.Tasks.TaskCreationInfo creationInfo, CancellationToken cancellationToken)
        {
            cancellationToken.ThrowIfCancellationRequested();

            if (creationInfo == null)
            {
                return(this.BadRequest());
            }

            var userId = User.FindFirst(ClaimTypes.NameIdentifier).Value;

            //var userId = HttpContext.Items["userId"].ToString();
            var modelCreationInfo = TaskCreateInfoConverter.Convert(userId, creationInfo);
            var modelTaskInfo     = await this.tasks.CreateAsync(modelCreationInfo, cancellationToken);

            var clientTaskInfo = TaskInfoConverter.Convert(modelTaskInfo);

            var routeParams = new Dictionary <string, object>
            {
                { "taskId", clientTaskInfo.Id }
            };

            return(this.CreatedAtRoute("GetTaskRoute", routeParams, clientTaskInfo));
        }