ok, I have resolved my problem, it's spend me a whole day, it maybe because my entity model name is not same with the database table name, when I drop the table and run update-database again, the problem is solved :(
yes, actually I tried everything before, but still not working, but when I reset the DB and run update-database again, that's working, maybe I use the difference table name between entity and database, but suppose that's not be an issue, I have set the table attribute in the entity model
Yes, that strange, when I create a new table and controller, I got the error again, don't know why :(
I got the below errors:
Server Error in '/' Application.
Can't create component 'MPeLife.FormLayoutApp.FormLayoutAppService' as it has dependencies to be satisfied.
'MPeLife.FormLayoutApp.FormLayoutAppService' is waiting for the following dependencies:
- Service 'Abp.Domain.Repositories.IRepository`1[[MPeLife.Models.FormLayout, MPeLife.Core, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]]' which was not registered.
in my controller:
private readonly IFormLayoutAppService _formLayoutAppService;
public FormLayoutController(IFormLayoutAppService formLayoutAppService)
{
_formLayoutAppService = formLayoutAppService;
}
in app service:
private readonly IRepository<FormLayout> _formLayoutRepository;
public FormLayoutAppService(IRepository<FormLayout> formLayoutRepository)
{
_formLayoutRepository = formLayoutRepository;
}
I didn't change any things, just create the new table:(
I found that if I use a repository to inject the app service, and it's working:
private readonly IFormLayoutRepository _formLayoutRepository;
public FormLayoutAppService(IFormLayoutRepository formLayoutRepository)
{
_formLayoutRepository = formLayoutRepository;
}
but why it must be use Repository? I have no other custom method to use, so if I create the Repository for each table, these Repositories are empty, and I have to create an interface and implements it, but I just want to use the simple generic methods:
IRepository<MyModel>
Yes, after I used the Repository and it's working, below is my entity, there is no any especially:
public class FormLayout : Entity, IModificationAudited, ICreationAudited
{
public virtual bool Active { get; set; }
[Required]
public virtual int CateTabId { get; set; }
[Required]
public virtual string Name { get; set; }
[Required]
public virtual string Value { get; set; }
public DateTime CreationTime { get; set; }
public DateTime? LastModificationTime { get; set; }
public long? LastModifierUserId { get; set; }
public long? CreatorUserId { get; set; }
[ForeignKey("CreatorUserId")]
public virtual AdminUser CreatorUser { get; set; }
[ForeignKey("LastModifierUserId")]
public virtual AdminUser LastModifierUser { get; set; }
[ForeignKey("CateTabId")]
public virtual CategoryTab CateTab { get; set; }
}
anyone can help?
thanks!!!!
ok, I have solved this issue, because I didn't use the zero-module, so the framework can't get the user id from abpsession, after I review the source code, I know just need to override SetCreationAuditProperties this method and can solve my problem....
Yes, I know, I have solved it, thanks!
<cite>klainer: </cite> Please can you post code which solved your issue? Thanks !
Actually, I just created a class and implement the AuthorizeAttribute, this can be an attribute for do the accessright control , this is not related with ABP framework, below are some simple code:
public class AclAttribute : AuthorizeAttribute
{
public override void OnAuthorization(AuthorizationContext filterContext)
{
if (filterContext == null)
{
throw new ArgumentNullException("filterContext");
}
if (filterContext.HttpContext.Session["User"] == null)
{
filterContext.HttpContext.Session["ReturnAction"] = HttpContext.Current.Request.Url.AbsoluteUri;
HttpContext.Current.Response.Redirect("/Login");
}
if (!string.IsNullOrEmpty(this.Roles))
{
var currUser = filterContext.HttpContext.Session["User"] as AdminUser;
if (currUser == null || !AdminUserAppService.HasAccessRights(this.Roles, currUser.Role))
{
filterContext.Result = new RedirectToRouteResult(new
RouteValueDictionary(new { controller = "Error", action = "AccessDenied" }));
}
}
}
}
}
then you can use it in your controller:
[Acl(Roles = UserRole.ADMINISTRATOR)]
public class AdminUserController : ControllerBase
{
//.....
}
I think you can read my reply in this, maybe can help you ?