public Task Create(TaskPostModel task) { Task toAdd = TaskPostModel.ToTask(task); context.Tasks.Add(toAdd); context.SaveChanges(); return(toAdd); }
public Taskk Create(TaskPostModel task, User addedBy) { Taskk toAdd = TaskPostModel.ToTask(task); toAdd.Owner = addedBy; context.Tasks.Add(toAdd); context.SaveChanges(); return(toAdd); }
public Task Upsert(int id, TaskPostModel task) { var existing = context.Tasks.AsNoTracking().FirstOrDefault(f => f.Id == id); if (existing == null) { Task toAdd = TaskPostModel.ToTask(task); context.Tasks.Add(toAdd); context.SaveChanges(); return(toAdd); } Task toUpdate = TaskPostModel.ToTask(task); toUpdate.Id = id; context.Tasks.Update(toUpdate); context.SaveChanges(); return(toUpdate); }