public async Task <ActionResult <Todo> > PostTodo(Todo todo)
        {
            _todoRepository.Create(todo);
            await _todoRepository.SaveChangesAsync();

            return(CreatedAtAction("GetTodo", new { id = todo.TodoID }, todo));
        }
        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
                       ));
        }
        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));
            }
        }
Exemple #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));
        }
Exemple #5
0
 private static void InitializeDatabase(ITodoRepository repo)
 {
     if (!repo.GetAll().Any())
     {
         repo.Create(GetTestTodo());
     }
 }
        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);
        }
Exemple #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
                       ));
        }
        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()));
        }
        public async Task <ActionResult <TodoApiModel> > Post([FromBody] TodoRequestApiModel value)
        {
            var todo = new TodoEntity(TodoId.NewId(), value.Task);

            return(Result(
                       await repository.Create(todo)
                       ));
        }
Exemple #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));
        }
Exemple #12
0
        private CreateTodoOutput Persist(CreateTodoInput model)
        {
            var id = _respository.Create(model);

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

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

            if (res)
            {
                return(todo);
            }
            return(BadRequest());
        }
        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));
        }
Exemple #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
            });
        }
Exemple #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);
        }
        public TodoReadDto Create(int userId, TodoCreateDto dto)
        {
            Todo entity = dto.ToEntity();

            entity.UserId = userId;

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

            return(entity.ToReadDto());
        }
Exemple #20
0
        public Todo Create(Todo todo)
        {
            if (todo.Invalid)
            {
                return(todo);
            }

            _todoRepository.Create(todo);

            return(todo);
        }
 public void AddNewTodo(Todo todo)
 {
     if (todo == null)
     {
         throw new Exception();
     }
     else
     {
         todoRepository.Create(todo);
     }
 }
        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);
        }
Exemple #23
0
 public ActionResult <Todo> Create([FromBody] Todo item)
 {
     if (repository.Create(item))
     {
         return(item);
     }
     else
     {
         return(BadRequest());
     }
 }
Exemple #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));
        }
 public IActionResult OnPost()
 {
     if (Item.Id == 0)
     {
         repo.Create(Item);
     }
     else
     {
         repo.Update(Item);
     }
     return(Redirect("/"));
 }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }
Exemple #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));
        }