Esempio n. 1
0
        public async Task <ActionResult> Create(TaskItem item)
        {
            if (!ModelState.IsValid)
            {
                return(View(item));
            }
            await _itemsRepo.AddItemAsync(item);

            return(RedirectToAction("Index"));
        }
Esempio n. 2
0
        public async Task <ActionResult <TaskItem> > CreateAsync(TaskItem taskItem)
        {
            if (!User.Identity.IsAuthenticated)
            {
                return(Unauthorized());
            }
            if (!(string.IsNullOrEmpty(taskItem.Id) && User.Identity.Name?.Equals(taskItem.Owner) == true))
            {
                return(BadRequest());
            }

            var createdItem = await _itemsRepo.AddItemAsync(taskItem);

            return(CreatedAtAction(nameof(GetAsync), new { id = createdItem.Id }, createdItem));
        }