コード例 #1
0
        public IList <ToDoItemViewModel> GetItems(int userId)
        {
            if (db.Tasks.Where(u => u.RemoteUserId == userId).Count() == 0)
            {
                db.Tasks.AddRange(remoteService.GetItems(userId).Select(t => new Task
                {
                    IsCompleted  = t.IsCompleted,
                    IsUploaded   = true,
                    Name         = t.Name,
                    RemoteUserId = t.UserId,
                    RemoteTaskId = t.ToDoId,
                    User         = db.Users.Single(u => u.RemoteId == userId)
                }));
                db.SaveChanges();
            }

            //return (new ToDoService()).GetItems(userId);
            return(db.Set <Task>().Where(u => u.RemoteUserId == userId && !u.IsDeleted).Select(
                       t =>
                       new ToDoItemViewModel
            {
                UserId = t.UserId,
                Name = t.Name,
                ToDoId = t.RemoteTaskId,
                IsCompleted = t.IsCompleted
            }
                       ).ToList());
        }
コード例 #2
0
        public async Task <IList <ToDoItemViewModel> > GetItemsAsync(int userId)
        {
            return(await Task.Run(() =>
            {
                db.Tasks.AddRange(remoteService.GetItems(userId).Select(t => new ToDoItem
                {
                    IsDeleted = false,
                    UserId = db.Users.Single(u => u.RemoteId == userId).Id,
                    IsCompleted = t.IsCompleted,
                    IsUploaded = true,
                    IsChanged = false,
                    Name = t.Name,
                    RemoteUserId = t.UserId,
                    RemoteTaskId = t.ToDoId,
                    User = db.Users.Single(u => u.RemoteId == userId)
                }));
                db.SaveChanges();

                return db.Set <ToDoItem>().Where(u => u.RemoteUserId == userId && !u.IsDeleted).Select(
                    t =>
                    new ToDoItemViewModel
                {
                    Id = t.Id,
                    UserId = t.UserId,
                    Name = t.Name,
                    ToDoId = t.RemoteTaskId,
                    IsCompleted = t.IsCompleted
                }
                    ).ToList();
            }
                                  ));
        }
コード例 #3
0
        private static void Update(ToDoItem item)
        {
            var dbTask = db.Set <ToDoItem>().Single(u => u.Id == item.Id);

            db.Entry(dbTask).CurrentValues.SetValues(item);
            db.Entry(dbTask).State = EntityState.Modified;
            db.SaveChanges();
        }