public async Task <IActionResult> ToggleActive([FromRoute] int id) { // Gets the user and the routine to toggle active status var user = _context.AppUser.SingleOrDefault(u => u.UserName == User.Identity.Name); Routine toggledRoutine = _context.Routine.SingleOrDefault(r => r.RoutineId == id); // user authorize check if (toggledRoutine.AppUserId != user.Id) { return(Unauthorized()); } // Toggles the routine status and saves to DB toggledRoutine.IsActive = !(toggledRoutine.IsActive); _context.Entry(toggledRoutine).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!RoutineExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PutAppTask([FromRoute] int id, [FromBody] AppTask appTask) { var user = _context.AppUser.SingleOrDefault(u => u.UserName == User.Identity.Name); appTask.AppUser = user; if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != appTask.AppTaskId) { return(BadRequest()); } _context.Entry(appTask).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!AppTaskExists(id)) { return(NotFound()); } else { throw; } } var taco = _context.AppTask.Find(id); return(Ok(taco)); }