public async Task <IActionResult> Fit(int id) { Fit fit = await _Db.Fits.Where(c => c.Id == id && c.AccountId == User.AccountId()).FirstOrDefaultAsync(); if (fit == null) { return(NotFound("The fit was not found or you do not have access to it.")); } _Db.Remove(fit); await _Db.SaveChangesAsync(); return(Ok()); }
public async Task <IActionResult> Revoke(IFormCollection request) { // Parse inputs as ints int.TryParse(request._str("accountId"), out int accountId); int.TryParse(request._str("roleId"), out int roleId); // Validate to ensure the required fields were returned. if (accountId == 0 || roleId == 0) { return(BadRequest("Invalid role or account ID provided")); } if (accountId == User.AccountId()) { return(Unauthorized("You are not allowed to remove your own groups")); } var accountRole = await _Db.AccountRoles .Where(ar => ar.AccountId == accountId && ar.RoleId == roleId) .Include(ar => ar.Account) .Include(ar => ar.Role).SingleOrDefaultAsync(); if (accountRole == null) { return(NotFound()); } try { _Db.Remove(accountRole); await _Db.SaveChangesAsync(); _Logger.LogInformation("{0} role revoked from {1}", accountRole.Role.Name, accountRole.Account.Name); return(Ok()); } catch (Exception ex) { _Logger.LogWarning("RemoveRole: Error revoking role from {0}: {1}", accountRole.Account.Name, ex.Message); return(BadRequest(ex.Message)); } }