public async Task <bool> AddItem(ToDoItem item) { _context.Add(item); await _context.SaveChangesAsync(); ToDoChange change = new ToDoChange(item); item.AddChange(change); _context.Add(change); try { return(await _context.SaveChangesAsync() > 0 ? true : false); } catch (System.Exception exp) { return(false); } }
public async Task <bool> UpdateItem(ToDoItem item, long userId) {//обновляются только измененные свойства ToDoItem it = await GetItem(item.ID); if (userId != it.UserId) { return(false); } ToDoChange change = new ToDoChange(item); it.IsCompleted = item.IsCompleted; it.AddChange(change); _context.Add(change); _context.Entry(it).State = EntityState.Modified; try { return(await _context.SaveChangesAsync() > 0 ? true : false); } catch (Exception exp) { return(false); } }
public void AddChange(ToDoChange change) { this.IsCompleted = change.Status; this.RecentUpdate = DateTime.Now; Changes.Add(change); }