Exemple #1
0
        public async Task CreateOrUpdateSexInfo(SexInfoCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdateSexInfoAsync(input);
            }
            else
            {
                await CreateSexInfoAsync(input);
            }
        }
Exemple #2
0
        private async Task CheckValidation(SexInfoCreateOrUpdateInput input)
        {
            var existingObj = (await _sexInfoRepository.GetAll().AsNoTracking()
                               .FirstOrDefaultAsync(l => l.Code == input.Code));

            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisCodeAlreadyExists"));
            }

            existingObj = (await _sexInfoRepository.GetAll().AsNoTracking()
                           .FirstOrDefaultAsync(l => l.Name == input.Name));
            if (existingObj != null && existingObj.Id != input.Id)
            {
                throw new UserFriendlyException(L("ThisNameAlreadyExists"));
            }
        }
Exemple #3
0
        public async Task <SexInfoCreateOrUpdateInput> GetSexInfoForEdit(NullableIdDto <int> input)
        {
            //Getting all available roles
            var output = new SexInfoCreateOrUpdateInput();

            if (input.Id.HasValue)
            {
                //Editing an existing user
                var sexInfo = await _sexInfoRepository.GetAsync(input.Id.Value);

                if (sexInfo != null)
                {
                    ObjectMapper.Map <SexInfo, SexInfoCreateOrUpdateInput>(sexInfo, output);
                }
            }

            return(output);
        }
Exemple #4
0
 private async Task UpdateSexInfoAsync(SexInfoCreateOrUpdateInput input)
 {
     var sexInfo = ObjectMapper.Map <SexInfo>(input);
     await _sexInfoRepository.UpdateAsync(sexInfo);
 }