Hi
My code is
using Abp.Application.Services; using Abp.Application.Services.Dto; using Abp.AutoMapper; using Abp.Domain.Repositories; using Abp.Linq.Extensions; using BCITS.BsmartWater.Storage; using System.Collections.Generic; using System.Linq; using Abp.Extensions; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; using BCITS.BsmartWater.Authorization; using Abp.Authorization; using System.Collections.ObjectModel; using System.Data.Entity;
namespace BCITS.BsmartWater.Tenants.PhoneBook { public interface IPersonAppService : IApplicationService { ListResultOutput<PersonListDto> GetPeople(GetPeopleInput input); Task CreatePerson(CreatePersonInput input);
Task DeletePerson(IdInput input);
Task DeletePhone(IdInput<long> input);
Task<PhoneInPersonListDto> AddPhone(AddPhoneInput input);
}
[AutoMapTo(typeof(Phone))]
public class AddPhoneInput : IInputDto
{
[Range(1, int.MaxValue)]
public int PersonId { get; set; }
[Required]
public PhoneType Type { get; set; }
[Required]
[MaxLength(Phone.MaxNumberLength)]
public string Number { get; set; }
}
[AutoMapTo(typeof(Person))]
public class CreatePersonInput : IInputDto
{
[Required]
[MaxLength(Person.MaxNameLength)]
public string Name { get; set; }
[Required]
[MaxLength(Person.MaxSurnameLength)]
public string Surname { get; set; }
[EmailAddress]
[MaxLength(Person.MaxEmailAddressLength)]
public string EmailAddress { get; set; }
}
public class GetPeopleInput : IInputDto
{
public string Filter { get; set; }
}
[AutoMapFrom(typeof(Person))]
public class PersonListDto : FullAuditedEntityDto
{
public string Name { get; set; }
public string Surname { get; set; }
public string EmailAddress { get; set; }
public Collection<PhoneInPersonListDto> Phones { get; set; }
}
[AutoMapFrom(typeof(Phone))]
public class PhoneInPersonListDto : CreationAuditedEntityDto
{
public PhoneType Type { get; set; }
public string Number { get; set; }
}
[AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook)]
public class PersonAppService : BsmartWaterAppServiceBase, IPersonAppService
{
private readonly IRepository<Person> _personRepository;
public PersonAppService(IRepository<Person> personRepository)
{
_personRepository = personRepository;
}
public ListResultOutput<PersonListDto> GetPeople(GetPeopleInput input)
{
var persons = _personRepository
.GetAll()
.Include(p => p.Phones)
.WhereIf(
!input.Filter.IsNullOrEmpty(),
p => p.Name.Contains(input.Filter) ||
p.Surname.Contains(input.Filter) ||
p.EmailAddress.Contains(input.Filter)
)
.OrderBy(p => p.Name)
.ThenBy(p => p.Surname)
.ToList();
return new ListResultOutput<PersonListDto>(persons.MapTo<List<PersonListDto>>());
}
[AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook_CreatePerson)]
public async Task CreatePerson(CreatePersonInput input)
{
var person = input.MapTo<Person>();
await _personRepository.InsertAsync(person);
}
[AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook_DeletePerson)]
public async Task DeletePerson(IdInput input)
{
await _personRepository.DeleteAsync(input.Id);
}
public async Task DeletePhone(IdInput<long> input)
{
await _**phoneRepository**.DeleteAsync(input.Id);
}
public async Task<PhoneInPersonListDto> AddPhone(AddPhoneInput input)
{
var person = _personRepository.Get(input.PersonId);
var phone = input.MapTo<Phone>();
person.Phones.Add(phone);
await CurrentUnitOfWork.SaveChangesAsync();
return phone.MapTo<PhoneInPersonListDto>();
}
}
}
The error i am getting is The name _phoneRepository does not exit in the current context
5 Answer(s)
-
0
Hi,
You missed to inject phone repository (IRepository<Phone, long>):
See the working code here: <a class="postlink" href="https://github.com/aspnetzero/aspnet-zero-samples/blob/master/PhoneBook/src/Acme.PhoneBook.Application/People/PersonAppService.cs#L24">https://github.com/aspnetzero/aspnet-ze ... ice.cs#L24</a>
-
0
It is not showing any error But after running when clicking on the delete phone button, a popup is showing as an internal error occurred during your request.
My code for IPersonAppService is
using Abp.Application.Services; using Abp.Application.Services.Dto; using Abp.AutoMapper; using Abp.Domain.Repositories; using Abp.Linq.Extensions; using BCITS.BsmartWater.Storage; using System.Collections.Generic; using System.Linq; using Abp.Extensions; using System.Threading.Tasks; using System.ComponentModel.DataAnnotations; using BCITS.BsmartWater.Authorization; using Abp.Authorization; using System.Collections.ObjectModel; using System.Data.Entity;
namespace BCITS.BsmartWater.Tenants.PhoneBook { public interface IPersonAppService : IApplicationService { ListResultOutput<PersonListDto> GetPeople(GetPeopleInput input); Task CreatePerson(CreatePersonInput input);
Task DeletePerson(IdInput input); Task DeletePhone(IdInput<long> input); Task<PhoneInPersonListDto> AddPhone(AddPhoneInput input); } [AutoMapTo(typeof(Phone))] public class AddPhoneInput : IInputDto { [Range(1, int.MaxValue)] public int PersonId { get; set; } [Required] public PhoneType Type { get; set; } [Required] [MaxLength(Phone.MaxNumberLength)] public string Number { get; set; } } [AutoMapTo(typeof(Person))] public class CreatePersonInput : IInputDto { [Required] [MaxLength(Person.MaxNameLength)] public string Name { get; set; } [Required] [MaxLength(Person.MaxSurnameLength)] public string Surname { get; set; } [EmailAddress] [MaxLength(Person.MaxEmailAddressLength)] public string EmailAddress { get; set; } } public class GetPeopleInput : IInputDto { public string Filter { get; set; } } [AutoMapFrom(typeof(Person))] public class PersonListDto : FullAuditedEntityDto { public string Name { get; set; } public string Surname { get; set; } public string EmailAddress { get; set; } public Collection<PhoneInPersonListDto> Phones { get; set; } } [AutoMapFrom(typeof(Phone))] public class PhoneInPersonListDto : CreationAuditedEntityDto { public PhoneType Type { get; set; } public string Number { get; set; } } [AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook)] public class PersonAppService : BsmartWaterAppServiceBase, IPersonAppService { private readonly IRepository<Person> _personRepository; private readonly IRepository<Phone, long> _phoneRepository; public PersonAppService(IRepository<Person> personRepository) { _personRepository = personRepository; } public PersonAppService(IRepository<Phone, long> phoneRepository) { _phoneRepository = phoneRepository; } public ListResultOutput<PersonListDto> GetPeople(GetPeopleInput input) { var persons = _personRepository .GetAll() .Include(p => p.Phones) .WhereIf( !input.Filter.IsNullOrEmpty(), p => p.Name.Contains(input.Filter) || p.Surname.Contains(input.Filter) || p.EmailAddress.Contains(input.Filter) ) .OrderBy(p => p.Name) .ThenBy(p => p.Surname) .ToList(); return new ListResultOutput<PersonListDto>(persons.MapTo<List<PersonListDto>>()); } [AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook_CreatePerson)] public async Task CreatePerson(CreatePersonInput input) { var person = input.MapTo<Person>(); await _personRepository.InsertAsync(person); } [AbpAuthorize(AppPermissions.Pages_Tenant_PhoneBook_DeletePerson)] public async Task DeletePerson(IdInput input) { await _personRepository.DeleteAsync(input.Id); } public async Task DeletePhone(IdInput<long> input) { await _phoneRepository.DeleteAsync(input.Id); } public async Task<PhoneInPersonListDto> AddPhone(AddPhoneInput input) { var person = _personRepository.Get(input.PersonId); var phone = input.MapTo<Phone>(); person.Phones.Add(phone); await CurrentUnitOfWork.SaveChangesAsync(); return phone.MapTo<PhoneInPersonListDto>(); } }
}
Please solve my problem
-
0
All errors are written into Logs folder under web project. Can you check it and share with us?
-
0
I didnt find any Logs folder under web project
-
0
<cite>sipoyraj: </cite> I didnt find any Logs folder under web project
Logs folder is hidden in visual studio solution explorer by default. Select WEB project, Use show all files menu in the top right side of solution explorer . Then you can see the Logs folder. Inside you can find the Logs.text.
Or
You can navigate to Web project solution folder in windows explorer to find the same.