public async Task <IActionResult> PutMstUserRole([FromRoute] int id, [FromBody] MstUserRole mstUserRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } if (id != mstUserRole.RoleId) { return(BadRequest()); } _context.Entry(mstUserRole).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!MstUserRoleExists(id)) { return(NotFound()); } else { throw; } } return(NoContent()); }
public async Task <IActionResult> PostMstUserRole([FromBody] MstUserRole mstUserRole) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } _context.MstUserRole.Add(mstUserRole); await _context.SaveChangesAsync(); return(CreatedAtAction("GetMstUserRole", new { id = mstUserRole.RoleId }, mstUserRole)); }
public static void GenerateToken(this MstUsers user, IConfiguration configuration) { try { MstUserRole mstUserRole = user.Role; var token = new JwtTokenBuilder() .AddSecurityKey(JwtSecurityKey.Create(configuration.GetValue <string>("JwtSecretKey"))) .AddIssuer(configuration.GetValue <string>("JwtIssuer")) .AddAudience(configuration.GetValue <string>("JwtAudience")) .AddExpiry(90) .AddClaim("Id", user.UserId.ToString()) .AddRole(mstUserRole.RoleName) .Build(); user.Token = token.Value; } catch (Exception) { throw; } }