예제 #1
0
        public async Task <PersonsModel> AddRelatedPersonAsync(int personId, PersonTypesModel personTypeModel, int relativePersonId)
        {
            var person = await _context.Persons.
                         FirstOrDefaultAsync(e => e.PersonId == personId);

            await SaveRelatedPerson(personId, personTypeModel, relativePersonId);

            var result = await GetPersonByIdAsync(personId);

            return(result);
        }
예제 #2
0
        public async Task <IActionResult> CreateRelativePersonAsync(int personId, PersonTypesModel personTypeModel, int relativePersonId)
        {
            if (_relatedPersonServices.checkIfRelatedPersonExist(personId, relativePersonId))
            {
                var model = await _relatedPersonServices.AddRelatedPersonAsync(personId, personTypeModel, relativePersonId);

                var location = _linkGanarator.GetPathByAction("GetPersonByIdAsync", "Persons", new { personId = model.PersonId });
                return(Created(location, model));
            }
            else
            {
                return(BadRequest("Related person already added"));
            }
        }
예제 #3
0
        private async Task SaveRelatedPerson(int personId, PersonTypesModel personTypeModel, int relativePersonId)
        {
            //var result = Mapping.Mapper.Map<PersonTypes>(personTypeModel);
            var result = new PersonTypes()
            {
                TypeName = personTypeModel.TypeName
            };
            await _context.PersonTypes.AddAsync(result);

            await _context.SaveChangesAsync();

            await _context.RelatedPersons.AddAsync(
                new RelatedPersons
            {
                RelatedPersonId = relativePersonId,
                PersonId        = personId,
                PersonTypeId    = result.PersonTypeId
            });

            await _context.SaveChangesAsync();
        }