Esempio n. 1
0
        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());
        }
Esempio n. 2
0
        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));
        }
Esempio n. 3
0
        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;
            }
        }