예제 #1
0
        public async Task <IActionResult> Delete(Guid id)
        {
            var todo = await _context.Todos.Where(TodoSpecifications.ById(id).Expression).FirstOrDefaultAsync();

            if (todo == null)
            {
                return(WhenTodoNull(id));
            }

            todo.MarkAs(TodoStatus.Abandoned);
            await _context.SaveChangesAsync();

            return(NoContent());
        }
예제 #2
0
        public async Task <IActionResult> Get(Guid id)
        {
            var todo = await _context.Todos.Where(TodoSpecifications.ById(id).Expression).FirstOrDefaultAsync();

            if (todo == null)
            {
                return(WhenTodoNull(id));
            }

            return(Ok(new
            {
                todo
            }));
        }
예제 #3
0
        public async Task <IActionResult> Put(Guid id, [FromBody] TodoBag value)
        {
            var todo = await _context.Todos.Where(TodoSpecifications.ById(id).Expression).FirstOrDefaultAsync();

            if (todo == null)
            {
                return(WhenTodoNull(id));
            }

            todo.UpdateFrom(value);
            await _context.SaveChangesAsync();

            return(AcceptedAtAction("Get", new { id = todo.Id }, todo));
        }
예제 #4
0
        public async Task <IQueryable <Todo_Master> > ListAsync(short[] statuses = null, string searchString = null)
        {
            var spec = Spec.Any <Todo_Master>();

            if (statuses?.Length > 0)
            {
                spec &= TodoSpecifications.ByStatusIDs(statuses);
            }
            if (!string.IsNullOrWhiteSpace(searchString))
            {
                spec &= TodoSpecifications.BySearchString(searchString);
            }
            var query = _repository.GetBySpecification(spec);

            return(await Task.FromResult(query));
        }