Example #1
0
        // GET: Todos/Create
        public IActionResult Create()
        {
            var todoEditVM = new TodoEditViewModel
            {
                TagList = _context.Tags
            };

            return(View(todoEditVM));
        }
Example #2
0
        public IActionResult Update(int id)
        {
            var model = new TodoEditViewModel
            {
                Todo    = _todoService.GetById(id),
                Periods = this.GetOptions()
            };

            return(View(model));
        }
Example #3
0
        public IActionResult Add()
        {
            var model = new TodoEditViewModel
            {
                Todo    = new Todo(),
                Periods = this.GetOptions()
            };

            return(View(model));
        }
Example #4
0
        private Todo ViewModel_to_model(Todo todo, TodoEditViewModel editModel)
        {
            todo.Id          = editModel.Id;
            todo.Title       = editModel.Title;
            todo.TagId       = editModel.TagId;
            todo.Description = editModel.Description;
            todo.StartDate   = editModel.Date == DateTime.MinValue ? DateTime.Now : editModel.Date;

            return(todo);
        }
Example #5
0
        private TodoEditViewModel Model_to_viewModelAsync(Todo todo)
        {
            var editModel = new TodoEditViewModel
            {
                Id          = todo.Id,
                Title       = todo.Title,
                TagId       = todo.TagId,
                Description = todo.Description,
                Date        = todo.StartDate,
                TagList     = _context.Tags
            };

            return(editModel);
        }
Example #6
0
        public IActionResult Update(TodoEditViewModel model)
        {
            if (ModelState.IsValid)
            {
                model.Todo.UpdatedAt = DateTime.Now;
                _todoService.Update(model.Todo);
                TempData["success"] = "Todo item is successfully updated!";

                return(RedirectToAction("Index"));
            }
            else
            {
                ModelState.AddModelError("Error", "Some error(s) accured while attempting to save changes");
                return(View(model));
            }
        }
Example #7
0
        public async Task <IActionResult> Create(TodoEditViewModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            var todo = ViewModel_to_model(new Todo(), editModel);

            todo.OwnerID = _userManager.GetUserId(User);

            _context.Add(todo);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }
Example #8
0
        public ActionResult Edit(int id)
        {
            Todo todo = repository.Get(id);

            if (todo == null)
            {
                return(HttpNotFound());
            }

            TodoEditViewModel model = new TodoEditViewModel();

            model.CategoryId = todo.CategoryId;
            model.Id         = todo.Id;
            model.IsDone     = todo.IsDone;
            model.Title      = todo.Title;

            return(View(model));
        }
Example #9
0
        public ActionResult Edit(TodoEditViewModel model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            Todo todo = new Todo();

            todo.CategoryId = model.CategoryId;
            todo.Id         = model.Id;
            todo.IsDone     = model.IsDone;
            todo.Title      = model.Title;

            if (todo == null)
            {
                return(HttpNotFound());
            }

            repository.Update(todo);
            return(RedirectToAction("Index", new { categoryId = todo.CategoryId }));
        }
Example #10
0
        public async Task <IActionResult> Edit(int id, TodoEditViewModel editModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(editModel));
            }

            // Fetch Contact from DB to get OwnerID.
            var todo = await _context.Todos.SingleOrDefaultAsync(m => m.Id == id);

            if (todo == null)
            {
                return(NotFound());
            }

            todo = ViewModel_to_model(todo, editModel);

            _context.Update(todo);
            await _context.SaveChangesAsync();

            return(RedirectToAction("Index"));
        }