public async Task <CreatedResult> CreateTodo(string id, [FromBody] TodoCreateDataRepresentation data)
        {
            var userId = User.GetId();

            return((await _todoStore.Create(
                        userId,
                        userId, // context is the userId
                        data
                        .ThrowInvalidDataExceptionIfNull("Invalid todo create data")
                        .FromRepresentation(id, TodoType.Item),
                        Permission.FullControl,
                        CallerCollectionRights.Todo
                        ))
                   .MakeTodoUri(Url)
                   .MakeCreated());
        }
示例#2
0
        /// <summary>
        ///     Reverse map with validation across-the-wire representation into in-memory representation
        /// </summary>
        public static TodoCreateData FromRepresentation(
            this TodoCreateDataRepresentation todo,
            string parentId,
            TodoType type)
        {
            return(new TodoCreateData
            {
                Name = todo.Name
                       .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A todo requires a name"),

                Parent = parentId
                         .ThrowInvalidDataExceptionIfNullOrWhiteSpace("A todo requires a tenant"),

                Type = type,
                Due = todo.Due,
                State = todo.State
            });
        }