Beispiel #1
0
        public void Update(string id, TodoItemUpdate updatedItem)
        {
            var currentItem = _todoItemService.Retrieve(id);

            if (currentItem == null)
            {
                var message = $"Not able to retrieve todo item with Id: {id}";

                _logger.LogError(message);
                throw new Exception(message);
            }

            var statusChanged = updatedItem.Status.HasValue && updatedItem.Status.Value != currentItem.Status;

            var now = DateTime.UtcNow;

            var item = new TodoItemDataAccess
            {
                Id              = currentItem.Id,
                Title           = string.IsNullOrWhiteSpace(updatedItem.Title) ? currentItem.Title : updatedItem.Title,
                Description     = updatedItem.Description == null ? currentItem.Description : updatedItem.Description,
                Status          = !statusChanged ? currentItem.Status : updatedItem.Status.Value,
                CreatedDate     = currentItem.CreatedDate,
                LastUpdatedDate = now
            };

            _todoItemService.Update(id, item);

            if (statusChanged)
            {
                MakeStatusHistory(id, updatedItem.Status.Value, now);
            }
        }
Beispiel #2
0
        public async Task UpdateAsync(TodoItemUpdate todoItemUpdate)
        {
            var todoItem = _mapper.Map <TodoItem>(todoItemUpdate);

            _todoItemRepository.Update(todoItem);
            await _unitOfWork.SaveAsync();
        }
Beispiel #3
0
        public void Update(TodoItemUpdate todoItemUpdate)
        {
            var todoItem = _mapper.Map <TodoItem>(todoItemUpdate);

            _todoItemRepository.Update(todoItem);
            _unitOfWork.Save();
        }
        public async Task <ActionResult <int> > Put(int id, TodoItemUpdate todoItemUpdate)
        {
            todoItemUpdate.Id = id;
            await _todoItemService.UpdateAsync(todoItemUpdate);

            return(Ok(id));
        }
        /// <summary>
        /// Delete a Task
        /// </summary>
        /// <param name="taskid"></param>
        /// <returns></returns>
        public async Task <bool> UpdateTask(TodoItemUpdate task)
        {
            var    requestString = "/tasks/" + task.id + ".json";
            string postdata      = JsonConvert.SerializeObject(task);
            var    data          = await client.HttpClient.PutWithReturnAsync(requestString, new StringContent("{\"todo-item\": " + postdata + "}", Encoding.UTF8));

            var response = await client.HttpClient.PutAsync(requestString, null);

            return(false);
        }
        public IActionResult Update(string id, TodoItemUpdate todoItemIn)
        {
            _itemService.Update(id, todoItemIn);

            return(NoContent());
        }