Base solution for your next web application

Activities of "sayas"

Hi,

I've created multi-tenant application to manage some institutions. My requirement is - whenever I create a new tenant, an institution should be created automatically. I've created a master for adding the institutions too. And that's working fine.

But when adding a new tenant, an error is occurred at the point of creating a new tenant. The error message shown in the browser was only 'An Internal Error Occurred'. But I got the 'UserId not found' error from the log.

I've given the permissions as well. Following is my code:

Institute Entity

[Table("AbpInstitutions")]
    public class Institution : FullAuditedEntity,IMustHaveTenant
    {
        public int TenantId { get; set; }
        
        [Required]
        [StringLength(50)]
        public string Name { get; set; }

        [StringLength(250)]
        public string Details { get; set; }

        [StringLength(50)]
        public string Caption { get; set; }

        [StringLength(250)]
        public string Logo { get; set; }

        //public ICollection<InstitutionCourseMapping> InstitutionCourseMappings { get; set; }

        public static Institution CreateInstitutionForNewTenant(string tenantName)
        {
            return new Institution
            {    
                Name = tenantName,
                Caption=tenantName,
                Details= "Institution Created by default for Tenant - " + tenantName,
                Logo=""
            };
        }
    }

InstitutionAppService

[AbpAuthorize(PermissionNames.Pages_Institution)]

 public async Task CreateInstitution(Institution input)
        {
            //var institution = input;
            try
            {
                await _institutionRepository.InsertAsync(input);
            }
            catch (Exception ex)
            {
                Trace.Write(ex.Message);
                throw;
            }
        }

TenantAppService

//Create a Default Institute for the new Tenant
                var defaultInstitution = Institution.CreateInstitutionForNewTenant(tenant.Name);
                await _institutionAppService.CreateInstitution(defaultInstitution);

SmartCampusAuthorizationProvider

var instiuionMaster = pages.CreateChildPermission(PermissionNames.Pages_Institution, L("Manage Institutions"), multiTenancySides: MultiTenancySides.Host);

Stack Trace (Got it from [AbpAuditLogs] )

System.InvalidOperationException: UserId not found.     at Microsoft.AspNet.Identity.UserManager`2.&lt;GetRolesAsync&gt;d__ac.MoveNext()  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     at Abp.Authorization.Users.AbpUserManager`2.<>c__DisplayClass63_0.<<GetUserPermissionCacheItemAsync>b__0>d.MoveNext() in D:\Halil\GitHub\module-zero\src\Abp.Zero\Authorization\Users\AbpUserManager.cs:line 641  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     at Abp.Runtime.Caching.CacheExtensions.<>c__DisplayClass5_0`2.&lt;&lt;GetAsync&gt;b__0>d.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:line 0  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     at Abp.Runtime.Caching.CacheBase.&lt;GetAsync&gt;d__15.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheBase.cs:line 69  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.CompilerServices.TaskAwaiter.ThrowForNonSuccess(Task task)     at System.Runtime.CompilerServices.TaskAwaiter.HandleNonSuccessAndDebuggerNotification(Task task)     at Abp.Runtime.Caching.CacheExtensions.&lt;GetAsync&gt;d__5`2.MoveNext() in D:\Halil\GitHub\aspnetboilerplate\src\Abp\Runtime\Caching\CacheExtensions.cs:line 38  --- End of stack trace from previous location where exception was thrown ---     at System.Runtime.CompilerServices.TaskA...

Somebody please help me out.. I'm Stuck here....

Oh.. I'm really Sorry.. I've typed it mistakenly. The error is not at the point of creating the new tenant, its happening at the point of Creating a Default Institute for the new Tenant (in TenantAppService).

Another interesting fact is, everything is working perfectly when i remove the [AbpAuthorize(PermissionNames.Pages_Institution)] from InstitutionAppService

But, I've given permission for the same to the admin user role in the table 'AbpPermissions' A screenshot of the same is attached.

PermissionNames

Public const string Pages_Institution = "Pages.Institution";

Hi Halil,

I've done as you said. The UserId shown from AbpSession is '1' and TenantId is null. As you know, '1' is the admin UserId.

Repeated the same after including the AbpAuthorize attribute and after giving a user-wise permission in AbpPermissions table. Now also getting the same result.

What to do now??

Hi dears,

I want to implement a multi-select list to save an Institution-Course Mapping.

I've produced a ComboBox to select an institution and a Multi-Select List for selecting some courses for the selected institution.

I've made it by creating a ViewModel of both the Institution & Course entities. The ViewModel contains of the ListResultDto's of each entities.

My question is, how can i get the selected values of the multiselect list and save it to the database? Should I use a controller actionmethode or the JavaScript API Itself?? Will be appreciable if you share some sample codes please.. thanks!!

Now I'm using ABP. But, after making a simple application successfully in Abp, I'll move on to AbpZero. Can you please help me on this?

Hi Halil,

Thank you for your reply. Can you please share me a sample code for doing the same? Any help will be highly appreciated! Thanks!!

Hai..

Thanks for your kind help. I got the values of select list & multiselect list using the $('#multipleSelect').val()

And sent the collected data using abp.services. Because i've written the code for inserting the data in AppServices.

But now i'm in trouble with another issue. That is , I'm using the 'InserAsync' function of 'IRepository' interface in the AppService. I've coded to set an instance of the repository in the AppService Constructor. But that constructor is not getting initiated. So that, an error is occurred at the point of inserting the data. If the IRepository instance is initiated, then I'm done.

I'll show you my code.

AppService

public class InstitutionCourseMappingAppService : SmartCampusAppServiceBase, IInstitutionCourseMappingAppService
    {
        public readonly IRepository<InstitutionCourseMapping,int> _institutionCourseMappingRepository;

        public InstitutionCourseMappingAppService()
        {

        }

        public InstitutionCourseMappingAppService(IRepository<InstitutionCourseMapping,int> institutionCourseMappingRepository)
        {
            _institutionCourseMappingRepository = institutionCourseMappingRepository;
        }

        public async Task MapCourses(string institutionId, string[] courses)
        {

            try
            {                
                foreach (string courseId in courses)
                {
                    InstitutionCourseMapping mapp = new InstitutionCourseMapping();
                    mapp.InstitutionId = Convert.ToInt32(institutionId);
                    mapp.CourseId = Convert.ToInt32(courseId);
                    await _institutionCourseMappingRepository.InsertAsync(mapp);   // Issue is happening here(Error: _institutionCourseMappingRepository is null)
                }                
            }
            catch (Exception ex)
            {
                Trace.Write(ex.Message);
                throw;
            }
        }

    }

JS

(function() {
    $(function () {

		var _$form = $('#mapcoursesForm');
        	_$form.validate();
        	_$form.find('button[type="submit"]').click(function(e) {
        	    e.preventDefault();

        	    if (!_$form.valid()) {
        	        return;
        	    }

        	    var institution= $('#institution').val();
        	    var selectedCourses = $('#courses').val();

        	    if (selectedCourses == null || selectedCourses == '') {
        	        swal("No Courses were Selected", "Please select any of the courses!", "warning");
        	        return false;
        	    }
        	    else
        	    {
        	        abp.ui.setBusy(_$form);
        	        var _institutionService = abp.services.app.institutionCourseMapping;    
   	            	// after this next line, it's directly going to the mapCourses methode. Not to the constructor  :(
        	        _institutionService.mapCourses(institution,selectedCourses).done(function (e) {
        	            swal("Success", "Courses and institutions were mapped successfully!", "Success");
        	            location.reload(true);  //reload page 
        	        }).always(function () {
        	            abp.ui.clearBusy(_$form);
        	        });
        	    }
		});
    });    
})();

How can we make it possible?

Hi Halil,

Have you added any of the above mentioned reporting tools to the ABP? Which is better in your opinion??

Yeah.. I've tried that too.. When deleting the parameterless constructor, even the code doesn't coming to the method 'MapCourses'. And it says 'An internal Server error occurred!', but no exceptions were found in the AbpAuditLogs table.

But when using the 2 constructors together, the same problem exists - it directly comes to the method. Now I'm Stuck!!

Hi Halil,

I've checked it with sql profiler. The funny thing is, i can see all the queries for inserting the data to AbpTenants, AbpUsers ect..... upto AbpAudits tables. But I could not find out the query for inserting the data to AbpInstitutions table!!! I had tried to attach the trace file for your reference. But your forum doesn't allow me to do so.. :roll:

Showing 1 to 10 of 16 entries