public async Task <int?> Delete(int id, string userId) { Models.Relation raw = await context.Relations.FindAsync(id); if (raw == null || (userId != null && raw.UserId != userId)) { return(null); } context.Relations.Remove(raw); await context.SaveChangesAsync(); return(id); }
public async Task <int?> Create(Relation data, string userId) { if ((await parent.NotesProvider.Get(data.From, userId) == null) || (await parent.NotesProvider.Get(data.To, userId) == null)) { return(null); } Models.Relation raw = Models.Relation.FromModel(data); if (userId != null) { raw.UserId = userId; } context.Relations.Add(raw); await context.SaveChangesAsync(); return(raw.Id); }
public async Task <int?> Update(int id, Relation data, string userId) { Models.Relation raw = await context.Relations.FindAsync(id); if (raw == null || (userId != null && raw.UserId != userId)) { return(null); } Models.Relation value = Models.Relation.FromModel(data); raw.From = value.From; raw.To = value.To; context.Relations.Update(raw); await context.SaveChangesAsync(); return(raw.Id); }