Ejemplo n.º 1
0
        public IActionResult Put(Task task)
        {
            //Check if task exists
            if (!_db.Tasks.Any(p => p.Id == task.Id))
            {
                return(NotFound());
            }

            task.User   = _userManager.GetUserAsync(User).Result;
            task.UserId = _userManager.GetUserId(User);

            //Update the task in the database and saves it
            _db.Update(task);
            _db.SaveChanges();

            //Return 200 ok with the new task
            return(Ok(task));
        }
Ejemplo n.º 2
0
        public IActionResult Put(Task task)
        {
            //Check if task exists
            if (!_db.Tasks.Any(p => p.Id == task.Id))
            {
                return(NotFound());
            }

            //Connect the user and user id to the edit task.
            // We dod not connect it in the front-end so we take it here instead.
            task.User   = _userManager.GetUserAsync(User).Result;
            task.UserId = _userManager.GetUserId(User);

            //Update the task in the database and saves it
            _db.Update(task);
            _db.SaveChanges();

            //Return 200 ok with the new task
            return(Ok(task));
        }