示例#1
0
        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);
            }
        }
示例#2
0
 public async Task <IActionResult> AddTodo([FromBody] AddTodoRequest request)
 {
     try
     {
         return(Ok(await this.todoService.Add(request)));
     }
     catch
     {
         return(StatusCode(StatusCodes.Status500InternalServerError));
     }
 }
示例#3
0
 public async Task <IActionResult> AddTodo([FromBody] AddTodoRequest request)
 {
     try
     {
         return(Ok(await _todoService.AddTodo(request)));
     }
     catch (Exception e)
     {
         return(Problem(e.Message));
     }
 }
示例#4
0
        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()));
        }
示例#6
0
        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);
        }
示例#8
0
        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 !"
            });
        }
示例#9
0
 public async Task <IActionResult> Post(AddTodoRequest request)
 {
     return(await Eventor.SendStream <AddTodoRequest, AddTodoResponse>(
                request,
                x => x.Result));
 }
示例#10
0
        async Task AddTodo()
        {
            await todoClient.AddTodoAsync(request);

            request = new AddTodoRequest();
        }