public async Task <IActionResult> PutxCourseDesc([FromRoute] Guid id, [FromBody] XCourseDesc varxCourseDesc)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != varxCourseDesc.XCourseDescId)
            {
                return(BadRequest());
            }

            _context.Entry(varxCourseDesc).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!xCourseDescExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <IActionResult> PutXInstructorInfo([FromRoute] Guid id, [FromBody] XInstructorInfo varXInstructorInfo)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != varXInstructorInfo.XInstructorInfoId)
            {
                return(BadRequest());
            }

            _context.Entry(varXInstructorInfo).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!XInstructorInfoExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ResponseData <TokenInfo> > RegisterDevice([FromBody] RegisterDeviceRequest request)
        {
            var response = new ResponseData <TokenInfo>();

            try
            {
                var email = $"{request.DeviceId}@mobile.device";
                var user  = await _userManager.FindByEmailAsync(email);

                if (user == null)
                {
                    var password = Guid.NewGuid().ToString().Replace("-", "");
                    user = new ApplicationUser
                    {
                        Id             = Guid.NewGuid(),
                        OS             = request.OS,
                        DeviceId       = request.DeviceId,
                        Email          = email,
                        EmailConfirmed = true,
                        UserName       = email
                    };

                    await _userManager.CreateAsync(user, password);

                    _context.Add(new XUserInfo
                    {
                        name        = "App",
                        family      = "Mobile",
                        login       = user.Id.ToString(),
                        XUserInfoId = user.Id
                    });
                    await _context.SaveChangesAsync();
                }
                await _userManager.AddToRoleAsync(user, MyIdentityRole.ROLE_MOBILEAPP);

                await _signInManager.SignInAsync(user, false);


                var    currentUser = user;
                string encodedJwt  = await CreateToken(currentUser);

                // Serialize and return the response
                var oldTokens = await _identityContext.RefreshTokens.
                                Where(p => p.UserId == currentUser.Id && p.IsExpired).
                                ToListAsync();

                oldTokens.ForEach(p => { p.IsExpired = true; });

                var refresh_token = Guid.NewGuid().ToString().Replace("-", "");
                var refreshToken  = new RefreshToken
                {
                    Id         = Guid.NewGuid(),
                    UserId     = currentUser.Id,
                    Token      = refresh_token,
                    DateIssued = DateTime.Now,
                    IsExpired  = false,
                };

                response.code = BaseStatus.Success;
                response.data = new TokenInfo
                {
                    access_token  = encodedJwt,
                    expires_in    = (int)_jwtOptions.ValidFor.TotalSeconds,
                    token_type    = "jwt",
                    refresh_token = refresh_token
                };

                _identityContext.Add(refreshToken);
                await _identityContext.SaveChangesAsync();
            }
            catch (Exception ex)
            {
                response.code        = BaseStatus.Exception;
                response.data        = null;
                response.message     = ex.Message;
                response.description = "Не удалось зарегистрироваться ";
            }

            return(response);
        }