Esempio n. 1
0
        private async Task ValidateRelation(BirthDoc birthDoc)
        {
            var allDocTypeRelations = await _lookupsService.GetLookups <DocumentTypeRelation>();

            var docType = await GetDocType();

            if (!allDocTypeRelations.Any(a => a.DocumentTypeId == docType.Id && a.RelationId == birthDoc.RelationId && a.GenderId == birthDoc.GenderId))
            {
                throw new DomainException($"The relation of the requester and the birth document owner is not valid.\r\nBirthDoc Name: {birthDoc?.Name?.FullName}, RelationId:{birthDoc?.RelationId}");
            }
        }
Esempio n. 2
0
        public void AddBirthDoc_ReturnsRequestWithCorrectCount()
        {
            //Arrange
            var      req = CreateRequestInstance();
            BirthDoc doc = new BirthDoc();

            //Act
            req.AddBirthDoc(doc);

            //Assert
            Assert.Equal(1, req.BirthDocs.Count);
        }
Esempio n. 3
0
 private void SetDefaultNID(BirthDoc birthDoc)
 {
     /*
      * 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 (birthDoc.IsFirstTime /* && birthDoc.NID == null*/)
     {
         birthDoc.NID = new NID(Constants.DEFAULT_NID_NUMBER);
     }
 }
Esempio n. 4
0
        public async Task CreateAndGetDoc()
        {
            var doc = new BirthDoc()
            {
                MotherFullName = "Fatema"
            };
            await _birthDocRepository.CreateBirthDoc(doc);

            await _birthDocRepository.UnitOfWork.CommitChangesAsync();

            Assert.True(doc.Id > 0);

            var docFromDB = _moisContext.BirthDocs.FirstOrDefault(a => a.Id == doc.Id);

            Assert.Equal(doc.MotherFullName, docFromDB.MotherFullName);
        }
Esempio n. 5
0
        public async Task <IEnumerable <BirthDocResponse> > CreateBirthDocsAsync(IEnumerable <BirthDoc> birthDocs, bool autoSave = false)
        {
            for (int i = 0; i < birthDocs.Count(); i++)
            {
                BirthDoc birthDoc = birthDocs.ElementAt(i);

                await ValidateRelation(birthDoc);
                await SetDefaultStateId(birthDoc);

                SetDefaultNID(birthDoc);
                birthDoc.Price = await GetDocPrice();

                await _birthDocRepository.CreateBirthDoc(birthDoc);
            }
            if (autoSave)
            {
                await SaveChangesAsync();
            }
            return(birthDocs.Select(a => new BirthDocResponse(a)));
            //return birthDocs.Select(a => new BirthDocResponse($"An error occurred while saving the birth docs: {ex.Message}"));
            //return new BirthDocResponse($"An error occurred while saving the birth doc: {ex.Message}");
        }
Esempio n. 6
0
 private BirthDocResponse(bool success, string message, BirthDoc birthDoc) : base(success, message)
     => BirthDoc = birthDoc;
Esempio n. 7
0
 public async Task CreateBirthDoc(BirthDoc birthDoc)
 {
     await _dbContext.BirthDocs.AddAsync(birthDoc);
 }
Esempio n. 8
0
        private async Task SetDefaultStateId(BirthDoc birthDoc)
        {
            var defaultState = await _lookupsService.FindWhere <State>(a => a.Code == "NEW");

            birthDoc.StateId = defaultState?.Id;
        }