Exemple #1
0
        public ActionResult <Todo> SaveTodo(Todo todo)
        {
            todo.Id = todoRepository.GetAll().Count + 1;

            todoRepository.Add(todo);

            return(CreatedAtAction(nameof(GetTodo), new { id = todo.Id }, todo));
        }
Exemple #2
0
 public ActionResult <TodoItem> Post(TodoItem item)
 {
     if (item != null)
     {
         _todoRepository.Add(item);
         return(CreatedAtAction(nameof(Post), item));
     }
     return(BadRequest());
 }
 public IActionResult Create([FromBody] TodoItem item)
 {
     if (item == null)
     {
         return(BadRequest());
     }
     _todoRepository.Add(item);
     _logger.LogInformation(LoggingEvents.INSERT_ITEM, "Item {0} Created", item.Key);
     return(CreatedAtRoute("GetTodo", new { controller = "Todo", id = item.Key }, item));
 }
Exemple #4
0
        public async Task <IActionResult> AddItem(AddTodoViewModel addTodoViewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(addTodoViewModel));
            }
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            TodoItem item = new TodoItem(addTodoViewModel.TodoText, new Guid(user.Id));

            item.DateCreated = DateTime.Now;
            item.DateDue     = addTodoViewModel.DateDue;
            _repository.Add(item);

            if (addTodoViewModel.Labels != null)
            {
                string[] labels = addTodoViewModel.Labels.Split(',');
                foreach (string label in labels)
                {
                    _repository.AddLabel(label.Trim().ToLower(), item.Id);
                }
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                TodoItem newItem = new TodoItem(model.Text, await GetUserId());
                newItem.DateDue = model.DateDue;

                if (!string.IsNullOrEmpty(model.Labels))
                {
                    var lbls = model.Labels.Split(',').Select(tl => tl.Trim().ToLower());
                    foreach (var label in lbls)
                    {
                        if (label.Equals(""))
                        {
                            continue;
                        }

                        var newlbl = new TodoItemLabel(label);
                        var lbl    = _repository.LabelExists(newlbl);
                        if (!newItem.Labels.Contains(lbl))
                        {
                            newItem.Labels.Add(lbl);
                        }
                    }
                }
                _repository.Add(newItem);
                return(RedirectToAction("Index"));
            }
            return(View("Add"));
        }
Exemple #6
0
        public async Task <IActionResult> Add(AddTodoViewModel it)

        {
            if (ModelState.IsValid)

            {
                ApplicationUser applicationUser = await _userManager.GetUserAsync(HttpContext.User);

                TodoItem todo = new TodoItem(it.Text, new Guid(applicationUser.Id))

                {
                    DateDue = it.DateDue
                };

                if (it.Labels != null)

                {
                    string[] labels = it.Labels.Split(',');

                    List <TodoItemLabel> todoItemLabels = new List <TodoItemLabel>();

                    foreach (String label in labels)

                    {
                        _repository.AddLabel(label.Trim(), todo.Id, todo.UserId);
                    }
                }

                _repository.Add(todo);

                return(RedirectToAction("Index"));
            }

            return(View());
        }
Exemple #7
0
        async Task <GenericCommandResult> IRequestHandler <CreateTodoCommand, GenericCommandResult> .Handle(CreateTodoCommand request, CancellationToken cancellationToken)
        {
            var todo = new TodoItem(request.Title, false, request.Date, request.User);
            await _repository.Add(todo);

            return(new GenericCommandResult(true, "Tarefa salva", todo));
        }
Exemple #8
0
        private async Task <TodoTask> SetupNewTaskAsync(string name, string description, DateTime?dueDate)
        {
            var expected = _entityFactory.NewTodoTask(name, description, dueDate);
            await _repository.Add(expected);

            return((TodoTask)expected);
        }
Exemple #9
0
        public ActionResult Add([FromBody] TodoCreateDto dto)
        {
            if (dto == null)
            {
                return(BadRequest());
            }

            var entity = _mapper.Map <TodoEntity>(dto);

            entity.Created = DateTime.Now;

            var newEntity = _todoRespository.Add(entity);

            bool success = _todoRespository.Save();

            if (!success)
            {
                throw new Exception("Adding an item failed on save.");
            }

            return(CreatedAtRoute(
                       nameof(GetById),
                       new { id = newEntity.Id },
                       _mapper.Map <TodoDto>(entity)));
        }
Exemple #10
0
        public async Task <IActionResult> Add(AddTodoViewModel item)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManager.GetUserAsync(HttpContext.User);

                TodoItem todoItem = new TodoItem(item.Text, new Guid(currentUser.Id));
                todoItem.DateDue = item.DateDue;

                string[] splitLabels = item.Labels.Split('|');

                if (splitLabels.Length > 0)
                {
                    foreach (string label in splitLabels)
                    {
                        TodoItemLabel temp = new TodoItemLabel(label.Trim());
                        temp = _repository.ItemLabelCheck(temp);
                        todoItem.Labels.Add(temp);
                        //todoItem.Labels.Add(new TodoItemLabel(label));
                    }
                }
                _repository.Add(todoItem);
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemple #11
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                TodoItem todoItem = new TodoItem(model.Text, new Guid(user.Id));
                todoItem.DateDue = model.DateDue;
                try
                {
                    _repository.Add(todoItem);
                }
                catch (DuplicateTodoItemException ex)
                {
                    Log.Information(ex.Message);
                }
                String[] labels = model.separateLabels();
                if (labels != null)
                {
                    foreach (string label in labels)
                    {
                        TodoItemLabel todoItemLabel = _repository.AddLabel(label);
                        _repository.AddLabelToTodoItem(todoItemLabel, todoItem);
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View());
        }
Exemple #12
0
        public ActionResult AddTodo([FromBody] TodoCreateDto todoCreateDto)
        {
            if (todoCreateDto == null)
            {
                return(BadRequest());
            }

            TodoEntity item = _mapper.Map <TodoEntity>(todoCreateDto);

            item.Created = DateTime.UtcNow;
            TodoEntity newTodoEntity = _todoRepository.Add(item);

            if (!_todoRepository.Save())
            {
                throw new Exception("Adding an item failed on save.");
            }

            var dto = _mapper.Map <TodoDto>(newTodoEntity);

            _todoHubContext.Clients.All.SendAsync("TodoAdded", dto);

            return(CreatedAtRoute(
                       nameof(GetSingle),
                       new { id = newTodoEntity.Id },
                       dto));
        }
Exemple #13
0
        public async Task <IActionResult> AddItem(AddTodoViewModel added)
        {
            if (ModelState.IsValid)
            {
                var user = await FetchUser();

                var item = new TodoItem(added.Text, new Guid(user.Id))
                {
                    DateCreated = DateTime.Now,
                    DateDue     = added.DateDue
                };

                _repository.Add(item);

                if (!string.IsNullOrEmpty(added.Labels))
                {
                    string[] labels = added.Labels.Split(',');

                    foreach (string s in labels)
                    {
                        _repository.AddLabel(s.Trim().ToLower(), item.Id);
                    }
                }

                return(RedirectToAction("Index"));
            }

            return(View(added));
        }
Exemple #14
0
        public IActionResult Create([FromBody] TodoItem item)
        {
            _todoStore.Add(item);
            //return CreatedAtRoute("GetTodo", new { Key = item.Key }, item);

            return(new NoContentResult());
        }
        public async Task<IActionResult> Create([FromBody] TodoItem item)
        {
            var response = new SingleModelResponse<TodoItem>() as ISingleModelResponse<TodoItem>;
            TodoItem itemJustInserted = null;

            if (item == null)
            {
                response.DidError = true;
                response.ErrorMessage = "Cannot pass null value";
            }

            try
            {
                itemJustInserted = _todoRepository.Add(item);
                response.Message = "Inserted Successfully!";
            }
            catch (Exception ex)
            {
                response.DidError = true;
                response.ErrorMessage = ex.ToString();
            }

            response.Model = _todoRepository.Find(itemJustInserted.Key);

            return response.ToHttpResponse();
        }
Exemple #16
0
 public IActionResult Add(AddViewModel model)
 {
     if (ModelState.IsValid)
     {
         if (model.Text == null)
         {
             model.Text = "";
         }
         if (model.Labels == null)
         {
             model.Labels = "";
         }
         if ((!model.Time.HasValue) || ((DateTime.UtcNow - model.Time.Value).TotalSeconds > 0))
         {
             model.Time = null;
         }
         Guid     userId = new Guid(_userManager.GetUserId(User));
         TodoItem item   = new TodoItem(model.Text, userId);
         item.DateDue = model.Time;
         foreach (string label in model.Labels.Trim().Split(','))
         {
             if (label != "")
             {
                 item.Labels.Add(_repository.GenerateLabel(label));
             }
         }
         _repository.Add(item);
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
 public void Adicionar(Todo todo)
 {
     if (true)
     {
         _todoRepository.Add(todo);
     }
 }
Exemple #18
0
        public void AddTodoList(string todo)
        {
            var todoList = new TodoList(todo);

            _todoRepository.Add(todoList);
            Console.WriteLine("Sukses Menambah Todo : " + todoList.todo);
        }
Exemple #19
0
        public async Task <IActionResult> Add(AddTodoViewModel item)
        {
            if (ModelState.IsValid)
            {
                var currentUser = await _userManager.GetUserAsync(HttpContext.User);

                var storedLabels = await _repository.GetLabels();

                var todoItem = new TodoItem(item.Text, new Guid(currentUser.Id))
                {
                    DateDue = item.DateDue
                };
                foreach (var asociatedLabel in  item.SelectedLabels)
                {
                    var label = storedLabels.Find(t => t.Value.Equals(asociatedLabel));
                    if (label == null)
                    {
                        continue;
                    }
                    todoItem.Labels.Add(label);
                }
                _repository.Add(todoItem);
                return(RedirectToAction("Index"));
            }
            return(View(item));
        }
Exemple #20
0
        public async Task <IActionResult> Add(AddTodoViewModel model)

        {
            if (ModelState.IsValid)
            {
                var labels = new List <TodoItemLabel>();
                if (model.Labels != null)
                {
                    foreach (var label in model.Labels)
                    {
                        labels.Add(await _todoRepository.GetLabelAsync(label));
                    }
                }
                var todoItem = new TodoItem(model.Text, await GetCurrentUserId())
                {
                    DateDue = model.DateDue,
                    Labels  = labels
                };

                _todoRepository.Add(todoItem);

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public async Task <TodoItem> AddTodo([FromBody] TodoItem item)
        {
            var addNew = _iTodoRepo.Add(item);
            await _context.SaveChangesAsync();

            return(addNew);
        }
Exemple #22
0
        public async Task <IActionResult> Create(TodoCreateEditViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var todo = new TodoItem
            {
                Title      = vm.TodoItem.Title,
                Date       = vm.TodoItem.Date,
                CategoryId = vm.TodoItem.CategoryId,
                Complete   = vm.TodoItem.Complete,

                OwnerID = _userManager.GetUserId(User)
            };

            var isAuthorized = await _authorizationService.AuthorizeAsync(
                User, todo,
                Operations.Create);

            if (!isAuthorized.Succeeded)
            {
                return(new ChallengeResult());
            }

            _todoRepo.Add(todo);
            _todoRepo.Save();

            return(RedirectToAction(nameof(List)));
        }
Exemple #23
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            var user = await _userManager.GetUserAsync(User);

            if (user == null)
            {
                throw new ApplicationException($"Unable to load user with ID '{_userManager.GetUserId(User)}'.");
            }

            if (ModelState.IsValid)
            {
                var todoItem = new TodoItem(model.Text, new Guid(user.Id))
                {
                    DateDue = model.DateDue
                };
                await _repository.Add(todoItem);

                if (model.Labels != null)
                {
                    string[] split = model.Labels.Split(",".ToCharArray());
                    foreach (var label in split)
                    {
                        var lab = await _repository.AddLabelToDb(new TodoItemLabel(label.ToUpper().Trim()));

                        await _repository.AddLabelToTodoItem(lab, todoItem);
                    }
                }
                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
        public IActionResult Post([FromBody] TodoCreateVm todo)
        {
            var result = new Todo(todo.Description);

            _repository.Add(result);

            return(CreatedAtAction(nameof(TodoController.Get), new { id = result.Id }, TodoDisplayVm.FromTodo(result)));
        }
Exemple #25
0
 public void AddTodo(string name)
 {
     _repository.Add(new Task()
     {
         Name = name, Done = false
     });
     NotifyObservers();
 }
Exemple #26
0
        public Todo Post([FromBody] Todo todo)
        {
            todo.UserId = _currentUser.UserId;

            _todoRepository.Add(todo);

            return(todo);
        }
 public IActionResult Post([FromBody] TodoItem todo)
 {
     if (todo == null)
     {
         return(BadRequest());
     }
     _TodoItems.Add(todo);
     return(new NoContentResult());
 }
Exemple #28
0
 public IActionResult Create([FromBody, Required] TodoItem item)
 {
     if (item == null)
     {
         return(BadRequest());
     }
     _todoItems.Add(item);
     return(CreatedAtRoute("GetTodo", new { id = item.Key }, item));
 }
Exemple #29
0
 public IActionResult Create([FromBody] TodoItem item)
 {
     if (item == null)
     {
         return(BadRequest()); //400
     }
     _todoRepository.Add(item);
     return(CreatedAtRoute("GetTodo", new { id = item.Key }, item));
 }
Exemple #30
0
        // POST api/<controller>
        public HttpResponseMessage Post(TodoItem item)
        {
            TodoItem _todo = new TodoItem {
                Name = item.Name
            };

            _databasePlaceHolder.Add(_todo);
            return(Request.CreateResponse <TodoItem>(HttpStatusCode.Created, _todo));
        }