Exemple #1
0
        public async Task <BaseToDoList> GetToDoListById(int itemId)
        {
            using (var context = new ToDoServiceDBContext())
            {
                BaseToDoList baseItem = (from item in context.ToDoLists
                                         join label in context.Labels
                                         on item.LabelId equals label.Id
                                         where item.Id == itemId
                                         select new BaseToDoList
                {
                    Id = item.Id,
                    Name = item.Name,
                }).FirstOrDefault();

                if (baseItem != null)
                {
                    baseItem.TodoItems = new List <BaseToDoItem>();
                    var db_item = await(from to_do_item in context.ToDoItems
                                        join label in context.Labels
                                        on to_do_item.LabelId equals label.Id
                                        where to_do_item.ToDoListId != null && to_do_item.ToDoListId.Value == baseItem.Id
                                        select new BaseToDoItem
                    {
                        Id   = to_do_item.Id,
                        Name = to_do_item.Name,
                    }).ToListAsync();

                    baseItem.TodoItems.AddRange(db_item);
                }
                return(baseItem);
            }
        }
Exemple #2
0
        public UpdateToDoListCommand ListToCommand(BaseToDoList item)
        {
            UpdateToDoListCommand command = new UpdateToDoListCommand
            {
                ToDoList = item
            };

            return(command);
        }
        public ToDoList MapListDTOToUpdateEntity(BaseToDoList baseToDo)
        {
            ToDoList itemList = new ToDoList()
            {
                Id          = baseToDo.Id,
                UpdatedDate = DateTime.Now,
                LabelId     = baseToDo.LabelId,
                Name        = baseToDo.Name,
                UserId      = baseToDo.UserId,
            };

            if (baseToDo.TodoItems != null && baseToDo.TodoItems.Count > 0)
            {
                itemList.TodoItems = new List <ToDoItem>();
                foreach (var item in baseToDo.TodoItems)
                {
                    itemList.TodoItems.Add(MapItemDTOToUpdateEntity(item));
                }
            }
            return(itemList);
        }