Got it. Thanks your clarification!
Thanks, got it. yes, I have made validation on client side ,but to make sure application reliability, I make the validation on server side also. I think I can use CustomValidate to address this issue. Thanks again.
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?
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.
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.
I have addressed it with a easy way, may be it is not a best practice, but I would like to share it here:
in console application, first I post a HttpWebRequest to <a class="postlink" href="http://localhost:62345/account/login">http://localhost:62345/account/login</a>, then in the response, we can get the cookie with access token.
Then I send the request to <a class="postlink" href="http://localhost:62345/api/services/app/question/GetQuestions">http://localhost:62345/api/services/app ... tQuestions</a>, and put the cookie with access token in the request header.
then question/GetQuestions works fines, the result id returned.
Thanks your clarification, I have used another way to avoid required it.
Thanks so much. Yes, add 'id' to injection list, then it works fine.