Esempio n. 1
0
        public List <string> GetTask(TasksDTO data)
        {
            var userId = db.Users.FirstOrDefault(x => x.Username == data.Username).Id;
            //var task = db.Users.Include(x => x.Tasks).FirstOrDefault(u => u.Id == userId).Tasks.Select(x => x.Text).ToList();
            var task = db.Task.Where(x => x.UserId == userId).Select(x => x.Text).ToList();

            //var task = db.Task.Where(x => x.UserId == userId).Select(x => new { Text = x.Text, Id = x.Id }).ToList(); return Ok(task) IActionResult
            return(task);
        }
Esempio n. 2
0
        public IActionResult AddTaskToUser(TasksDTO data)
        {
            var user = db.Users.Include(x => x.Tasks).FirstOrDefault(u => u.Username == data.Username);
            var task = new Registration.Data.Models.Task()
            {
                Text = data.TextareaValue, UserId = user.Id
            };

            user.Tasks.Add(task);
            db.SaveChanges();
            return(Ok());
        }