Skip to content

Commit cdb2b04

Browse files
authored
Merge pull request #210 from aspnetzero/pr/3686
Update Developing-Step-By-Step-Angular-Edit-Mode-Phone-Numbers.md
2 parents 7dd0fda + b9f7252 commit cdb2b04

File tree

1 file changed

+1
-183
lines changed

1 file changed

+1
-183
lines changed

docs/en/Developing-Step-By-Step-Angular-Edit-Mode-Phone-Numbers.md

Lines changed: 1 addition & 183 deletions
Original file line numberDiff line numberDiff line change
@@ -180,189 +180,7 @@ export class PhoneBookComponent extends AppComponentBase implements OnInit {
180180
}
181181
```
182182

183-
# Edit Mode For People
184-
185-
Now we want to edit name, surname and e-mail of people:
186-
187-
<img src="images/edit-person-core1.png" alt="Edit Person" class="img-thumbnail" />
188-
189-
First of all, we create the necessary DTOs to transfer people's id, name,
190-
surname and e-mail. We can optionally configure auto-mapper, but this is not necessary because all properties match automatically. Then we create the functions in PersonAppService for
191-
editing people:
192-
193-
```csharp
194-
[AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook_EditPerson)]
195-
public async Task<GetPersonForEditOutput> GetPersonForEdit(GetPersonForEditInput input)
196-
{
197-
var person = await _personRepository.GetAsync(input.Id);
198-
return ObjectMapper.Map<GetPersonForEditOutput>(person);
199-
}
200-
201-
[AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook_EditPerson)]
202-
public async Task EditPerson(EditPersonInput input)
203-
{
204-
var person = await _personRepository.GetAsync(input.Id);
205-
person.Name = input.Name;
206-
person.Surname = input.Surname;
207-
person.EmailAddress = input.EmailAddress;
208-
await _personRepository.UpdateAsync(person);
209-
}
210-
```
211-
212-
Then we add configuration for AutoMapper into CustomDtoMapper.cs like below:
213-
214-
```csharp
215-
configuration.CreateMap<Person, GetPersonForEditOutput>();
216-
```
217-
218-
## View
219-
220-
Create edit-person-modal.component.html:
221-
222-
```html
223-
<div bsModal #modal="bs-modal" (onShown)="onShown()" class="modal fade" tabindex="-1" role="dialog" aria-labelledby="modal" aria-hidden="true" [config]="{backdrop: 'static'}">
224-
<div class="modal-dialog modal-lg">
225-
<div class="modal-content">
226-
<form *ngIf="active" #personForm="ngForm" novalidate (ngSubmit)="save()">
227-
<div class="modal-header">
228-
<h4 class="modal-title">
229-
<span>{{"EditPerson" | localize}}</span>
230-
</h4>
231-
<button type="button" class="close" (click)="close()" aria-label="Close">
232-
<span aria-hidden="true">&times;</span>
233-
</button>
234-
</div>
235-
<div class="modal-body">
236-
237-
<div class="form-group">
238-
<label>{{"Name" | localize}}</label>
239-
<input #nameInput class="form-control" type="text" name="name" [(ngModel)]="person.name" required maxlength="32">
240-
</div>
241-
242-
<div class="form-group">
243-
<label>{{"Surname" | localize}}</label>
244-
<input class="form-control" type="email" name="surname" [(ngModel)]="person.surname" required maxlength="32">
245-
</div>
246-
247-
<div class="form-group">
248-
<label>{{"EmailAddress" | localize}}</label>
249-
<input class="form-control" type="email" name="emailAddress" [(ngModel)]="person.emailAddress" required maxlength="255" pattern="^\w+([\.-]?\w+)*@\w+([\.-]?\w+)*(\.\w{1,})+$">
250-
</div>
251-
252-
</div>
253-
<div class="modal-footer">
254-
<button [disabled]="saving" type="button" class="btn btn-secondary" (click)="close()">{{"Cancel" | localize}}</button>
255-
<button type="submit" class="btn btn-primary" [disabled]="!personForm.form.valid" [buttonBusy]="saving" [busyText]="l('SavingWithThreeDot' | localize)"><i class="fa fa-save"></i> <span>{{"Save" | localize}}</span></button>
256-
</div>
257-
</form>
258-
</div>
259-
</div>
260-
</div>
261-
```
262-
263-
Add those lines to **phonebook.component.html:**:
264-
265-
```html
266-
267-
// Other Code lines...
268-
269-
<button (click)="editPerson(person)" title="{{'Edit' | localize}}" class="btn btn-outline-hover-primary btn-icon">
270-
<i class="fa fa-plus"></i>
271-
</button>
272-
<button *ngIf="'Pages.Tenant.PhoneBook.EditPerson' | permission" (click)="editPersonModal.show(person.id)" title="{{'EditPerson' | localize}}" class="btn btn-outline-hover-success btn-icon">
273-
<i class="fa fa-pencil"></i>
274-
</button>
275-
<button id="deletePerson" (click)="deletePerson(person)" title="{{'Delete' | localize}}" class="btn btn-outline-hover-danger btn-icon" href="javascript:;">
276-
<i class="fa fa-times"></i>
277-
</button>
278-
279-
// Other Code lines...
280-
281-
<createPersonModal #createPersonModal(modalSave)="getPeople()"></createPersonModal>
282-
<editPersonModal #editPersonModal (modalSave)="getPeople()"></editPersonModal>
283-
```
284-
285-
## Controller
286-
287-
Create edit-person-modal.component.ts:
288-
289-
```typescript
290-
import { Component, ViewChild, Injector, ElementRef, Output, EventEmitter } from '@angular/core';
291-
import { ModalDirective } from 'ngx-bootstrap';
292-
import { PersonServiceProxy, EditPersonInput } from '@shared/service-proxies/service-proxies';
293-
import { AppComponentBase } from '@shared/common/app-component-base';
294-
295-
@Component({
296-
selector: 'editPersonModal',
297-
templateUrl: './edit-person-modal.component.html'
298-
})
299-
export class EditPersonModalComponent extends AppComponentBase {
300-
301-
@Output() modalSave: EventEmitter<any> = new EventEmitter<any>();
302-
303-
@ViewChild('modal' , { static: false }) modal: ModalDirective;
304-
@ViewChild('nameInput' , { static: false }) nameInput: ElementRef;
305-
306-
person: EditPersonInput = new EditPersonInput();
307-
308-
active: boolean = false;
309-
saving: boolean = false;
310-
311-
constructor(
312-
injector: Injector,
313-
private _personService: PersonServiceProxy
314-
) {
315-
super(injector);
316-
}
317-
318-
show(personId): void {
319-
this.active = true;
320-
this._personService.getPersonForEdit(personId).subscribe((result)=> {
321-
this.person = result;
322-
this.modal.show();
323-
});
324-
325-
}
326-
327-
onShown(): void {
328-
// this.nameInput.nativeElement.focus();
329-
}
330-
331-
save(): void {
332-
this.saving = true;
333-
this._personService.editPerson(this.person)
334-
.subscribe(() => {
335-
this.notify.info(this.l('SavedSuccessfully'));
336-
this.close();
337-
this.modalSave.emit(this.person);
338-
});
339-
this.saving = false;
340-
}
341-
342-
close(): void {
343-
this.modal.hide();
344-
this.active = false;
345-
}
346-
}
347-
```
348-
349-
Add those lines to **main.module.ts:**:
350-
351-
```typescript
352-
import { EditPersonModalComponent } from './phonebook/edit-person-modal.component';
353-
354-
// Other Code lines...
355-
356-
declarations: [
357-
DashboardComponent,
358-
PhoneBookComponent,
359-
CreatePersonModalComponent,
360-
EditPersonModalComponent
361-
]
362-
363-
// Other Code lines...
364-
```
365183

366184
## Next
367185

368-
- [Edit Mode For People](Developing-Step-By-Step-Angular-Edit-Mode-People)
186+
- [Edit Mode For People](Developing-Step-By-Step-Angular-Edit-Mode-People)

0 commit comments

Comments
 (0)