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));
        }
Esempio n. 2
0
        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 <IActionResult> PutLawyer(Lawyer lawyer)
        {
            await _myLawyerService.UpdateLawyer(lawyer);

            return(NoContent());
        }
Esempio n. 5
0
        public async Task <IActionResult> GetLawyerDetails()
        {
            var vm = new UserProfileViewModel {
            };

            try
            {
                var userId = User.FindFirst(ClaimTypes.NameIdentifier)?.Value;
                var user   = await UserManager.FindByIdAsync(userId);

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


                vm = new UserProfileViewModel
                {
                    Id          = userId,
                    Age         = user.DateOfBirth.HasValue ? user.DateOfBirth.Value.CalculateAge() : 0,
                    Email       = user.Email,
                    Name        = user.Name,
                    NameEn      = user.NameEn,
                    UserName    = user.UserName,
                    LawyerId    = user.LawyerId,
                    DateOfBirth = user.DateOfBirth.HasValue ? user.DateOfBirth.Value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture) : "",
                    Gender      = user.Gender,
                    PhoneNumber = user.PhoneNumber,
                    ProvinceId  = user.ProvinceId,
                    ProfileImg  = string.IsNullOrEmpty(user.ProfileImg) ? "/images/personal-img.jpg" : user.ProfileImg,
                };
                vm.Provinces = CountryService.GetProvinces();
                if (user.LawyerId.HasValue)
                {
                    var lawyer = lawyerService.GetLawyer(user.LawyerId.Value);
                    vm.Spetializations  = lawyerService.GetSpetializations();
                    vm.SpetializationId = lawyer.SpecializationId;
                    vm.Sessions         = SesstionService.GetLawyerSesstions(user.LawyerId.Value);
                    vm.Description      = lawyer.Description;
                    vm.DescriptionEn    = lawyer.DescriptionEn;
                    vm.Certificates     = lawyer.Certificates;
                    vm.CertificatesEn   = lawyer.CertificatesEn;
                    vm.Price            = lawyer.Fees;
                    vm.Rating           = lawyerService.GetRating(user.LawyerId.Value);
                    vm.ExperienceId     = lawyer.ExperienceId;

                    vm.Experiences       = lawyerService.GetLawyerExperiences();
                    vm.Services          = ServiceService.Get(user.LawyerId.Value);
                    vm.ServiceCategories = ServiceService.GetCategories(user.LawyerId.Value);
                    vm.VideoURL          = lawyer.VideoURL;


                    lawyer.ModifiedDate = DateTime.Now;
                    lawyerService.UpdateLawyer(lawyer);
                }
            }
            catch (Exception ex)
            {
                throw;
            }

            return(Ok(vm));
        }