Beispiel #1
0
        public Task Create(TaskPostModel task)
        {
            Task toAdd = TaskPostModel.ToTask(task);

            context.Tasks.Add(toAdd);
            context.SaveChanges();
            return(toAdd);
        }
Beispiel #2
0
        public Taskk Create(TaskPostModel task, User addedBy)
        {
            Taskk toAdd = TaskPostModel.ToTask(task);

            toAdd.Owner = addedBy;
            context.Tasks.Add(toAdd);
            context.SaveChanges();
            return(toAdd);
        }
Beispiel #3
0
        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);
        }