示例#1
0
        public ToDoModule(IToDoStorage toDoStorage)
            : base("/todos")
        {
            Get["/"] = _ => Response.AsJson(toDoStorage.GetAll());

            Put["/"] = _ =>
                {
                    ToDo item = this.Bind();

                    if (item == null)
                    {
                        return HttpStatusCode.UnsupportedMediaType;
                    }

                    return Response.AsJson(toDoStorage.Add(item));
                };

            Post["/{id}"] = x =>
                {
                    ToDo item = this.Bind("id");

                    if (item == null)
                    {
                        return HttpStatusCode.UnsupportedMediaType;
                    }

                    item.id = x.id;
                    return Response.AsJson(toDoStorage.Update(item));
                };
        }
示例#2
0
 /// <summary>
 /// Initializes a new instance of the <see cref="BoardsController" /> class.
 /// </summary>
 /// <param name="todoStorage">The board storage.</param>
 /// <param name="mapper">The mapper.</param>
 /// <exception cref="System.ArgumentNullException">boardStorage</exception>
 public ToDosController(IToDoStorage todoStorage, IMapper mapper)
 {
     this._todoStorage = todoStorage ?? throw new ArgumentNullException(nameof(todoStorage));
     this._mapper      = mapper ?? throw new ArgumentNullException(nameof(mapper));
 }