Пример #1
0
        public async Task <TodoItem> Add([FromBody] TodoItem todoItem)
        {
            _todoContext.Todos.Add(todoItem);
            await _todoContext.SaveChangesAsync();

            return(todoItem);
        }
Пример #2
0
        public async Task <Todo> CreateTodo(Todo todo, CancellationToken cancellationToken)
        {
            _context.Todos.Add(todo);

            await _context.SaveChangesAsync(cancellationToken);

            return(todo);
        }
Пример #3
0
        public async Task <IActionResult> Delete(int id)
        {
            var toDelete = _context.TodoItems
                           .SingleOrDefault(x => x.Id == id);

            if (toDelete == null)
            {
                return(NotFound($"TodoItem with id: {id} could not be found"));
            }

            _context.TodoItems.Remove(toDelete);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
Пример #4
0
            public async Task <UpdateTodoItemCommandResult> Handle(UpdateTodoItemCommand request)
            {
                var item = await _context.TodoLists
                           .Where(x => x.Id == request._parentId)
                           .SelectMany(x => x.TodoItems)
                           .Where(x => x.Id == request._id)
                           .SingleOrDefaultAsync();

                item.Title    = request.UpdateView.Title;
                item.Priority = request.UpdateView.Priority;
                item.DueDate  = request.UpdateView.DueDate;
                item.Note     = request.UpdateView.Note;
                //item.Status = request.UpdateView.Status;

                await _context.SaveChangesAsync();

                return(new UpdateTodoItemCommandResult
                {
                    Successfull = true,
                    Data = new ViewModel.TodoItem.ListView
                    {
                        Title = item.Title,
                        Priority = item.Priority,
                        Status = item.Status,
                        DueDate = item.DueDate,
                    }
                });
            }
Пример #5
0
        public async Task <TView> Create <TView>(ICreate <TEntity> toCreate, Expression <Func <TEntity, TView> >?selectExpression)
            where TView : IViewOf <TEntity>
        {
            var data = _mapper.Map <TEntity>(toCreate);

            var created = _repository.Add(data).Entity;
            await _context.SaveChangesAsync();

            return(_mapper.Map <TView>(created));
        }
Пример #6
0
            public async Task <CreateTodoListCommandResult> Handle(CreateTodoListCommand request)
            {
                var color = System.Drawing.ColorTranslator.FromHtml(request._toCreate.LabelColor);

                color = Color.FromArgb(color.R, color.G, color.B);

                var newEntity = _context.TodoLists.Add(new Entities.TodoList
                {
                    Title      = request._toCreate.Title,
                    LabelColor = color
                }).Entity;

                await _context.SaveChangesAsync();

                return(new CreateTodoListCommandResult
                {
                    Successfull = true,
                    Data = new CreatedView
                    {
                        Title = newEntity.Title
                    }
                });
            }