public ActionResult <TodoModel> CreateTodoItem(TodoModel item, string group) { if (item == null || string.IsNullOrEmpty(item.Content)) { _logger.LogInformation(LoggingEvents.InsertItem, "Empty item"); return(BadRequest()); } var entity = new TodoEntity { PartitionKey = group, RowKey = Guid.NewGuid().ToString(), Completed = item.Completed, Content = item.Content, Due = item.Due }; _repository.CreateTodoItem(entity); item.Id = entity.RowKey; item.Group = entity.PartitionKey; _logger.LogInformation(LoggingEvents.InsertItem, "Item {id} created in {group}", entity.RowKey, group); return(CreatedAtAction(nameof(GetTodoItem), new { group = entity.PartitionKey, id = entity.RowKey }, item)); }
public ActionResult Create([ModelBinder(typeof(NewTodoItemBinder))] TodoItemModel todoItemModel) { var userId = User.Identity.GetUserId(); var todoListId = todoItemModel.TodoListId; _repository.CreateTodoItem(userId, todoListId, todoItemModel.TodoItem); return(RedirectToAction("Index", "Todo", new { id = todoListId })); }
public async Task ProcessTodoRequest(HttpRequest httpRequest) { string requestBody = await new StreamReader(httpRequest.Body).ReadToEndAsync(); var todoModel = Newtonsoft.Json.JsonConvert.DeserializeObject <TodoModel>(requestBody); var todoEntity = _mapper.Map <TodoEntity>(todoModel); todoEntity.RowKey = Guid.NewGuid().ToString(); await _todoRepository.CreateTodoItem(todoEntity); }
public IActionResult CreateTodoItem(TodoItem todoItem) { IActionResult result; try { todoItem.Id = todoItem.Id ?? Guid.NewGuid(); _todoRepository.CreateTodoItem(todoItem); result = new CreatedResult(new Uri($"/todo/{todoItem.Id}", UriKind.Relative), todoItem); } catch (Exception exception) { result = new ObjectResult($"Error creating Todo: {exception.Message}."); } return(result); }