public async Task CreateOrUpdateActivityInfo(ActivityInfoCreateOrUpdateInput input)
        {
            await CheckValidation(input);

            if (input.Id.HasValue)
            {
                await UpdateActivityInfoAsync(input);
            }
            else
            {
                await CreateActivityInfoAsync(input);
            }
        }
        private async Task CheckValidation(ActivityInfoCreateOrUpdateInput input)
        {
            var existingObj = (await _activityInfoRepository.GetAll().AsNoTracking()
                               .FirstOrDefaultAsync(l => l.Code == input.Code));

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

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

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

                if (activityInfo != null)
                {
                    ObjectMapper.Map <ActivityInfo, ActivityInfoCreateOrUpdateInput>(activityInfo, output);
                }
            }

            return(output);
        }
 private async Task UpdateActivityInfoAsync(ActivityInfoCreateOrUpdateInput input)
 {
     var activityInfo = ObjectMapper.Map <ActivityInfo>(input);
     await _activityInfoRepository.UpdateAsync(activityInfo);
 }