public async Task <TodoItemDto> AddAsync(AddTodoRequest request) { try { var todoItemToAdd = new TodoItem { Content = request.Content }; var todoItem = await _context.Todos.AddAsync(todoItemToAdd); var saved = await _context.SaveChangesAsync() > 0; if (!saved) { return(null); } return(new TodoItemDto { Id = todoItem.Entity.Id, Content = todoItem.Entity.Content, IsDone = todoItem.Entity.IsDone, }); } catch (Exception ex) { Console.WriteLine($"[ERR] {ex.Message}"); return(null); } }
public async Task <IActionResult> AddTodo([FromBody] AddTodoRequest request) { try { return(Ok(await this.todoService.Add(request))); } catch { return(StatusCode(StatusCodes.Status500InternalServerError)); } }
public async Task <IActionResult> AddTodo([FromBody] AddTodoRequest request) { try { return(Ok(await _todoService.AddTodo(request))); } catch (Exception e) { return(Problem(e.Message)); } }
public async Task <ActionResult <TodoItemDto> > AddTodoAsync([FromBody] AddTodoRequest request) { var res = await _service.AddAsync(request); if (res == null) { return(BadRequest()); } return(CreatedAtAction(nameof(AddTodoAsync), res.Id, res)); }
public override Task <AddTodoResponse> AddTodo(AddTodoRequest request, ServerCallContext context) { var fileName = BuildFilePath(request.Name); using (var fs = new FileStream(fileName, FileMode.Create)) using (var writer = new StreamWriter(fs)) { writer.Write(request.Content); writer.Close(); } //File.WriteAllLines(BuildFilePath(request.Name), new[] { request.Content }); return(Task.FromResult(new AddTodoResponse())); }
public async Task <TodoViewModel> AddTodo(AddTodoRequest request) { var todo = new Todo() { UserId = request.UserId, Title = request.Title, Text = request.Text, TargetDate = request.TargetDate, CreatedDate = DateTime.UtcNow }; await _context.Todos.AddAsync(todo); await _context.SaveChangesAsync(); return(new TodoViewModel() { Id = todo.Id, Text = todo.Text, Title = todo.Title, CreatedDate = todo.CreatedDate, TargetDate = todo.TargetDate }); }
public override async Task <AddTodoReply> AddTodo(AddTodoRequest request, ServerCallContext context) { var reply = new AddTodoReply() { Text = request.Text + " added" }; var todo = new Domain.Entities.Todo(); todo.Text = request.Text; dbContext.Todo.Add(todo); await dbContext.SaveChangesAsync(); await _todoHub.Clients.All.SendAsync("ReceiveTodo", new TodoItem() { Id = todo.Id.ToString(), Text = todo.Text }); return(reply); }
public Response <Todo> Add([FromBody] AddTodoRequest request) { if (!TryLogin(request)) { return(new Response <Todo> { Ok = false, Error = "Login ou mot de passe invalide" }); } User user = Database.GetUser(request.Login); if (string.IsNullOrEmpty(request.Title) || string.IsNullOrEmpty(request.Description)) { return(new Response <Todo> { Ok = false, Error = "Champs Title ou Description vide" }); } Todo newTodo = Database.AddTodo(user, request.Title, request.Description); if (newTodo != null) { return(new Response <Todo> { Ok = true, Resource = newTodo }); } return(new Response <Todo> { Ok = false, Error = "Hmm... something went wrong !" }); }
public async Task <IActionResult> Post(AddTodoRequest request) { return(await Eventor.SendStream <AddTodoRequest, AddTodoResponse>( request, x => x.Result)); }
async Task AddTodo() { await todoClient.AddTodoAsync(request); request = new AddTodoRequest(); }