thanks hikalkan, you rock :) i knew there is a small silly mistake :$
Can I take a few more moments of yours and ask a question about another issue I posted earlier, but still struggling to understand what to do about the public users?
Actually its a big decision to make, I think i have 3 options:
Please share your opinon. looking forward to your ideas. Arslan.
Well I can make use of another entity bUT what about the filters like IMusthave tenant, the abp framework for handling cookies and all. There will be no permissions requirement for now, but I will be saving basic user settings, a little transaction history, managing notifications and messages between the public users and tenant users and saving logs for capturing user experience.
Hi Hikalkan, well thanks for the previous replies as they really helped me managing my repositories and application services while keeping my code neat and clean. rite now i have another small issue, may be i am making a very basic mistake.
I have a repository container same as mentioned earlier.
Since my core classes are all relational, which means they have navigation objects of parent and navigation list of child in them. I am using Angular SPA which requires JSON objects and they cannot be circular referenced so to handle this i have made DTOs of all these Core classes but without the navigation objects which actually worked fine.
But now i have a complex scenario where i want to send a Complex DTO of a BusinessServices (table in db) with its Questions (Child Table) and Questions with its choices(Child of child). all of these tables are 1 to many in relationship. So i have made the DTOs as follows:
[MapTo]
[AutoMap(typeof(BusinessServices))]
public class AdminServiceCompleteDto : EntityDto, IDoubleWayDto
{
...... // Dto properties same as Core
public ICollection<AdminQuestionsDto> questions {get;set;}
}
[AutoMap(typeof(Qualification))]
public class AdminQualificationDto: EntityDto,IDoubleWayDto
{
.....// Dto properties same as Core
public int ServiceId {get;set;}
public ICollection<AdminInputChoiceDto> mcqAnswers { get; set; }
}
[AutoMap(typeof(CustomerInputChoice))]
public class AdminInputChoiceDto: EntityDto,IDoubleWayDto
{
.....// Dto properties same as Core
public int QuestionId {get;set;}
}
Now I send the AdminServiceCompleteDto object to Angular SPA which recieves it well and displays everything nicely.
But when i send the updated object back and try to update the same object then nothings gets updated. I tried following but nothing works:
Try1:
public AdminServiceCompleteDto SetServiceData(AdminServiceCompleteDto input)
{
var service = _adminBusinessServiceRepository.Get(input.Id);
service = input.MapTo<BusinessServices>();
return service.MapTo<AdminServiceCompleteDto>();
}
// Result: Nothing gets updated.
Try 2:
public AdminServiceCompleteDto SetServiceData(AdminServiceCompleteDto input)
{
var service = _adminBusinessServiceRepository.InsertOrUpdate(input.MapTo<BusinessServices>());
return service.MapTo<AdminServiceCompleteDto>();
}
// Result: Nothing gets updated.
Try 3:
public AdminServiceCompleteDto SetServiceData(AdminServiceCompleteDto input)
{
BusinessServices service = new BusinessServices();
if (input.Id > 0)
{
service = _adminDataRepositories._businessServicesRepository.Get(input.Id);
service = input.MapTo<BusinessServices>();
CurrentUnitOfWork.SaveChanges();
var qualifications = input.qualification.MapTo<List<Qualification>>();
foreach (var q in input.qualification)
{
q.bServId = service.Id;
var question = _adminDataRepositories._qualificationRepository.InsertOrUpdate(q.MapTo<Qualification>()); // program break here
foreach (var a in q.mcqAnswers)
{
a.qualificationId = question.Id;
_adminDataRepositories._customerInputChoiceRepository.InsertOrUpdate(a.MapTo<CustomerInputChoice>());
}
}
}
else
service =_adminDataRepositories._businessServicesRepository.Insert(input.MapTo<BusinessServices>());
return service.MapTo<AdminServiceCompleteDto>();
}
// This gives runtime error but with no data.
But it works if i bring earch DTO serperately and save them individually. Which is lengthy and cumbersome :( i would appreciate if you could give me a quick and easy process for the above problem. Arslan.
hey, Thankyou for sharing, its worth appreciating
sorry but its not happening help me, review my code please: Definition:
public interface ISupplierRepositoriesContainer: ITransientDependency
{
ISupplierProfileRepository _supplierProfileRepository { get; }
ISupplierBusnsServicesRepository _supplierBusnsServicesRepository { get; }
ISupplierBusnsCoverageRepository _supplierBusnsCoverageRepository { get; }
ISupplierPhotosRepository _supplierPhotosRepository { get; }
ISupplierVideosRepository _supplierVideosRepository { get; }
ISupplierCertificationsRepository _supplierCertificationRepository { get;}
ISupplierLeadsRepository _supplierLeadsRepository { get; }
}
Implementation:
class SupplierRepositoryContainer: ISupplierRepositoriesContainer, ITransientDependency
{
public ISupplierProfileRepository _supplierProfileRepository { get; }
public ISupplierBusnsServicesRepository _supplierBusnsServicesRepository { get; }
public ISupplierBusnsCoverageRepository _supplierBusnsCoverageRepository { get; }
public ISupplierPhotosRepository _supplierPhotosRepository { get; }
public ISupplierVideosRepository _supplierVideosRepository { get; }
public ISupplierCertificationsRepository _supplierCertificationRepository { get; }
public ISupplierLeadsRepository _supplierLeadsRepository { get; }
}
Thanks bro. It did resolve my problem already.
I tried everything as mentioned, but I am getting different errors on your different suggestions. Let me list the two which I want to use: 1.Your suggestion to use
_supplierRepository.FirstOrDefault(t=>t.TenantId==AbpSession.TenantId);
is not retrieving the supplier object from db and Throwing a null object reference at the time of first usage in following method:
public List<SupplierBusnsServiceDto> GetSupplierBusnsService()
{
return Mapper.Map<List<SupplierBusnsServiceDto>>(_supplierProfile.supplierbusnsServices);
}
I have created a one-one relation with Tenant because I am trying to build a Supplier Profile architecture, which will have its business services, photos , videos and other tables. All of these will be child tables of the SupplierProfile Entity. My db model looks like following:
public SupplierAppServices(IRepository<SupplierProfile> supplierRepository)
{
_supplierRepository = supplierRepository;
_supplierProfile = GetCurrentTenant().supplier; // or
//_supplierProfile = supplierRepository.Get(AbpSession.TenantId.Value);
}
Note that all of this is in my AppService Class, where all methods of this class are UOW by default and should get the Repository using dependency injection. And by using AppServiceBase inheritance i should be able to get the TenantManager and UserManager methods like GetCurrentTenant and GetCurrentUser. But i am getting error on calling GetCurrentTenant() in my constructor that "Must set UnitOfWorkManager before use it" on following line in my AppServiceBase Class
Line 60: using (CurrentUnitOfWork.SetTenantId(null))
Line 61: {
Line 62: return TenantManager.GetById(AbpSession.GetTenantId());
Summary: First Try is not giving data because there is a null object reference errors because the repository object is not retrieving data from db. Second try is not giving tenant because UOW is not set where as i am calling the GetTenantId from my app service Constructor.
I strongly hope that you will guide me with better programming logic and a permanent solution.
Hi Hikalkan , Yes I read that documentation last night and I think I should call ToList() method after the getall method.
Anyways I need a little more help. Can you please give me sample code snippet to lazy load my supplier. Also note that my supplier and tenant entities are in one to one relationship having a navigation object in each entity class. Do you recommend calling a GetCurrentTenant () method in my AppService constructor to load my supplier object?
Hi Doubleday, I tried downloading from the above link but the link is broken. Can you send another link. Arslan.