Пример #1
0
 public UserController(IService <User> service, IService <Company> companyService, IMapper mapper, IHttpContextAccessor contextAccessor, UserModelService modelService)
 {
     _service             = service;
     _mapper              = mapper;
     _userCompanyId       = Convert.ToInt32(contextAccessor.HttpContext.User.Claims.FirstOrDefault(c => c.Type == Core.Enums.ClaimTypes.CompanyId.ToString()).Value);
     _userId              = Convert.ToInt32(contextAccessor.HttpContext.User.Claims.FirstOrDefault(c => c.Type == Core.Enums.ClaimTypes.UserId.ToString()).Value);
     _modelService        = modelService;
     _companyModelService = companyService;
 }
Пример #2
0
 public AuthMiddleware(RequestDelegate next, JWTHandler _jWTHandler, UserModelService _userModelService)
 {
     jWTHandler       = _jWTHandler;
     userModelService = _userModelService;
     _next            = next;
 }
Пример #3
0
 public MeController(ModelStateSerializer _modelStateSerializer, UserModelService _userModelService)
 {
     modelStateSerializer = _modelStateSerializer;
     userModelService     = _userModelService;
 }
Пример #4
0
 public AuthController(UserModelService _userModelService, JWTHandler _JWTCreator, ModelStateSerializer _modelStateSerializer)
 {
     JWTHandler           = _JWTCreator;
     modelStateSerializer = _modelStateSerializer;
     userModelService     = _userModelService;
 }
Пример #5
0
        PostProfileAsync(IUserViewModel uploadModel, RequestContext requestContext)
        {
            var profileResult        = new IdentityManagerResult <PostProfileResultState, (IUserViewModel, string)>();
            var userTitle            = Dependencies.LocalizationService.Localize("General.User");
            var userDoesntExistTitle = Dependencies.LocalizationService.Localize("Adm.User.NotExist");

            profileResult.Data = (uploadModel, userTitle);
            MedioClinicUser user = null;

            try
            {
                user = await UserManager.FindByIdAsync(uploadModel.CommonUserViewModel.Id);
            }
            catch (Exception ex)
            {
                HandlePostProfileException(ref profileResult, ex, PostProfileResultState.UserNotFound);
                profileResult.Data = (uploadModel, userDoesntExistTitle);

                return(profileResult);
            }

            var commonUserModelCustomMappings = new Dictionary <(string propertyName, Type propertyType), object>
            {
                { (nameof(MedioClinicUser.Email), typeof(string)), uploadModel.CommonUserViewModel.EmailViewModel.Email },
            };

            try
            {
                // Map the common user properties.
                user = UserModelService.MapToMedioClinicUser(uploadModel.CommonUserViewModel, user, commonUserModelCustomMappings);

                // Map all other potential properties of specific models (patient, doctor, etc.)
                user = UserModelService.MapToMedioClinicUser(uploadModel, user);
            }
            catch (Exception ex)
            {
                HandlePostProfileException(ref profileResult, ex, PostProfileResultState.UserNotMapped);

                return(profileResult);
            }

            try
            {
                // We need to use the user store directly due to the design of Microsoft.AspNet.Identity.Core.UserManager.UpdateAsync().
                await UserStore.UpdateAsync(user);

                var avatarFile = uploadModel.CommonUserViewModel.AvatarFile;

                if (avatarFile != null)
                {
                    var avatarBinary = FileManager.GetPostedFileBinary(avatarFile);
                    AvatarRepository.UploadUserAvatar(user, avatarBinary);
                }
            }
            catch (Exception ex)
            {
                HandlePostProfileException(ref profileResult, ex, PostProfileResultState.UserNotUpdated);

                return(profileResult);
            }

            (var model, var title) = GetViewModelByUserRoles(user, requestContext, true);

            if (model != null)
            {
                profileResult.Success     = true;
                profileResult.ResultState = PostProfileResultState.UserUpdated;
                profileResult.Data        = (model, title);
            }

            return(profileResult);
        }