コード例 #1
0
        public async Task <UserGetOneResponse> GetOne(ApplicationUser currentUser, UserTypeVM userType, long id)
        {
            var response            = new UserGetOneResponse();
            var applicationUserType = GetApplicationUserType(currentUser);

            ApplicationUser item = null;

            switch (userType)
            {
            case UserTypeVM.Admin when applicationUserType == UserType.Admin:
                item = await _fuelContext.AdminUsers.FirstOrDefaultAsync(x => x.Id == id);

                break;

            case UserTypeVM.Admin when applicationUserType != UserType.Admin:
                response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_RECEIVE_USER]);
                break;

            case UserTypeVM.Client when applicationUserType == UserType.Admin || applicationUserType == UserType.Manager:
                item = await _fuelContext.ClientUsers.FirstOrDefaultAsync(x => x.Id == id);

                break;

            case UserTypeVM.Client when applicationUserType != UserType.Admin && applicationUserType != UserType.Manager:
                response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_RECEIVE_USER]);
                break;

            case UserTypeVM.Driver when applicationUserType == UserType.Admin || applicationUserType == UserType.Manager:
                item = await _fuelContext.DriverUsers.FirstOrDefaultAsync(x => x.Id == id);

                break;

            case UserTypeVM.Driver when applicationUserType != UserType.Admin && applicationUserType != UserType.Manager:
                response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_RECEIVE_USER]);
                break;

            case UserTypeVM.Manager when applicationUserType == UserType.Admin:
                item = await _fuelContext.ManagerUsers.FirstOrDefaultAsync(x => x.Id == id);

                break;

            case UserTypeVM.Manager when applicationUserType != UserType.Admin:
                response.AddError(_stringLocalizer[CustomStringLocalizer.NO_RIGHTS_TO_RECEIVE_USER]);
                break;

            default:
                throw new NotImplementedException("Not implemented user type");
            }

            if (item != null)
            {
                response.Item = await Convert(item);
            }
            else if (!response.HasError())
            {
                response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]);
            }

            return(response);
        }
コード例 #2
0
        public async Task <UserGetOneResponse> GetOne(ApplicationUser currentUser)
        {
            var response = new UserGetOneResponse();

            if (currentUser != null)
            {
                response.Item = await Convert(currentUser);
            }
            else
            {
                response.AddError(_stringLocalizer[CustomStringLocalizer.USER_NOT_FOUND]);
            }

            return(response);
        }