Beispiel #1
0
        public async Task <IActionResult> Edit(int id, [Bind("Id,Name,DeadlineDate,Description")] Todo.Model.Models.Task task)
        {
            if (id != task.Id)
            {
                return(NotFound());
            }

            if (ModelState.IsValid)
            {
                try
                {
                    _context.Update(task);
                    await _context.SaveChangesAsync();
                }
                catch (DbUpdateConcurrencyException ex)
                {
                    if (!Utils.TaskExists(task.Id, _context))
                    {
                        //RH:
                        //return Conflict();
                        //return NotFound();
                        return(Conflict(new { message = $"Record '{id}' was not found." }));
                    }
                    else
                    {
                        throw ex; //RH: Pocyztaj o różnicy między throw a throw ex
                    }
                }
                return(RedirectToAction(nameof(Index)));
            }
            return(View(task));
        }
Beispiel #2
0
        public async Task <IActionResult> Create([Bind("Id,Name,DeadlineDate,Description")] Todo.Model.Models.Task task)
        {
            if (ModelState.IsValid)
            {
                _context.Add(task);
                await _context.SaveChangesAsync();

                return(RedirectToAction(nameof(Index))); //RG: Duży plus za nameof!
            }
            return(View(task));
        }
Beispiel #3
0
        public void Put(int id, [FromBody] Todo.Model.Models.Task task)
        {
            var taskToUpdate = _context.Task.FirstOrDefault(x => x.Id == id);

            if (taskToUpdate != null)
            {
                taskToUpdate.Name         = task.Name;
                taskToUpdate.Description  = task.Description;
                taskToUpdate.DeadlineDate = task.DeadlineDate;
                _context.SaveChanges(); //RH: jw.
            }
        }
Beispiel #4
0
 public void Post([FromBody] Todo.Model.Models.Task task)
 {
     _context.Task.Add(task);
     _context.SaveChanges(); //RH: To jest nigdzie nie awaitowany Async, w razie problemów nie złapiesz wyjątków w żaden sposób
 }