Base solution for your next web application
Starts in:
01 DAYS
01 HRS
01 MIN
01 SEC

Activities of "lcyhjx"

I define a domain entity as following: public class Order : FullAuditedEntity<long, User>
{

    public string OrderNumber { get; set; }
…

}

I have a service method in application layer as below: public InitReceiveOrderOutput InitReceiveOrder(InitReceiveOrderInput input) { Order order1 = _orderRepository.GetAll() .Include(x=>x.CreatorUser) .FirstOrDefault(x=>x.Id == input.OrderId);

        Order order2 = _orderRepository.GetAll()
           .FirstOrDefault(x => x.Id == input.OrderId);

        return new InitReceiveOrderOutput(order);
    }

After execute Order order1 = _orderRepository.GetAll() .Include(x=>x.CreatorUser) .FirstOrDefault(x=>x.Id == input.OrderId); I would like to get order with CreateUser

After execute Order order2 = _orderRepository.GetAll() .FirstOrDefault(x => x.Id == input.OrderId); I would like to get order without CreateUser

But actually, I found both order1 and order2 with CreateUser, I am not sure why? Do you have any suggestion to get order without CreateUser?

Application Service

public class OrderPublishService : ApplicationService, IOrderPublishService
    {

        private readonly IRepository<Order,long> _orderRepository;
        private readonly OrderDomainService _orderDomainService;
        private readonly IUnitOfWorkManager _unitOfWorkManager;


        public OrderPublishService(IRepository<Order, long> orderRepository,OrderDomainService orderDomainService , IUnitOfWorkManager unitOfWorkManager)
        {
            _orderRepository = orderRepository;
            _orderDomainService = orderDomainService;
            _unitOfWorkManager = unitOfWorkManager;
        }

     
        public  PublishOrderOutput PublishOrder(PublishOrderInput input)
        {
            //map, I do not user automap here
            Order order = input.Map2Order(); 

           _orderRepository.Insert(order);
   
            _unitOfWorkManager.Current.SaveChanges();

            return new PublishOrderOutput()
            {
                 
            };
        }
    }

//Repository

public class OrderRepository : BOMRepositoryBase<Order, long>,IOrderRepository
    {
        public OrderRepository(IDbContextProvider<BOMDbContext> dbContextProvider)
            : base(dbContextProvider)
        {
        }
    }

//Domain Entity

public class Order : FullAuditedEntity<long, User>  
    {

        public string OrderNumber { get; set; }

       //other property
       .....
}

I have addressed it by changing the code as following :

throw new UserFriendlyException("Available balance is not enough.");

then the response is:

<Response xmlns="http://localhost/api/services/app/orderpublish/publishorder">
   <error>
      <code>0</code>
      <details null="true"/>
      <message>Available balance is not enough.</message>
      <validationErrors null="true"/>
   </error>
   <result null="true"/>
   <success>false</success>
   <unAuthorizedRequest>false</unAuthorizedRequest>
</Response>

Not sure if it is the best way, if not, could you please let me know the best practice?

Hi,

Please see following scenario: I mark a field as [required] for a service input, then I invoke this service but do not pass the value of the required field. Then get following response:

{
   "success": false,
   "result": null,
   "error":    {
      "code": 0,
      "message": "Your request is not valid!",
      "details": null,
      "validationErrors": [      {
         "message": "The EstimateStartTime field is required.",
         "members": null
      }]
   },
   "unAuthorizedRequest": false
}

The error message ‘Your request is not valid’ and “The EstimateStartTime field is required” are predefined. How can I implement localization for these predefined error message? Do you have any suggestion?

Yes, I was testing if exception in UserManager.LoginAsync, what will happen. I have checked thie logs in website – logs.txt. But cannot find the exception in log file.

Hi

Please see following scenario: I have an application service, in the business logic, need to do some business rule validation. If validation failed, then I throw an AbpException as following” throw new Abp.AbpException("Available balance is not enough.");

But when I invoked the service, I get following response:

{
   "success": false,
   "result": null,
   "error":    {
      "code": 0,
      "message": "An internal error occured during your request!",
      "details": null,
      "validationErrors": null
   },
   "unAuthorizedRequest": false
}

You can see the error message is a common message ‘An internal error occured during your request!’, but the message I want is ‘Available balance is not enough’. The common error message is fine for unexpected exception, but for the business error, I need to get specific business error message in front-end application. Do you have any suggestion?

BTW, there is spelling error: An internal error occured during your request! An internal error occurred during your request!

Thanks! if I invoke unitOfWorkManager.Current.SaveChanges() explictly, then the data is inserted into DB. But I cannot understand, why I need to invoke unitOfWorkManager.Current.SaveChanges() explictly. as my understand, the transanction should be commited automatically at the end of method.

it's not inserted to database, the service operation is executed completed, but still cannot find it in DB. Also, I tried to make following change - I did not pass the value to a un-nullable field, I would like to get a exception to verify the Repository.Insert method, but unfortunattly, still no error, no exception thrown.

Hi,

I define a entiy named Order, and define a service In application layer called orderService. In orderService, there are two operations. GetAll() and CreateNewOrder();

The GetAll() operation works fine, the mainly code is

var orders= _orderRepository.GetAll().ToList();

but the CreateNewOrder does not work, I debug it, the following statement has been executed.

var newOrder = _orderRepository.Insert(order);

But nothing happened, the new order is not inserted in to DB, no exception.

I am sure something is wrong in my coding, but no exception when execute Repository.Insert statement, so it is hardly for me to know what’s the issue.

Do you have any suggestion?

Hi In AuthorizationProvider, we can initialize permissions,

public class BOMAuthorizationProvider : AuthorizationProvider
    {
        public override void SetPermissions(IPermissionDefinitionContext context)
        {
            //TODO: Localize (Change FixedLocalizableString to LocalizableString)

            context.CreatePermission("CanCreateQuestions", new FixedLocalizableString("Can create questions"));
            context.CreatePermission("CanDeleteQuestions", new FixedLocalizableString("Can delete questions"));
            context.CreatePermission("CanDeleteAnswers", new FixedLocalizableString("Can delete answers"));
            //context.CreatePermission("CanAnswerToQuestions", new FixedLocalizableString("Can answer to questions"), isGrantedByDefault: true);
            context.CreatePermission("CanAnswerToQuestions", new FixedLocalizableString("Can answer to questions"));

        }
    }

My question is how to implement localization for permissions which will be displayed on GUI. For example, in localization xml file, define a localization string as below

<text name="Permission_Create_Question" value="Can create questions" />

in another localization xml file, define a localization string as below

<text name="Permission_Create_Question" value="新增提问" />

what change should I do to implement it? Thanks!

Showing 21 to 30 of 54 entries