Ejemplo n.º 1
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());
        }
Ejemplo n.º 2
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));
        }
Ejemplo n.º 3
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"));
        }
Ejemplo n.º 4
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));
        }
Ejemplo n.º 5
0
        public async Task <IActionResult> AddNew(AddTodoViewModel todoViewModel)
        {
            if (!ModelState.IsValid)
            {
                todoViewModel.Message = "Text field must not be empty.";
                return(RedirectToAction("Add", todoViewModel));
            }

            var currentUser = await _userManager.GetUserAsync(HttpContext.User);

            var todoItem = new TodoItem(todoViewModel.Text, Guid.Parse(currentUser.Id))
            {
                DateDue = todoViewModel.DateDue
            };

            _repository.Update(todoItem, Guid.Parse(currentUser.Id));

            if (todoViewModel.Labels == null || todoViewModel.Labels.Trim().Length <= 0)
            {
                return(RedirectToAction("Index"));
            }

            var labels = new SortedSet <string>(todoViewModel.Labels.ToLower().Replace(",", " ").Replace("  ", " ").Trim().Split(' ').ToList());

            foreach (var l in labels)
            {
                var label = new TodoItemLabel(l);
                await _labelRepository.Update(label, todoItem);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 6
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));
        }
Ejemplo n.º 7
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());
        }
Ejemplo n.º 8
0
        public async Task <IActionResult> Add(AddTodoViewModel item)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }
            var currentUser = await _userManager.GetUserAsync(HttpContext.User);

            var _item = new TodoItem(item.Text, new Guid((currentUser.Id)))
            {
                DateDue = item.DateDue
            };

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

                foreach (var i in labels)
                {
                    var todoItemLabel = new TodoItem.TodoItemLabel(i.Trim());
                    if (_item.Labels.Contains(todoItemLabel))
                    {
                        continue;
                    }

                    _item.Labels.Add(todoItemLabel);
                }
            }
            await _repository.AddAsync(_item);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 9
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));
        }
Ejemplo n.º 10
0
        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"));
        }
Ejemplo n.º 11
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());
        }
Ejemplo n.º 12
0
 public IActionResult Add(AddTodoViewModel todoViewModel)
 {
     if (todoViewModel == null)
     {
         todoViewModel = new AddTodoViewModel();
     }
     return(View(todoViewModel));
 }
Ejemplo n.º 13
0
        public IActionResult Todo()
        {
            AddTodoViewModel todoViewModel = new AddTodoViewModel();

            todoViewModel.TodoList = _todoService.GetCompleteItems().ToList();

            return(View(todoViewModel));
        }
Ejemplo n.º 14
0
 public async Task <IActionResult> Add(AddTodoViewModel model)
 {
     if (ModelState.IsValid)
     {
         _repository.Add(new TodoItem(model.Text, await GetCurrentUserId()));
         return(RedirectToAction("Index"));
     }
     return(View(model));
 }
Ejemplo n.º 15
0
        public async Task <ActionResult> Add(AddTodoViewModel model)
        {
            await TodoService.AddAsync(new AddTodoServiceRequest
            {
                Title    = model.Title,
                Username = Username
            });

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 16
0
        public async Task <IActionResult> AddNewToDo(AddTodoViewModel m)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManager.GetUserAsync(HttpContext.User);

                var item = new TodoItem(m.Text, Guid.Parse(currentUser.Id));
                _repository.Add(item);
                return(RedirectToAction("Index"));
            }
            return(View("Add", m));
        }
Ejemplo n.º 17
0
        public async Task <IActionResult> Add(AddTodoViewModel m)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await
                                              _userManager.GetUserAsync(HttpContext.User);

                _repository.Add(new TodoSqlRepository.TodoItem(m.Text, new Guid(currentUser.Id)));
                return(RedirectToAction("Index"));
            }
            return(View(m));
        }
Ejemplo n.º 18
0
        public ActionResult Add(AddTodoViewModel AddTodoViewModel)
        {
            ToDo newTodo = new ToDo
            {
                Name        = AddTodoViewModel.Name,
                Description = AddTodoViewModel.Description
            };

            TodoData.Add(newTodo);

            return(Redirect("/ToDo"));
        }
Ejemplo n.º 19
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var userId = await GetCurrentUserIdAsync();

                var newItem = new TodoItem(model.Text, userId);
                _repository.Add(newItem);
                return(RedirectToAction("Index"));
            }

            return(View(model));
        }
Ejemplo n.º 20
0
        public IActionResult Add(AddTodoViewModel addTodoView)         //async
        {
            if (ModelState.IsValid)
            {
                TodoItem     item = new TodoItem(addTodoView.Text, _userId, addTodoView.DateDue);
                LabelManager lm   = new LabelManager(item, addTodoView.Labele, _repository);
                TodoItem     temp = lm.GetItemWithLabels();
                _repository.Add(temp);

                return(RedirectToAction("Index"));
            }

            return(View(addTodoView));
        }
Ejemplo n.º 21
0
        public async Task <IActionResult> Add(AddTodoViewModel vm)
        {
            ApplicationUser currentUser = await _user.GetUserAsync(HttpContext.User);

            var userId = currentUser.Id;

            if (ModelState.IsValid)
            {
                vm.UserId = userId;
                vm.DetermineLabels();
                _repository.Add(new TodoViewModel(vm));
                return(RedirectToAction("Index"));
            }
            return(View(vm));
        }
Ejemplo n.º 22
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser currentUser = await _userManager.GetUserAsync(HttpContext.User);

                TodoItem item;

                try
                {
                    item = new TodoItem(model.Text, Guid.Parse(await _userManager.GetUserIdAsync(currentUser)));
                }
                catch (FormatException ex)
                {
                    _repository.AddError(ex.Message);
                    return(View("Error"));
                }
                catch (ArgumentNullException ex)
                {
                    _repository.AddError(ex.Message);
                    return(View("Error"));
                }
                try
                {
                    item.DateDue = model.DateDue;
                    if (model.Label != null)
                    {
                        string[] labels = model.Label.Split(',');
                        foreach (string l in labels)
                        {
                            if (l.Trim() != "")
                            {
                                _repository.AddLabel(item, l.Trim());
                            }
                        }
                    }

                    _repository.Add(item);
                    return(RedirectToAction("Index"));
                }
                catch (DuplicateTodoItemException ex)
                {
                    _repository.AddError(ex.Message);
                    return(View());
                }
            }
            return(View());
        }
Ejemplo n.º 23
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (ModelState.IsValid)
            {
                var user = await _user.GetUserAsync(HttpContext.User);

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

                return(RedirectToAction("Index"));
            }
            return(View(model));
        }
Ejemplo n.º 24
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }
            else
            {
                var user = await _userManager.GetUserAsync(HttpContext.User);

                _repository.Add(new TodoItem(model.Text, new Guid(user.Id))
                {
                    DateDue = model.DateDue
                });
                // _repository.AddLabel(model.Label.Trim().ToLower(), new Guid(user.Id));
                return(RedirectToAction("Index"));
            }
        }
Ejemplo n.º 25
0
        public ActionResult Add(AddTodoViewModel todoViewModel)
        {
            Guid userId = getUserId();

            if (!ModelState.IsValid)
            {
                return(View(todoViewModel));
            }

            TodoItem item = new TodoItem();

            if (todoViewModel.Labels != null)
            {
                string[]         splits    = todoViewModel.Labels.Split(',');
                List <TodoLabel> labelList = new List <TodoLabel>();

                foreach (string label in splits)
                {
                    TodoLabel todoLabel = new TodoLabel(label.Trim());

                    labelList.Add(todoLabel);
                }

                item.Labels = labelList;
            }

            if (todoViewModel.DateDue.Equals(DateTime.MinValue))
            {
                item.DateDue = new Nullable <DateTime>();
            }
            else
            {
                item.DateDue = todoViewModel.DateDue;
            }
            item.Text          = todoViewModel.Text;
            item.UserId        = userId;
            item.DateCompleted = new Nullable <DateTime>();



            _repository.Add(item);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 26
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

            Guid userId = new Guid(user.Id);

            TodoItem newItem = new TodoItem(model.Text, userId);

            if (model.DateDue != null)
            {
                newItem.DateDue = (DateTime)model.DateDue;
            }
            else
            {
                newItem.DateDue = null;
            }
            if (!string.IsNullOrWhiteSpace(model.Labels))
            {
                string[] labelValues = model.Labels.Split(',');
                foreach (var labelValue in labelValues)
                {
                    string trimmedLabelValue = labelValue.Trim();

                    //if it isnt empty or null
                    if (!string.IsNullOrWhiteSpace(trimmedLabelValue))
                    {
                        TodoLabel existingLabel = _repository.GetLabel(trimmedLabelValue);
                        if (existingLabel == null)
                        {
                            TodoLabel newLabel = new TodoLabel(trimmedLabelValue);
                            _repository.AddLabel(newLabel);
                            newItem.Labels.Add(newLabel);
                        }
                        else
                        {
                            newItem.Labels.Add(existingLabel);
                        }
                    }
                }
            }

            _repository.Add(newItem);
            return(RedirectToAction("Index"));
        }
Ejemplo n.º 27
0
        public async Task <IActionResult> Add(AddTodoViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            var user = await _context.Users.FirstOrDefaultAsync();

            var newTodo = new Todo();

            newTodo.Name        = model.Name;
            newTodo.Description = model.Description;
            newTodo.User        = user;

            _context.Todos.Add(newTodo);
            _context.SaveChanges();

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 28
0
        public async Task <IActionResult> Add(AddTodoViewModel todoModel)
        {
            if (!ModelState.IsValid)
            {
                return(View());
            }

            ApplicationUser usr = await _userManager.GetUserAsync(HttpContext.User);

            TodoItem item = new TodoItem(todoModel.Text, usr.GuidId);

            item.DateCreated = DateTime.Now;
            item.DateDue     = todoModel.DateDue;

            string[] labels = todoModel.labels == null?new string[0] {
            }:todoModel.labels.Split(';');
            item.Labels = new List <TodoItemLabel>();

            foreach (string lab in labels)
            {
                TodoItemLabel existingLab = _repository.GetLabel(lab);
                if (existingLab != null)
                {
                    //existingLab.LabelTodoItems.Add(item);
                    item.Labels.Add(existingLab);
                }
                else
                {
                    TodoItemLabel newLabel = new TodoItemLabel(lab);
                    newLabel.LabelTodoItems.Add(item);
                    item.Labels.Add(newLabel);
                }
            }
            _repository.Add(item);

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 29
0
        public async Task <IActionResult> Add(AddTodoViewModel todoModel)
        {
            if (ModelState.IsValid)
            {
                ApplicationUser user = await _userManager.GetUserAsync(HttpContext.User);

                if (user == null)
                {
                    return(Forbid("User not found."));
                }
                List <string> labels = todoModel.Labels
                                       .Split(',')
                                       .Select(l => l.Trim())
                                       .Where(l => !string
                                              .IsNullOrWhiteSpace(l))
                                       .Distinct()
                                       .ToList();

                List <TodoItemLabel> labelList = await _todoRepository.GetLabelsAsync(labels);

                labels.Except(labelList.Select(l => l.Value)).ToList().ForEach(l2 =>
                {
                    labelList.Add(new TodoItemLabel(l2));
                });
                TodoItem todoItem = new TodoItem(todoModel.Text, Guid.NewGuid())
                {
                    UserId  = new Guid(user.Id),
                    DateDue = todoModel.DateDue,
                    Labels  = labelList
                };
                await _todoRepository.AddAsync(todoItem);

                return(RedirectToAction(nameof(Index)));
            }
            return(View(todoModel));
        }
Ejemplo n.º 30
0
        public ActionResult Add()
        {
            AddTodoViewModel AddTodoViewModel = new AddTodoViewModel();

            return(View(AddTodoViewModel));
        }