Exemplo n.º 1
0
        public async Task <ActionResult <Todo> > PostTodo(Todo todo)
        {
            _todoRepository.Create(todo);
            await _todoRepository.SaveChangesAsync();

            return(CreatedAtAction("GetTodo", new { id = todo.TodoID }, todo));
        }
Exemplo n.º 2
0
        public ICommandResult Handle(CreateTodoCommand command)
        {
            // Fail Fast Validation
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(
                           false,
                           "Ops, parece que sua tarefa está errada!",
                           command.Notifications
                           ));
            }

            // Gera entidade
            var todo = new TodoItem(command.Title, command.Date, command.User);

            //Salva no banco
            _repository.Create(todo);

            /// Retorna resultado
            return(new GenericCommandResult(
                       true,
                       "Tarefa Salva!",
                       todo
                       ));
        }
Exemplo n.º 3
0
        public override async Task <returnBool> CreateTodo(TodoReturn request, ServerCallContext context)
        {
            try
            {
                await _toporepository.Create(new Model.Todo
                {
                    Category = request.Category,
                    Content  = request.Content,
                    Title    = request.Title
                }).ConfigureAwait(false);

                var response = new returnBool()
                {
                    Bool = true
                };
                return(await Task.FromResult(response));
            }
            catch (Exception e)
            {
                var response = new returnBool()
                {
                    Bool = false
                };
                return(await Task.FromResult(response));
            }
        }
Exemplo n.º 4
0
        public ActionResult Create(CreateTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                DateTime startDate = GetDateTimeFromString(model.StartDate, model.StartTime);
                DateTime dueDate   = GetDateTimeFromString(model.DueDate, model.DueTime);

                Todo todo = new Todo
                {
                    Title       = model.Title,
                    Description = model.Description,
                    StartDate   = startDate,
                    DueDate     = dueDate,
                    AssignedTo  = model.AssignedTo,
                    Owner       = model.Owner
                };

                todoRepository.Create(todo);
                TempData["TodoSuccess"] = "Todo item " + todo.Title + " added successfully";
                return(RedirectToAction("Index", "Home"));
            }

            model.RegisteredUsers = GetRegisteredUsers();
            return(View(model));
        }
Exemplo n.º 5
0
 private static void InitializeDatabase(ITodoRepository repo)
 {
     if (!repo.GetAll().Any())
     {
         repo.Create(GetTestTodo());
     }
 }
Exemplo n.º 6
0
        public Todo Create(Todo todo)
        {
            Todo result;

            using (var uowTransaction = this.uow.Begin(repository, todoLogRepository))
            {
                try
                {
                    result = repository.Create(todo);
                    foreach (var todoLog in result.TodoLogs ?? Enumerable.Empty <TodoLog>())
                    {
                        todoLog.TodoId = result.Id;
                        todoLogRepository.Create(todoLog);
                    }
                    uowTransaction.Commit();
                }
                catch
                {
                    uowTransaction.Rollback();
                    throw;
                }
            }

            return(result);
        }
Exemplo n.º 7
0
        public ICommandResult Handle(CreateTodoCommand command)
        {
            //Fail Fast Validation
            if (command.Invalid)
            {
                return(new GenericCommandResult(
                           false,
                           "Ops",
                           command.Notifications
                           ));
            }

            //Gera Entidade
            var todo = new TodoItem(command.Title, command.Date, command.User);

            //Salva no banco
            _repository.Create(todo);

            //Retorna o Generic true
            return(new GenericCommandResult(
                       true,
                       "Tarefa Salva!",
                       todo
                       ));
        }
Exemplo n.º 8
0
        public async Task <ActionResult <TodoItem> > Post([FromBody] TodoItem todoItem)
        {
            todoItem.Id = await _repository.GetNextId();

            await _repository.Create(todoItem);

            return(new OkObjectResult(todoItem));
        }
        public async Task <Result> HandleAsync(CreateTodoCommand command)
        {
            var todo = await CreateTodo(command);

            await _todoRepository.Create(todo);

            return(await Task.FromResult(Result.Ok()));
        }
Exemplo n.º 10
0
        public async Task <ActionResult <TodoApiModel> > Post([FromBody] TodoRequestApiModel value)
        {
            var todo = new TodoEntity(TodoId.NewId(), value.Task);

            return(Result(
                       await repository.Create(todo)
                       ));
        }
Exemplo n.º 11
0
        public async Task <ActionResult <Todo.Todo> > Post([FromBody] Todo.Todo todo)
        {
            todo.Id = await _repo.GetNextId();

            await _repo.Create(todo);

            return(new OkObjectResult(todo));
        }
Exemplo n.º 12
0
        private CreateTodoOutput Persist(CreateTodoInput model)
        {
            var id = _respository.Create(model);

            _respository.Persist();
            return(new CreateTodoOutput {
                Id = id
            });
        }
Exemplo n.º 13
0
        private static void InitializeDatabase(ITodoRepository repo)
        {
            var todoList = repo.GetAll();

            if (!todoList.Any())
            {
                repo.Create(GetTestTodo());
            }
        }
Exemplo n.º 14
0
 public IActionResult Create([FromBody] TodoItem todoItem)
 {
     if (todoItem == null)
     {
         return(BadRequest());
     }
     TodoRepository.Create(todoItem);
     return(CreatedAtRoute("GetTodoItem", new { id = todoItem.Id }, todoItem));
 }
Exemplo n.º 15
0
        public ActionResult <Todo> Post([FromBody] Todo todo)
        {
            var res = repo.Create(todo);

            if (res)
            {
                return(todo);
            }
            return(BadRequest());
        }
Exemplo n.º 16
0
        public IActionResult Create([FromBody] Todo todo)
        {
            if (todo.TodoItems == null)
            {
                todo.TodoItems = new List <TodoItem>();
            }
            _todoRepository.Create(todo);

            return(CreatedAtRoute("GetTodo", new { id = todo.Id }, todo));
        }
Exemplo n.º 17
0
        public GetTodoDTO Create(CreateTodoDTO model)
        {
            var todo = _todoRepository.Create(new CreateTodoModel {
                Text = model.Text
            });

            return(new GetTodoDTO {
                Id = todo.Id, Text = todo.Text, Completed = todo.Completed
            });
        }
Exemplo n.º 18
0
        public async Task <OperationResult> Create(Todo item)
        {
            var operationResult = new OperationResult();

            try
            {
                if (!IsIdEmpty(item))
                {
                    operationResult.Error = new GenericError {
                        Code        = TodoListOperationCodes.IdViolation,
                        Description = "error creating a new todo item, todo item id must be empty for creation"
                    };
                }
                else if (IsNameEmpty(item))
                {
                    operationResult.Error = new GenericError {
                        Code        = TodoListOperationCodes.EmptyName,
                        Description = "error creating a new todo item, you must provide a name to the todo item"
                    };
                }
                else if (IsUserIdEmpty(item))
                {
                    operationResult.Error = new GenericError {
                        Code        = TodoListOperationCodes.EmptyUserIdentification,
                        Description = "error creating a new todo item, you must provide a user identification"
                    };
                }
                else
                {
                    var itemCreated = await _todoRepository.Create(item);

                    if (itemCreated == null)
                    {
                        operationResult.Error = new GenericError {
                            Code        = ErrorCodes.Unknow,
                            Description = "unkown error creating the todo item"
                        };
                    }
                    else
                    {
                        operationResult.Code   = UserOperationCodes.Created;
                        operationResult.Result = itemCreated;
                    }
                }
            }
            catch (Exception ex)
            {
                operationResult.Error = new GenericError {
                    Code        = ErrorCodes.InternalError,
                    Description = "internal error creating the todo item",
                    Exception   = ex
                };
            }
            return(operationResult);
        }
Exemplo n.º 19
0
        public TodoReadDto Create(int userId, TodoCreateDto dto)
        {
            Todo entity = dto.ToEntity();

            entity.UserId = userId;

            _repository.Create(entity);
            _repository.SaveChanges();

            return(entity.ToReadDto());
        }
Exemplo n.º 20
0
        public Todo Create(Todo todo)
        {
            if (todo.Invalid)
            {
                return(todo);
            }

            _todoRepository.Create(todo);

            return(todo);
        }
Exemplo n.º 21
0
 public void AddNewTodo(Todo todo)
 {
     if (todo == null)
     {
         throw new Exception();
     }
     else
     {
         todoRepository.Create(todo);
     }
 }
Exemplo n.º 22
0
        public void Create(string note)
        {
            var rand = new Random();
            var item = new TodoItem
            {
                Note           = note,
                ExpirationDate = DateTime.Now.AddMinutes(rand.Next(0, 30))
            };

            _todoRepository.Create(item);
        }
Exemplo n.º 23
0
 public ActionResult <Todo> Create([FromBody] Todo item)
 {
     if (repository.Create(item))
     {
         return(item);
     }
     else
     {
         return(BadRequest());
     }
 }
Exemplo n.º 24
0
        /// <summary>
        /// Creates the object
        /// </summary>
        /// <param name="description"></param>
        /// <returns></returns>
        public Task <Todos> CreateTodo(string description)
        {
            Devon4NetLogger.Debug($"SetTodo method from service TodoService with value : {description}");

            if (string.IsNullOrEmpty(description) || string.IsNullOrWhiteSpace(description))
            {
                throw new ArgumentException("The 'Description' field can not be null.");
            }

            return(_todoRepository.Create(description));
        }
Exemplo n.º 25
0
 public IActionResult OnPost()
 {
     if (Item.Id == 0)
     {
         repo.Create(Item);
     }
     else
     {
         repo.Update(Item);
     }
     return(Redirect("/"));
 }
Exemplo n.º 26
0
        public async Task <ActionResult <Todo> > Post([FromBody] Todo todo)
        {
            if (todo is null)
            {
                todo = new Todo();              //hack
            }
            todo.Id = await _repo.GetNextIdAsync();

            await _repo.Create(todo);

            return(new OkObjectResult(todo));
        }
Exemplo n.º 27
0
        public ICommandResult Handle(CreateTodoCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Ops, parece que sua tarefa está errada!", command.Notifications));
            }

            var todo = new TodoItem(command.Title, command.User, command.Date);

            _repository.Create(todo);

            return(new GenericCommandResult(true, "Tarefa salva", todo));
        }
Exemplo n.º 28
0
        public ICommandResult Handle(CreateTodoCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "Error creating TODO", command.Notifications));
            }

            var todo = new TodoItem(command.Title, command.User, command.Date);

            _repository.Create(todo);

            return(new GenericCommandResult(true, "TODO created!", todo));
        }
Exemplo n.º 29
0
        public ICommandResult Handle(CreateTodoCommand command)
        {
            command.Validate();
            if (!command.Valid)
            {
                return(new GenericCommandResult(false, "Houve um erro na solicitação", command.Notifications));
            }

            TodoItem item = new TodoItem(command.Title, command.Date, command.User);

            _repository.Create(item);

            return(new GenericCommandResult(true, "certo", item));
        }
Exemplo n.º 30
0
        public ICommandResult Handle(CreateTodoCommand command)
        {
            command.Validate();
            if (command.Invalid)
            {
                return(new GenericCommandResult(false, "ops, algo deu errado", command.Notifications));
            }

            var todo = new TodoItem(command.Title, command.Date, command.User, Guid.NewGuid());

            _todoRepository.Create(todo);

            return(new GenericCommandResult(true, "Tarefa salva", todo));
        }