Base solution for your next web application

Activities of "Bernard"

HI,

I had to convert my Json like following

`var questionnaire = _$questionnaireInformationForm.serializeFormToObject();

function convertJsonToArray(oldJson) {

var newJson = {
    "Questions": [],
    "intitule": oldJson.intitule,
    "descriptif": oldJson.descriptif,
    "dateDebut": oldJson.dateDebut,
    "dateFin": oldJson.dateFin
};


$.each(oldJson.Questions, function (index, questionData) {
    if (index.includes("Text")) {
        // Extraire la question
        var questionIndex = index.split(".")[0];
        var question = {
            "Text": questionData,
            "Type": oldJson.Questions[questionIndex + ".Type"],
            "Answers": []
        };

   
        $.each(oldJson.Questions[questionIndex + ".Answers"], function (answerKey, answerValue) {
            if (answerKey.includes("Text")) {
                question.Answers.push({ "Text": answerValue });
            }
        });

  
        newJson.Questions.push(question);
    }
});

return newJson;

}

// Conversion var newJson = convertJsonToArray(questionnaire); debugger

console.log(JSON.stringify(newJson, null, 4));

abp.ui.setBusy(); _questionnairesService .createOrEdit(newJson)`......

Answer

Hi Could you please share the link

Thks

Answer

Hi

Have you the time to make a sample ?

Answer

Hi oguzhanagir,

**I finally found the solution ! **

I must Map person entity with input this way in Creat method :

` [AbpAuthorize(AppPermissions.Pages_Persons_Create)] protected virtual async Task Create(CreateOrEditPersonDto input) { var person = ObjectMapper.Map

   if (AbpSession.TenantId != null)
   {
       person.TenantId = (int?)AbpSession.TenantId;
   }

   //For Test
   person.Id = 90;

   //await _personRepository.InsertAsync(person);
   //await CurrentUnitOfWork.SaveChangesAsync();

   ObjectMapper.Map(person, input);

}`

And in method CreateOrEdit send Output this way :

` public virtual async Task

 if (input.TypePerson == TypePerson.Physique)
 {
     input.Intitule = $"{input.Prenom} {input.Nom}";


 }

 if (input.Id == null)
 {
     await Create(input);

 }
 else
 {

     await Update(input);
 }

 var person = ObjectMapper.Map<Person>(input);
 var output = new GetPersonForEditOutput { Person = ObjectMapper.Map<CreateOrEditPersonDto>(person) };

 return output;

}`

And Id is here !

Please tell me if something is wrong or must be changed

Thks for All patience oguzhanagir

Bernard

Answer

Hi Bernard

As far as I understand, you want to perform a create operation using the service method and this method has a return value, which you want to receive on the Javascript side. After correcting the return value of the service method here, you can use the sample code on the Javascript side.

 _exampleService 
   .exampleMethod({ 
     id: exampleId, 
   }) 
   .done(function (result) { 
     console.log(result); 
   }); 

With this usage, you can get the values ​​returned in the service method.

Not exaxtly The personservice and the entire code have been generated by PowerTools from Asp Net zero . I just want to get the Id of the new entity because for the moment you have to close the view to be able to have this id, I would like to stay on the view and refresh by obtaining the id of the new entity. I need this id because I have one to many relationships

For example : Person has many Task

to add a new Task in Person Create view i must be able to get the PersonId.

Answer

The type seems to be good but no data returned

Answer

` public class CreatePersonOutput { public int Id { get; set; } }

[AbpAuthorize(AppPermissions.Pages_Persons_Create)] protected virtual async Task

   if (AbpSession.TenantId != null)
   {
       person.TenantId = (int?)AbpSession.TenantId;
   }

   person.Color = GenerateRandomColor();
   person.Id = 20;
   //await _personRepository.InsertAsync(person);
   //await CurrentUnitOfWork.SaveChangesAsync();

   return new CreatePersonOutput { Id = person.Id };

}

`

No changes in result after changing method

Answer

Hi oguzhanagir

The Create method is :

[AbpAuthorize(AppPermissions.Pages_Persons_Create)] protected virtual async Task <int> Create(CreateOrEditPersonDto input) { var person = ObjectMapper.Map<Person>(input); `

if (AbpSession.TenantId != null)
{
    person.TenantId = (int?)AbpSession.TenantId;
}

person.Color = GenerateRandomColor();


await _personRepository.InsertAsync(person);
await CurrentUnitOfWork.SaveChangesAsync();

return person.Id ;

}`

and JS :

` _personsService .createOrEdit(person) .done(function (result) {

     console.log("PersonId :" + result);

     abp.notify.info(app.localize('SavedSuccessfully'));
     abp.event.trigger('app.createOrEditPersonModalSaved');
    
     if (typeof successCallback === 'function') {
         successCallback();
     }
 })`
        

Answer

Hi oguzhanagir,

Sorry i'm not able ro retrieve saved data in my view when Create Mode; there might be an example in the project ? I am not used to working in service mode but directly with a controller and in ASP MVC 5 version;

thks for help Bernard

Answer

Hi, Do I have to return the result in Json to be able to read it on Jquery side? Because id is empty and other fields are filled

Showing 1 to 10 of 92 entries