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

Activities of "fguo"

Please discard my last post. It's my fault. I forgot to add Content Type in Header while I test it by postman.

Sorry! :oops:

Thank you for your suggestion. As a test, I tried to modify the PersonAppService.AddPhone() in Phonebook example:

    public async Task<PhoneInPersonListDto> AddPhone(AddPhoneInput input)
    {
           throw new Abp.UI.UserFriendlyException(401,"Test","Invalid Code");
    }

I tried to run it in Swagger UI, and got a correct response body: { "result": null, "targetUrl": null, "success": false, "error": { "code": 401, "message": "Test", "details": "Invalid Code", "validationErrors": null }, "unAuthorizedRequest": false, "__abp": true }

However, when I tried to run it by POSTMAN, I got a different error in response body: { "result": null, "targetUrl": null, "success": false, "error": { "code": 0, "message": "Your request is not valid!", "details": "The following errors were detected during validation.\r\n - \r\n", "validationErrors": [ { "message": "", "members": [ "" ] } ] }, "unAuthorizedRequest": false, "__abp": true }

Can you advise what I did wrong?

BTW, this is for a 3rd party client which I can't control. The client side just needs to receive the same error code and message as what I see in Swagger.

Thanks,

I sometime need to response an error message and assign an error code to reject a HTTP request. For example, there is an AddPhoneNumber method in the phonebook example. If the input phone number in HTTP POST request is in our blocked list, I need to reject the POST request with Error code 401 and a message of "Blocked Phone Number". How do I implement it? Do you have a similar example?

Thanks,

Got it. Because the Phone is defined in Person as virtual ICollection<Phone>, it is not initiated along with "new Person()". I modified my code as following (adding 2 lines with comment):

public async Task<PhoneInPersonListDto> AddPhone(AddPhoneInput input) { var person = new Person(); person.Phones = new List<Phone>(); // concrete ICollection<Phone> person.Name = "x"; person.Surname = "y";

var phone = ObjectMapper.Map<Phone>(input); person.Phones.Add(phone);

var personId = await _personRepository.InsertAndGetIdAsync(person); var phoneId = phone.Id; // Cannot get this if using InsertAsync(person).

return ObjectMapper.Map<PhoneInPersonListDto>(phone); }

It works as expected. Thank you! :)

BTW, do you think the "new List<T>(); " is the best way to initiate ICollection<T>?

I am trying to provide an API to insert a parent object with children objects. For testing, I modified a little from the phonebook example, but it always throws out System.NullReferenceException: Object reference not set to an instance of an object.

Here is my code:

    public async Task&lt;PhoneInPersonListDto&gt; AddPhone(AddPhoneInput input)
    {
        var person = new Person();
        person.Name = "x";
        person.Surname = "y";

        var phone = ObjectMapper.Map&lt;Phone&gt;(input);
        person.Phones.Add(phone);

        var personId = await _personRepository.InsertAndGetIdAsync(person);

        return ObjectMapper.Map&lt;PhoneInPersonListDto&gt;(phone);
    }

Can you advise what I missed?

Thanks,

Got it! In debug mode, the Log.txt is located in Web.Host\bin\Debug\net461\App_Data. It works as I expected.

Thanks,

I have similar questions. In debug mode, how do I see the real exception message?

When I add my own applications (e.g. a POST for inserting a record into DB table), I first test it in swagger interface. Some times, I get a message in Response Body: "An internal error occurred during your request!" Usually, this message relates to an exception thrown from Database. It is very helpful for debugging, if I can read the exception message.

In release mode, I can read the exception details from Log.txt file. How do I find the similar Log file or "real exception message" while testing in swagger?

Thanks,

I noticed that most entity properties are defined as "public virtual ..." in Phonebook example and other code. As my understanding, "virtual" is for lazy loading or overwriting in derived classes. So, it is useful to define "virtual" on navigation properties (e.g. public virtual ICollection<Phone> Phones { get; set; }). What is the purpose to define all other entity properties as "virtual" (e.g. public virtual string Name { get; set; })? Does it effect performance on large DB tables?

Thanks,

Understand now and tried this way. It works as expected!

Thank you very much!

I am trying Core + angular v4.1. The Web.Public is new on this version. Not sure how to "run mvc to seed data". Can you tell me more details?

Thanks,

Showing 171 to 180 of 254 entries