Beispiel #1
0
        public async Task <HttpStatusCode> UpdateTask(int id, [FromBody] PreTodoModel data, string userId)
        {
            var TaskOwner = userId;
            var todoModel = await _context.TodoModel.FindAsync(id);

            if (data.TaskContent != string.Empty)
            {
                todoModel.TaskContent = data.TaskContent;
            }
            if (data.TaskHeader != string.Empty)
            {
                todoModel.TaskHeader = data.TaskHeader;
            }

            _context.Update(todoModel);
            await _context.SaveChangesAsync();

            return(HttpStatusCode.Accepted);
        }
Beispiel #2
0
        public async Task <HttpStatusCode> AddToList([FromBody] PreTodoModel preTodoModel, string userId)
        {
            if (userId == null)
            {
                return(HttpStatusCode.BadRequest);
            }

            TodoModel todoModel = new TodoModel(preTodoModel)
            {
                TaskOwner = userId
            };

            if (ModelState.IsValid)
            {
                _context.Add(todoModel);
                await _context.SaveChangesAsync();

                return(HttpStatusCode.Accepted);
            }

            return(HttpStatusCode.BadRequest);
        }