Base solution for your next web application

Activities of "cosmic"

Hi, I implemented OU based on documentation at [http://aspnetboilerplate.com/Pages/Documents/Zero/Organization-Units#filter-entities-for-a-user]). I'm using a method that gets entities in user's OUs including their child OUs. (method GetProductsForUserIncludingChildOusAsync(long userId) in documentation). Every time I call a method, I'm getting following error:

The specified LINQ expression contains references to queries that are associated with different contexts.
System.NotSupportedException: The specified LINQ expression contains references to queries that are associated with different contexts.
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.InlineObjectQuery(ObjectQuery inlineQuery, Type expressionType)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.InlineValue(Expression expression, Boolean recompileOnChange)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitExpressionList(ReadOnlyCollection`1 original)
   at System.Linq.Expressions.EntityExpressionVisitor.VisitMethodCall(MethodCallExpression m)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.FuncletizingVisitor.Visit(Expression exp)
   at System.Data.Entity.Core.Objects.ELinq.Funcletizer.Funcletize(Expression expression, Func`1& recompileRequired)
   at System.Data.Entity.Core.Objects.ELinq.ExpressionConverter..ctor(Funcletizer funcletizer, Expression expression)
   at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.CreateExpressionConverter()
   at System.Data.Entity.Core.Objects.ELinq.ELinqQueryState.GetExecutionPlan(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__6()
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<>c__DisplayClass7.<GetResults>b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.<System.Collections.Generic.IEnumerable<T>.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)

I'm using no tenants, single DB. My LINQ query is exactly as in documentation. Any idea how to solve this? Thanks.

Hi, I found a very interesting thing.

When I'll use [AbpAuthorize] attribute on any application service and then I'll call this service direct through the JavaScript, like this:

abp.services.app.machine.getStatusAsync({
    id: machineId
}).done(function (data) {
    // some code
});

Then the data.result will be always "No user logged in!". But user is logged in and he has full permissions.

But, when I'll call through the MVC controller the same app service still with the [AbpAuthorize] attribute, like this: JavaScript

$.get(url, { id: machineId }).done(function (response) {
    abp.message.info(response.result);
});

MVC Controller

public async Task<JsonResult> GetStatus(int id)
{
    var input = new GetMachineStatusInput
    {
        Id = id
    };
    var output = await _machineAppService.GetStatusAsync(input);

    return Json(new MvcAjaxResponse(output.Response.Status), JsonRequestBehavior.AllowGet);
}

Then the expected result will be returned.

Why this is happening? How I can resolve this?

Hello, I found in the application log file following warning:

WARN|Abp.Domain.Uow.CallContextCurrentUnitOfWorkProvider|There is a unitOfWorkKey in CallContext but not in UnitOfWorkDictionary!

This warning message is repeatedly added into the log file every few seconds. What does it mean? How I can fix this?

Question

Hello, I followed your documentation about Data Filters to create my custom filters, but without success. I need a filter with the support of a list of int values.

Example:

var placeIds = new List<int> { 1, 2, 3, 4, 5 };

I have tried following in my DB context, as suggested at [https://github.com/jcachat/EntityFramework.DynamicFilters])

var values = new List<int> { 1, 2, 3, 4, 5 };
var values2 = new List<int?> { null, 1, 2, 3, 4, 5 };
modelBuilder.Filter(DataFilters.MustHavePlace, (IMustHavePlace p, List<int> placeList) => placeList.Contains(p.PlaceId), values);
modelBuilder.Filter(DataFilters.MayHavePlace, (IMayHavePlace p, List<int?> placeList) => placeList.Contains(p.PlaceId), values2);

When I'll try to run the application, it will always return following exception:

ERROR|Abp.Web.Mvc.Controllers.AbpHandleErrorAttribute|System.NullReferenceException: Object reference not set to an instance of an object.
   at EntityFramework.DynamicFilters.DynamicFilterExtensions.SetSqlParameters(DbContext context, DbCommand command)
   at EntityFramework.DynamicFilters.DynamicFilterCommandInterceptor.SetDynamicFilterParameterValues(DbCommand command, DbContext context)
   at EntityFramework.DynamicFilters.DynamicFilterCommandInterceptor.ReaderExecuting(DbCommand command, DbCommandInterceptionContext`1 interceptionContext)
   at System.Data.Entity.Infrastructure.Interception.InternalDispatcher`1.Dispatch[TTarget,TInterceptionContext,TResult](TTarget target, Func`3 operation, TInterceptionContext interceptionContext, Action`3 executing, Action`3 executed)
   at System.Data.Entity.Infrastructure.Interception.DbCommandDispatcher.Reader(DbCommand command, DbCommandInterceptionContext interceptionContext)
   at System.Data.Entity.Core.EntityClient.Internal.EntityCommandDefinition.ExecuteStoreCommands(EntityCommand entityCommand, CommandBehavior behavior)
   at System.Data.Entity.Core.Objects.Internal.ObjectQueryExecutionPlan.Execute[TResultType](ObjectContext context, ObjectParameterCollection parameterValues)
   at System.Data.Entity.Core.Objects.ObjectContext.ExecuteInTransaction[T](Func`1 func, IDbExecutionStrategy executionStrategy, Boolean startLocalTransaction, Boolean releaseConnectionOnSuccess)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.&lt;&gt;c__DisplayClass7.&lt;GetResults&gt;b__5()
   at System.Data.Entity.SqlServer.DefaultSqlExecutionStrategy.Execute[TResult](Func`1 operation)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.GetResults(Nullable`1 forMergeOption)
   at System.Data.Entity.Core.Objects.ObjectQuery`1.&lt;System.Collections.Generic.IEnumerable&lt;T&gt;.GetEnumerator>b__0()
   at System.Data.Entity.Internal.LazyEnumerator`1.MoveNext()
   at System.Linq.Enumerable.Single[TSource](IEnumerable`1 source)
   at System.Linq.Queryable.Count[TSource](IQueryable`1 source)

What is wrong?

Hello, is it possible to set the User.Name and User.Surname as optional? How can I achieve this? Currently both are marked as Required. I need only UserName and EmailAddress to be required.

I have tried to override and to create new properties without Required attribute in a User class, but without success.

public class User : AbpUser<Tenant, User>
{
    ...
    public override string Name { get; set; }  // Not working
    ...
    public new string Name { get; set; }  // Not working
    ...
}

I have also tried to set properties as nullable through the EF Fluent API.

modelBuilder.Entity<User>().Property(e => e.Name).IsOptional();  // Not working

It will always return an exception:

Abp.Web.Mvc.Controllers.AbpHandleErrorAttribute|System.Data.Entity.Validation.DbEntityValidationException: Validation failed for one or more entities. See 'EntityValidationErrors' property for more details.
Question

Hi, anybody has an example to properly load data by the dynamic web API into the DataTables? I need server-side processing with pagination and filtering support.

Here is the JavaScript code I have played with:

var tableData = {
    draw: 1,
    recordsTotal: 0,
    recordsFiltered: 0,
    data: []
};
$("#datatable_auditlogs").DataTable({
    processing: true,
    serverSide: true,
    ajax: function (data, callback, settings) {
        abp.services.rioclub.auditLog.getPaged({
            skipCount: data.start,
            maxResultCount: data.length
        }).done(function (result) {
            tableData.recordsTotal = result.totalCount;
            tableData.recordsFiltered = result.totalCount;
            tableData.data = result.items;
        });
        callback(
            JSON.parse(tableData)
        );
    }
});

Above code is not working. I'll be appreciative for any help.

Hi, I have this app service:

public ListResultOutput<RecordDto> GetAllFilter(Expression<Func<Record, bool>> predicate)
{
    var items = _recordRepository.GetAllList(predicate);

    return new ListResultOutput<RecordDto>
    {
        Items = items.MapTo<List<RecordDto>>()
    };
}

I tried call this service from JavaScript code, but it didn't work:

abp.services.app.record.getAllFilter(function(r){
    return r.recordType = 20;
}).done(function (data) {
    for (var i = 0; i < data.items.length; i++) {
        records.push([i, data.items[i].points]);
    }
});

How I can call this service from JavaScript code right way? Is it possible?

Question

Hi, I have this code in the MVC controller:

public async Task<ActionResult> Edit(long? id)
{
    if (id == null)
    {
        throw new UserFriendlyException("Bad request");
    }

    var output = await _userAppService.GetAsync(new GetUserInput(id.Value));

    if (output.User == null)
    {
        throw new UserFriendlyException(L("InvalidUser"));
    }

    return View(output.User.MapTo<UserEditViewModel>());
}

If the ID is not supplied, then it will throw an UserFriendlyException, this is correct. But, when I look into the log file, there is following exception:

2015-04-17 13:43:06.1042|ERROR|Default|Abp.UI.UserFriendlyException: Bad request
   at Controllers.UsersController.<Edit>d__f.MoveNext() in c:\...\Controllers\UsersController.cs:line 109
--- 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 System.Threading.Tasks.TaskHelpersExtensions.ThrowIfFaulted(Task task)
   at System.Web.Mvc.Async.TaskAsyncActionDescriptor.EndExecute(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass37.<BeginInvokeAsynchronousActionMethod>b__36(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethod(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3d()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.AsyncInvocationWithFilters.<>c__DisplayClass46.<InvokeActionMethodFilterAsynchronouslyRecursive>b__3f()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass33.<BeginInvokeActionMethodWithFilters>b__32(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResult`1.CallEndDelegate(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncResultWrapper.WrappedAsyncResultBase`1.End()
   at System.Web.Mvc.Async.AsyncResultWrapper.End[TResult](IAsyncResult asyncResult, Object tag)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.EndInvokeActionMethodWithFilters(IAsyncResult asyncResult)
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<>c__DisplayClass2b.<BeginInvokeAction>b__1c()
   at System.Web.Mvc.Async.AsyncControllerActionInvoker.<>c__DisplayClass21.<BeginInvokeAction>b__1e(IAsyncResult asyncResult)

It looks like a result of unhandled exception. I think, the UserFriendlyException (AbpException) is not handled correctly. In log file should be only first line, or am I wrong?

Hi, is it possible to use ABP XML localization source in DataAnnotations?

For example, with the Resource file it works:

[Required]
[Display(ResourceType = typeof(MyResource), Name = "Password")]
public string Password { get; set; }

But, is it possible to do with the XML file localization source defined in the ABP module as a DictionaryBasedLocalizationSource?

Question

Hi, is there any way to define two unique menus in one module? I need two menus in my web application, one in the sidebar (MainMenu) and one in the top bar (TopMenu). Thank you for help.

Showing 1 to 10 of 11 entries