public async Task <IActionResult> GetSession(string Id)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var user   = await UserManager.FindByIdAsync(userId);

            var session = SesstionService.GetSesstionById(Id);

            if (session.Id > 0)
            {
                if (session.UserId != userId && session.Appointment.LawyerId != user.LawyerId)
                {
                    return(BadRequest(new List <string> {
                        "Invalid User"
                    }));
                }
            }
            session.IsGeust  = session.UserId == userId;
            session.UserName = user.UserName;

            if (user.LawyerId.HasValue)
            {
                var lawyer = LawyerService.GetLawyer(user.LawyerId.Value);
                lawyer.ModifiedDate = DateTime.Now;
                LawyerService.UpdateLawyer(lawyer);
            }


            return(Ok(session));
        }
Exemple #2
0
        public IActionResult GetDetails(int Id)
        {
            var model = lawyerService.GetLawyer(Id);

            model.Services = ServiceService.Get(Id);
            return(Ok(model));
        }
        public async Task <IActionResult> Token([FromBody] LoginModel model)
        {
            var user = await UserManager.FindByEmailAsync(model.UserName);

            if (user != null && user.EmailConfirmed && await UserManager.CheckPasswordAsync(user, model.Password))
            {
                var roles = await UserManager.GetRolesAsync(user);

                var claims = new[]
                {
                    new Claim(ClaimTypes.NameIdentifier, user.Id),
                    new Claim(JwtRegisteredClaimNames.Sub, user.UserName),
                    new Claim(JwtRegisteredClaimNames.Jti, Guid.NewGuid().ToString()),
                    new Claim(ClaimTypes.Role, roles.Count > 0?roles[0]:"")
                };

                var signingKey = new SymmetricSecurityKey(Encoding.UTF8.GetBytes(AppConfiguration.SecurityKey));

                var token = new JwtSecurityToken(
                    issuer: "http://elmaitre.com",
                    audience: "http://elmaitre.com",
                    expires: DateTime.Now.AddDays(1),
                    claims: claims,
                    signingCredentials: new Microsoft.IdentityModel.Tokens.SigningCredentials(signingKey, SecurityAlgorithms.HmacSha256)

                    );

                if (user.LawyerId.HasValue)
                {
                    var lawyer = lawyerService.GetLawyer(user.LawyerId.Value);
                    lawyer.ModifiedDate = DateTime.Now;
                    lawyerService.UpdateLawyer(lawyer);
                }
                var result = new TokenViewModel
                {
                    token      = new JwtSecurityTokenHandler().WriteToken(token),
                    expiration = token.ValidTo,
                    IsLawyer   = user.LawyerId.HasValue,
                    UserName   = !string.IsNullOrEmpty(user.Name) ? user.Name : user.UserName,
                    UserNameEn = !string.IsNullOrEmpty(user.NameEn) ? user.NameEn : user.UserName
                };

                WriteCookies("token", result.token, result.expiration);
                WriteCookies("IsLawyer", result.IsLawyer.ToString(), result.expiration);
                WriteCookies("UserName", result.UserName, result.expiration);
                WriteCookies("UserNameEn", result.UserNameEn, result.expiration);

                return(Ok(result));
            }
            return(Unauthorized());
        }
        public async Task <IActionResult> SaveInfo([FromBody] UserProfileViewModel model)
        {
            var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
            var user   = await UserManager.FindByIdAsync(userId);

            if (user == null)
            {
                return(Unauthorized());
            }

            user.Name        = model.Name;
            user.NameEn      = model.NameEn;
            user.DateOfBirth = DateTime.ParseExact(model.DateOfBirth, "yyyy-MM-dd", CultureInfo.InvariantCulture);
            user.Gender      = model.Gender;
            user.PhoneNumber = model.PhoneNumber;
            user.ProvinceId  = model.ProvinceId;
            await UserManager.UpdateAsync(user);

            if (user.LawyerId.HasValue)
            {
                var lawyer = LawyerService.GetLawyer(user.LawyerId.Value);
                lawyer.Description      = model.Description;
                lawyer.Certificates     = model.Certificates;
                lawyer.DescriptionEn    = model.DescriptionEn;
                lawyer.CertificatesEn   = model.CertificatesEn;
                lawyer.SpecializationId = model.SpetializationId;
                lawyer.UserId           = userId;
                lawyer.Fees             = model.Price;
                lawyer.ExperienceId     = model.ExperienceId;
                lawyer.VideoURL         = model.VideoURL;

                LawyerService.UpdateLawyer(lawyer);
            }

            WriteCookies("UserName", user.Name, DateTime.Now.AddHours(2));
            WriteCookies("UserNameEn", user.NameEn, DateTime.Now.AddHours(2));


            return(Ok(new { isSuccess = true }));
        }
        public async Task <ActionResult <Lawyer> > SearchLawyer(int id)
        {
            var response = await _myLawyerService.GetLawyer(id);

            return(response);
        }