public Entities.Todo Add(Entities.Todo entity)
 {
     entity.Id = Guid.NewGuid();
     context.Set <Entities.Todo>().Add(entity);
     context.SaveChanges();
     return(entity);
 }
        public async Task <Entities.Todo> AddAsync(Entities.Todo todo)
        {
            todo.Id = todo.Id == Guid.Empty ? Guid.NewGuid() : todo.Id;
            _todoContext.Add(todo);
            await _todoContext.SaveChangesAsync();

            return(todo);
        }
 public void Update(Entities.Todo entity)
 {
     if (context.Entry(entity).State != EntityState.Modified)
     {
         context.Entry(entity).State = EntityState.Modified;
     }
     context.Set <Entities.Todo>().Update(entity);
     context.SaveChanges();
 }
예제 #4
0
        public async Task <int> Handle(AddTodo request, CancellationToken cancellationToken)
        {
            var todo = new Entities.Todo {
                Name = request.Name, Complete = false
            };

            _db.Add(todo);
            await _db.SaveChangesAsync(cancellationToken);

            return(todo.Id);
        }
        public async Task <Entities.Todo> UpdateAsync(Entities.Todo todo)
        {
            var local = _todoContext.Todos.Local.FirstOrDefault(entity => entity.Id == todo.Id);

            if (local is not null)
            {
                _todoContext.Entry(local).State = Microsoft.EntityFrameworkCore.EntityState.Detached;
            }
            _todoContext.Entry(todo).State = Microsoft.EntityFrameworkCore.EntityState.Modified;
            await _todoContext.SaveChangesAsync();

            return(todo);
        }
 public void Delete(Entities.Todo entity)
 {
     context.Set <Entities.Todo>().Remove(entity);
     context.SaveChanges();
 }