EzDev.org

aspnetboilerplate

aspnetboilerplate - ASP.NET Boilerplate - Application Framework ASP.NET Boilerplate - Web Application Framework an application framework and starting point for asp.net mvc web applications with best practices and most popular tools!


ASP.NET Boilerplate .NET Core 2

Trying to upgrade ASP.NET Boilerplate project from .NET Core 1.x to .NET Core 2.0

Solution builds successfully, but throws exception in Startup.ConfigureServices method at

 services.AddAbpIdentity<Tenant, User, Role, SecurityStampValidator>(
     options => {})
   .AddUserManager<UserManager>()
   .AddRoleManager<RoleManager>()
   .AddSignInManager<SignInManager>()
   .AddClaimsPrincipalFactory<UserClaimsPrincipalFactory>()
   .AddDefaultTokenProviders();

Exception details

System.TypeLoadException: 'Could not load type 'Microsoft.AspNetCore.Authentication.SharedAuthenticationOptions' from assembly 'Microsoft.AspNetCore.Authentication, Version=2.0.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'.'


Source: (StackOverflow)

Can't call javascript client method in signalr

The following code works fine in IIS Express, but failed in IIS10.

The weird thing is serverside method can successfully be invoked, however clientside method can't.

JavaScript

var hub = $.connection.liveRoomHub;
hub.client.addMessageToPage = function(data){
    debugger;//here, this method never gets invoked
    console.log(JSON.stringify(data));
};
$.connection.hub.start()
    .done(function() {
        hub.server.join('room1')
        .done(function(){
            debugger; //code can run into here
            hub.server.sendMessage('user','test','room1');
        })
    });

C#

public class LiveRoomHub : Microsoft.AspNet.SignalR.Hub
{
    public ILogger Logger { get; set; }

    public async Task SendMessage(string name, string message, string roomName)
    {
        await Clients.Group(roomName)
            .addMessageToPage(new
            {
                Name = name,
                Message = message
            });
        Logger.Info($"{name}send msg:{message}in room:{roomName},");//logged
    }

    public async Task Join(string roomName)
    {
        await Groups.Add(Context.ConnectionId, roomName);
        Logger.Info($"{Context.ConnectionId} enter room: {roomName}");//logged
    }
}

Source: (StackOverflow)

Custom mapping with asp.net boilerplate and Automapper

I am new of ASP.NET BoilerPlate (ABP) and I am trying to understand how to create custom mappings using AutoMapper and, maybe, the ABP automapper attributes: AutoMap, AutoMapFrom, AutoMapTo.

With ABP I can map two classes in this way:

[AutoMapTo(typeof(DestClass)]
public class SourceClass {
    public string A { get; set; }
    public string B { get; set; }
}

public class DestClass {
    public string A { get; set; }
    public string B { get; set; }
}

But if I have two classes like the following where I want the property AB to be automapped as a join of A and B:

[AutoMapTo(typeof(DestClass)]
public class SourceClass {
    public string A { get; set; }
    public string B { get; set; }
}

public class DestClass {
    public string AB { get; set; }
}

Are there some attributes with ABP? Or do I need to use the "classical" AutoMapper code:

Mapper.CreateMap<SourceClass, DestClass>()
    .ForMember(dest => dest.AB,
        opts => opts.MapFrom(src => (src.A + ", " + src.B)));

And where do I have to place such init code?


Source: (StackOverflow)

Add-Migration Created Columns Alphabetically Asp.Net Core 2.0

I have created a model and run command Add-Migration in PMC. it created columns in alphabetically order in migration. After updating database sqlserver table are also in alphabetically order. I want the same order which i used in my original model instead of alphabetical order. I don't want to go with this.

[Key, Column(Order=0)]
public int MyFirstKeyProperty { get; set; }

[Column(Order=1)]
public int MySecondKeyProperty { get; set; }

As i have 70 properties in my table and some time it may exceed. and i am not sure it works or not. I have searched a lot and just know that it is issue with .Net Core2.0. is it ture? Any solution? Thanks.


Source: (StackOverflow)

Store ValueObject in Database using ASP.NET Boilerplate

Trying to implement DDD using ASP.NET Boilerplate and Entity Framework

Employee object

public class Employee : Entity<long>
{
   public virtual string Name { get; protected set; }

   public virtual Nationality Nationality { get; protected set; }
}

defines property Nationality, which is value object

public class Nationality : ValueObject<Nationality>
{      
    public virtual string Name { get; protected set; }
}

Attempt to add database migration produces obvious error

EntityType 'Nationality' has no key defined. Define the key for this EntityType.

Took a look at 3 different approach to persist value object in database

Should i implement one of the above mentioned method manually to persist ValueObject (if so what are some of the best practices) ? or it's already done by ASP.NET Boilerplate Framework ?


Source: (StackOverflow)

Asp.Net Boilerplate,, How to Get current Login User?

I want to get the user data which is currently logged in,, ?? I have to send current user ID to a table in database How to do this??


Source: (StackOverflow)

Get records as host admin for all tenants in AspnetBoilerplate

I want to retrieve records when logged in as the host admin for all tenants.

await auditLogRepository.GetAll().ToListAsync();

This however will not return records for tenants however. AuditLog implements IMayHaveTenant which I think is causing this as anything that implements IMustHaveTenant returns all the records.

How can I select the AuditLogs for all tenants when logged in as the host admin (no tenant)?


Source: (StackOverflow)

ASP.NET Boilerplate Angular Project Error when npm start

I use ASP.NET Boilerplate Framework that is based on .Net Core and Angular. I follow directives in this page step by step but when I run npm start I get the following error message:

ERROR in ./src/polyfills.ts
Module not found: Error: Can't resolve 'web-animations-js' in'D:\Project_Net\MyProjSPA\angular\src'
resolve 'web-animations-js' in 'D:\Project_Net\MyProjSPA\angular\src'
  Parsed request is a module
  using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src)
    Field 'browser' doesn't contain a valid alias configuration
  after using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src)
    resolve as module
      D:\Project_Net\MyProjSPA\angular\src\node_modules doesn't exist or is not a directory
      D:\Project_Net\MyProjSPA\node_modules doesn't exist or is not a directory
      D:\Project_Net\node_modules doesn't exist or is not a directory
      looking for modules in D:\Project_Net\MyProjSPA\angular\node_modules
        using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./node_modules)
          using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./node_modules/web-animations-js)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.js doesn't exist
            as directory
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js doesn't exist
      looking for modules in D:\node_modules
        No description file found
        Field 'browser' doesn't contain a valid alias configuration
        No description file found
        no extension
          Field 'browser' doesn't contain a valid alias configuration
          D:\node_modules\web-animations-js doesn't exist
        .ts
          Field 'browser' doesn't contain a valid alias configuration
          D:\node_modules\web-animations-js.ts doesn't exist
        .js
          Field 'browser' doesn't contain a valid alias configuration
          D:\node_modules\web-animations-js.js doesn't exist
        as directory
          D:\node_modules\web-animations-js doesn't exist
      looking for modules in D:\Project_Net\MyProjSPA\angular\node_modules
        using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./node_modules)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./node_modules)
          using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./node_modules/web-animations-js)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.js doesn't exist
            as directory
              D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js doesn't exist
      looking for modules in D:\Project_Net\MyProjSPA\angular\src
        using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src)
          using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src/web-animations-js)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js.js doesn't exist
            as directory
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js doesn't exist
      looking for modules in D:\Project_Net\MyProjSPA\angular\src
        using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src)
          Field 'browser' doesn't contain a valid alias configuration
        after using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src)
          using description file: D:\Project_Net\MyProjSPA\angular\package.json (relative path: ./src/web-animations-js)
            no extension
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js doesn't exist
            .ts
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js.ts doesn't exist
            .js
              Field 'browser' doesn't contain a valid alias configuration
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js.js doesn't exist
            as directory
              D:\Project_Net\MyProjSPA\angular\src\web-animations-js doesn't exist
[D:\Project_Net\MyProjSPA\angular\src\node_modules]
[D:\Project_Net\MyProjSPA\node_modules]
[D:\Project_Net\node_modules]
[D:\node_modules\package.json]
[D:\node_modules\web-animations-js\package.json]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js]
[D:\node_modules\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.ts]
[D:\node_modules\web-animations-js.ts]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.js]
[D:\node_modules\web-animations-js.js]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js]
[D:\node_modules\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.ts]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js.js]
[D:\Project_Net\MyProjSPA\angular\node_modules\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js.ts]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js.js]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js.ts]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js.js]
[D:\Project_Net\MyProjSPA\angular\src\web-animations-js]
 @ ./src/polyfills.ts 36:0-27
 @ multi ./src/polyfills.ts

Here are my framework versions:

npm -v // 3.10.10
node -v // 6.11.3
tsc -v //2.5.3
ng -v // @angular/core 4.4.4
angular-cli version in `package.json` : //@angular/cli": "^1.3.2"

I think it's related to angular version or typescript version.Am I right? What should I do to resolve this problem?


Source: (StackOverflow)

Net standard Library missing reference in ASP.NET Boilerplate

every time i clone Abp.ModuleZero to my machine when i run nuget command update-database the error show me and when i build the solution in viusal studio the project doesn't build and show many errors in error list console window most of them is like :

The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'

i try to install Netstandard.library package from package manager console window but doesn't any sense.

my visual studio IDE version is 2015 Update 3.


Source: (StackOverflow)

Registering new dependency

I am using asp.net boilerplate to create new project.

I have defined new service as follows:

public class Employee : Entity<int>
{
    public string FName { get; set; }
    public string LName { get; set; }
}

public interface IEmployeeAppService : IApplicationService
{
    Employee AddEmployee(Employee emp);
    List<Employee> GetAll();
}

public class EmployeeAppService : MyTestProjectAppServiceBase, IEmployeeAppService
{
    private IRepository<Employee, int> _employeeRepository;

    public EmployeeAppService(IRepository<Employee, int> repo)
    {
        _employeeRepository = repo;
    }

    public Employee AddEmployee(Employee emp)
    {
        return _employeeRepository.Insert(emp);
    }

    public List<Employee> GetAll()
    {
        return _employeeRepository.GetAllList();
    } 
}

I want to use the service in HomeController:

public class HomeController : MyTestProjectControllerBase
{
    IEmployeeAppService service;

    public HomeController(IEmployeeAppService svc)
    {
        service = svc;
    }
}

When I run the application I get following error:

Can't create component 'MyTestProject.Services.EmployeeAppService' as it has dependencies to be satisfied.

'MyTestProject.Services.EmployeeAppService' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`2[[MyTestProject.Domain.Employee, MyTestProject.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null],[System.Int32, mscorlib, Version=4.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089]]' which was not registered.

How do I register the EmployeeAppService dependency with HomeController?

UPDATE

I tried the following code

IocManager.Register(typeof(IRepository<Employee, int>),
                    typeof(EmployeeAppService),
                    Abp.Dependency.DependencyLifeStyle.Transient);

but then it displays this error

There is already a component with that name. Did you want to modify the existing component instead? If not, make sure you specify a unique name.


Source: (StackOverflow)

ASPNETBOILERPLATE - App service method not returning related entities in .NET Core

I am in the process of converting my .NET MVC5 template into .NET Core MVC template of ASPNETZERO. So all the code I am converting is working just as I need in my MVC5 template solution. My method code is shown below.

  public async Task<EditCompanyDto> GetCompanyForEdit(NullableIdDto input)
    {
        var companyEditDto = (await _companyRepository.GetAsync((int)input.Id));
        var cmp = companyEditDto.MapTo<EditCompanyDto>();
        return cmp;
    }

This code works perfectly in the MVC5 template and returns the related entities of Address, Contact and Note. In the .NET Core solution this exact same code returns only the Address and Contact collections in the above method. It keeps returning the Note collection as NULL.

Shown below is my company entity. I have removed some fields for this post, but have left all the navigational properties.

public class Company : FullAuditedEntity, IMustHaveTenant
{

    public string CompanyTaxId { get; set; }

    public bool ActiveYesNo { get; set; }

    public virtual NoteHeader Note { get; set; }

    public virtual List<CompanyAddress> Addresses { get; set; }

    public virtual List<CompanyContact> Contacts { get; set; }

    public virtual int TenantId { get; set; }

    public Company()
    {
        Addresses = new List<CompanyAddress>();
        Contacts = new List<CompanyContact>();
    }

}

Source: (StackOverflow)

How to stop or pause Quartz job

I have executed 2 jobs (MyJob1 and MyJob2) as below:

public async Task<ActionResult> ScheduleJob()
    {
        await _jobManager.ScheduleAsync<MyJob1>(
            job =>
            {
                job.WithIdentity("Job1Identity", "MyGroup")
                    .WithDescription("This is job 1");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInSeconds(5)
                            .Build();
                    });
            });

        await _jobManager.ScheduleAsync<MyJob2>(
            job =>
            {
                job.WithIdentity("Job2Identity", "MyGroup")
                    .WithDescription("This is job 2");
            },
            trigger =>
            {
                trigger.StartNow()
                    .WithSimpleSchedule(schedule =>
                    {
                        schedule.RepeatForever()
                            .WithIntervalInSeconds(5)
                            .Build();
                    });
            });

        return Content("OK, scheduled!");
    }

--> I have tried to use _jobManager.Stop() but it stops all my job, so how to stop or pause only MyJob2?


Source: (StackOverflow)

Foreign Key Reference Object Returning Null [closed]

I am referencing the AbpUser table in an entity with the following entity definition:

[ForeignKey("LocationManagerId")]
public virtual User LocationManager { get; set; }
public virtual long LocationManagerId { get; protected set; }

My DTO is as follows:

[AutoMapFrom(typeof(Location))]
public class LocationDto : FullAuditedEntityDto<Guid>
{
    <snip>
    public virtual User LocationManager { get; set; }
}

Using the AsyncCrudAppService and calling the following from an MVC controller:

var locations = (await _locationAppService.GetAll(new PagedAndSortedResultRequestDto())).Items;

locations.LocationManager is returning null. I've confirmed everything in both the entity and the dto is set to virtual. I'm at a loss. Anyone have any insight?


Source: (StackOverflow)

Should I be calling an AppService from another AppService?

Context

Currently I'm working in a Documents and Records Management System (DRMS?). Because of some technical limitations I need to store a "view" file and a "source" file (DOCX or XLSX). A view file is a PDF file for users to print, download and view for every day usage while a source file is the editable file. When users require to update a file, they will download the source, update it, and upload a new view file and the corresponding source file.

I'm not able, at this time, to implement XLSX viewers/editors and, due to the quantity of files, I cannot migrate to ODFs in order to use open source viewers available.

Right now I have two models like this:

public class Document {
    //Other fields
    public virtual List<DigitalFile> Files { get; set; }
}

public class DigitalFile {
    //Other fields
    public virtual Document FileOf { get; set; }
}

The Document model has all the "business" data while the DigitalFile model has data about the files themselves (path, url, type, etc.)

Each time a document is created it will have 1 view file (required) and it may have 1 source file (some documents may not be editable). From this you can know that when a document is created/updated at least 1 digital file will be created/updated as well.

Problem/Question

I will have a DocumentAppService to handle all the CRUD operations but here's where my doubt comes, should I be calling an AppService from another AppService? I mean, when a Document is created, should the Create method call another Create method in DigitalFileAppService? Or should it be better if DocumentAppService handled everything on its own?

Right now all the CRUD operation on DigitalFile are tied to the operations on Document, which is why I'm in doubt of implementing an AppService for the files.


Source: (StackOverflow)

ASP.NET Boilerplate: What is the best solution for Four eyes principle

I want to add 4 eyes principle to ASP.NET Boilerplate framework. That means every change on Role, User,.. need to be approved (by another admin) before applied to the system. I have searched for some time but no answer. So what is the best solution for this flow?

Can I create the same tables with Abp tables (dbo.AbpUser_Temp, etc) and the all the changes will be stored in these tables? Is there any better solution?

Example: In the application, Admin1 has created a user named User1. But this user cannot login to the application until he was approved by Admin2.


Source: (StackOverflow)