Exemplo n.º 1
0
        public virtual async Task <IActionResult> DeleteBatchAsync(KeyList <TKey> ids, QueryString queryString)
        {
            var query = Repository.Query.Where(p => ids.Contains(p.Id));

            query = ApplyRouteParams(query);

            var entityList = await query.ToListAsync();

            if (ids.Count() != entityList.Count())
            {
                var missingIds = ids.Except(entityList.Select(p => p.Id));
                return(await BuildResponseForNotFoundEntityAsync(missingIds, queryString));
            }

            Repository.RemoveRange(entityList);

            var flowResult = await Flow.DeleteAsync(entityList, SaveAsync);

            if (flowResult != null)
            {
                return(flowResult);
            }

            return(NoContent());
        }
Exemplo n.º 2
0
        public virtual async Task <IActionResult> DeleteAsync(TKey id, QueryString queryString)
        {
            var query = Repository.Query.Where(p => p.Id.Equals(id));

            query = ApplyRouteParams(query);

            var entity = await query.FirstOrDefaultAsync();

            if (entity == null)
            {
                return(await BuildResponseForNotFoundEntityAsync(id, queryString));
            }

            Repository.Remove(entity);

            var flowResult = await Flow.DeleteAsync(entity, SaveAsync);

            if (flowResult != null)
            {
                return(flowResult);
            }

            return(NoContent());
        }