Exemplo n.º 1
0
        /// <summary>
        /// Deletes the Item
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>
        public override Task <ToDoPostResponse> DeleteItem(ToDoQuery request, ServerCallContext context)
        {
            var item = (from data in _dataContext.ToDoDbItems
                        where data.Id == request.Id
                        select data).Single();


            _dataContext.ToDoDbItems.Remove(item);

            var result = _dataContext.SaveChanges();

            if (result > 0)
            {
                return(Task.FromResult(new ToDoPostResponse()
                {
                    Status = true,
                    StatusCode = 100,
                    StatusMessage = "Deleted Successfully"
                }));
            }
            else
            {
                return(Task.FromResult(new ToDoPostResponse()
                {
                    Status = false,
                    StatusCode = 500,
                    StatusMessage = "Issue Occured."
                }));
            }
        }
Exemplo n.º 2
0
        public async Task <QueryResult <ToDo> > GetToDos(ToDoQuery queryObj)
        {
            var result = new QueryResult <ToDo>();

            var query = context.ToDos
                        .Include(v => v.Priority)
                        .AsQueryable();

            query = query.ApplyFiltering(queryObj);

            var columnsMap = new Dictionary <string, Expression <Func <ToDo, object> > >()
            {
                ["priority"] = v => v.Priority.Name,
                ["name"]     = v => v.Name,
                ["done"]     = v => v.Done
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
        public async Task <QueryResult <ToDo> > GetToDos(ToDoQuery queryObj)
        {
            var result = new QueryResult <ToDo>();

            var query = context.ToDos.AsQueryable();

            query = query.ApplyFiltering(queryObj);

            var columnsMap = new Dictionary <string, Expression <Func <ToDo, object> > >()
            {
                ["Title"]        = v => v.Title,
                ["Body"]         = v => v.Body,
                ["CreationDate"] = v => v.CreationDate.ToString()
            };

            query = query.ApplyOrdering(queryObj, columnsMap);

            result.TotalItems = await query.CountAsync();

            query = query.ApplyPaging(queryObj);

            result.Items = await query.ToListAsync();

            return(result);
        }
Exemplo n.º 4
0
        /// <summary>
        /// Get Item with the Id
        /// </summary>
        /// <param name="request"></param>
        /// <param name="context"></param>
        /// <returns></returns>

        public override Task <ToDoData> GetToDoItem(ToDoQuery request, ServerCallContext context)
        {
            var result = from data in _dataContext.ToDoDbItems
                         where data.Id == request.Id
                         select data;

            return(Task.FromResult(result.First()));
        }
        public static IQueryable <ToDo> ApplyFiltering(this IQueryable <ToDo> query, ToDoQuery queryObj)
        {
            if (!String.IsNullOrEmpty(queryObj.Title))
            {
                query = query.Where(v => v.Title == queryObj.Title);
            }

            return(query);
        }
Exemplo n.º 6
0
        public static IQueryable <ToDo> ApplyFiltering(this IQueryable <ToDo> query, ToDoQuery queryObj)
        {
            if (queryObj.PriorityId.HasValue)
            {
                query = query.Where(v => v.Priority.Id == queryObj.PriorityId.Value);
            }

            if (!string.IsNullOrEmpty(queryObj.Name))
            {
                query = query.Where(v => v.Name.Contains(queryObj.Name));
            }

            return(query);
        }