//Post api/user/Login
        public async Task <IActionResult> PostLogin([FromForm] UserLoginModel model)
        {
            var IsInfoValid = ModelState.IsValid;

            if (IsInfoValid == false)
            {
                return(BadRequest(new { message = "Login Info not valid" }));
            }
            var key  = Encoding.UTF8.GetBytes(_AppSetting.JWT_Secret);
            var User = await _userManager.FindByNameAsync(model.UserName);

            if (User == null)
            {
                return(NotFound());
            }
            if (User.IsActive == false)
            {
                return(NotFound());
            }
            var role = await _userManager.GetRolesAsync(User);

            if (User != null && await _userManager.CheckPasswordAsync(User, model.Password))
            {
                var Token    = TokenHelpers.CreateToken(User, key);
                var userrole = role;
                return(Ok(new { Token, userrole }));
            }
            else
            {
                return(BadRequest(new { message = "Login Info not valid" }));
            }
        }
        // Post api/user/register
        public async Task <object> PostRegister([FromForm] UserRegisterModel NewUser)
        {
            //to create role
            // MyRoleModel iden = new MyRoleModel
            //{
            //  Name = "Student"
            //};


            //            IdentityResult res = await _roleManager.CreateAsync(iden);
            ////////////////////
            //to get the intake for the user
            //var intake = NewUser.IntakeId;


            ///////////////////////////
            //to get the intakeid
            int intakename = NewUser.IntakeId.GetValueOrDefault();
            var intake     = db.GetIntakeByName(intakename);

            if (intake == null)
            {
                return(NotFound());
            }
            NewUser.IntakeId = intake.IntakeId;

            /////////////////
            var  file            = Request?.Form?.Files?.FirstOrDefault();
            bool IsInfoValid     = ModelState.IsValid;
            bool IsImageUploaded = file?.Length > 0;

            if (IsInfoValid == false)
            {
                return(BadRequest(new { message = "invalid registration info" }));
            }
            if (IsImageUploaded == false)
            {
                //if user exists
                var checkuser = await _userManager.FindByNameAsync(NewUser.UserName);

                if (checkuser != null)
                {
                    return(StatusCode(409, $"User '{NewUser.UserName}' already exists."));
                }
                ///////////
                var user = await _userManager.CreateAsync(NewUser, NewUser.Password);

                // to assign role to user
                var userdata = await _userManager.FindByNameAsync(NewUser.UserName);

                await _userManager.AddToRoleAsync(userdata, "Student");

                //token part
                var keytoken  = Encoding.UTF8.GetBytes(_AppSetting.JWT_Secret);
                var Usertoken = await _userManager.FindByNameAsync(NewUser.UserName);

                await _userManager.AddToRoleAsync(Usertoken, "Student");

                var roletoken = await _userManager.GetRolesAsync(Usertoken);

                if (Usertoken != null && await _userManager.CheckPasswordAsync(Usertoken, NewUser.Password))
                {
                    var Token    = TokenHelpers.CreateToken(Usertoken, keytoken);
                    var userrole = roletoken;
                    return(Ok(new { Token, userrole }));
                }


                return(Ok(user));
            }

            var uploadedfilename = ContentDispositionHeaderValue.Parse(file.ContentDisposition).FileName.Trim('"');
            var IsImgExtAllowed  = FSHelpers.IsImageExtensionAllowed(uploadedfilename);

            if (IsImgExtAllowed == false)
            {
                return(BadRequest(new { message = "Image extensions allowed are jPG and PNG only " }));
            }
            var dbImagePath = FSHelpers.SaveProfileImage(NewUser, uploadedfilename, file);

            NewUser.PrifleImageUrl = dbImagePath;
            //if user exists
            var checkuser2 = await _userManager.FindByNameAsync(NewUser.UserName);

            if (checkuser2 != null)
            {
                return(StatusCode(409, $"User '{NewUser.UserName}' already exists."));
            }
            ///////////
            var result = await _userManager.CreateAsync(NewUser, NewUser.Password);

            // to assign role to user
            var u = await _userManager.FindByNameAsync(NewUser.UserName);

            var r = await _userManager.AddToRoleAsync(u, "Student");

            //token part
            var key  = Encoding.UTF8.GetBytes(_AppSetting.JWT_Secret);
            var User = await _userManager.FindByNameAsync(NewUser.UserName);

            await _userManager.AddToRoleAsync(User, "Student");

            var role = await _userManager.GetRolesAsync(User);

            if (User != null && await _userManager.CheckPasswordAsync(User, NewUser.Password))
            {
                var Token    = TokenHelpers.CreateToken(User, key);
                var userrole = role;
                return(Ok(new { Token, userrole }));
            }
            else
            {
                return(BadRequest(new { message = "Login Info not valid" }));
            }
        }