private async Task ValidateRelation(DeathDoc deathDoc) { var allDocTypeRelations = await _lookupsService.GetLookups <DocumentTypeRelation>(); var docType = await GetDocType(); if (!allDocTypeRelations.Any(a => a.DocumentTypeId == docType.Id && a.RelationId == deathDoc.RelationId && a.GenderId == deathDoc.GenderId)) { throw new DomainException($"The relation of the requester and the death document owner is not valid.\r\nDeathDoc Name: {deathDoc?.Name?.FullName}, RelationId:{deathDoc?.RelationId}"); } }
public void AddDeathRecordDoc_ReturnsRequestWithCorrectCount() { //Arrange var req = CreateRequestInstance(); DeathDoc doc = new DeathDoc(); //Act req.AddDeathRecordDoc(doc); //Assert Assert.Equal(1, req.DeathDocs.Count); }
private void SetDefaultNID(DeathDoc deathDoc) { /* * This is a workaround: * We have the NID as DDD value object and to handle value objects in ef core we use OwnsOne in fluent api * OwnsOne doesn't allow null properties for values objects except if you are saving it in a deparate table * We can avoid this be setting NID prop to an empty new instance with the value of NationalIdenNumber = null * but this will through an exception in the constructor of NID value object */ if (deathDoc.NID == null) { deathDoc.NID = new NID(Constants.DEFAULT_NID_NUMBER); } }
public async Task CreateAndGetDoc() { var doc = new DeathDoc() { MotherFullName = "Fatema" }; await _deathDocRepository.CreateDeathDoc(doc); await _deathDocRepository.UnitOfWork.CommitChangesAsync(); Assert.True(doc.Id > 0); var docFromDB = _moisContext.DeathDocs.FirstOrDefault(a => a.Id == doc.Id); Assert.Equal(doc.MotherFullName, docFromDB.MotherFullName); }
public async Task <IEnumerable <DeathDocResponse> > CreateDeathDocsAsync(IEnumerable <DeathDoc> deathRecords, bool autoSave = false) { for (int i = 0; i < deathRecords.Count(); i++) { DeathDoc deathRecord = deathRecords.ElementAt(i); await ValidateRelation(deathRecord); await SetDefaultStateId(deathRecord); SetDefaultNID(deathRecord); deathRecord.Price = await GetDocPrice(); await _deathDocRepository.CreateDeathDoc(deathRecord); } if (autoSave) { await SaveChangesAsync(); } return(deathRecords.Select(a => new DeathDocResponse(a))); }
public async Task CreateDeathDoc(DeathDoc deathDoc) { await _dbContext.DeathDocs.AddAsync(deathDoc); }
private DeathDocResponse(bool success, string message, DeathDoc deathRecord) : base(success, message) => DeathDoc = deathRecord;
private async Task SetDefaultStateId(DeathDoc deathRecord) { var defaultState = await _lookupsService.FindWhere <State>(a => a.Code == "NEW"); deathRecord.StateId = defaultState?.Id; }