DocSas/PropertyService.Domain/ModelView/Secures/CodeGeneratorProvider..cs
/// <summary>
/// generate code as an asynchronous operation.
/// </summary>
/// <param name="cType">Type of the c.</param>
/// <returns>Task&lt;DSCResponse&gt;.</returns>
generate code as an asynchronous operation.
generate code as an asynchronous operation .
public async  Task<DSCResponse> GenerateCodeAsync(DSCCodeType cType)
        {
            var response = new DSCResponse();
            var msg = new Dictionary<string, string>();
            var serviceTrack = await _serviceTrackRepo.GetSingleAsync(x => x.CodeType.Equals(cType.ToString(), StringComparison.OrdinalIgnoreCase));
            var result = string.Empty;
            if (serviceTrack != null)
            {
                var letters = serviceTrack.AvailableLetters;
                var lettersLength = serviceTrack.LettersLength;
                var start = serviceTrack.StartValue;
                var max = serviceTrack.MaxInd;
                Enum.TryParse(serviceTrack.NumberPosition, out DSCPosition numPosition);
                for (int i = 0; i < lettersLength; i++)
                {
                    Random rnd = new Random();
                    var index = rnd.Next(letters.Length);
                    result += letters[index];
                }
                switch (numPosition)
                {
                    case DSCPosition.Right:
                        result = string.Concat(result, max);
                        break;
                    case DSCPosition.Left:
                        result = string.Concat(max, result);
                        break;
                }
                serviceTrack.MaxInd++;
                var success = await _serviceTrackRepo.ModifyAsync(serviceTrack);
                if (!success)
                {
                    msg.Add("SomethingWrong", "Something went wrong");
                }
            }
            response.ResponseData = result;
            response.ErrorMessage = msg;
            return response;
        }
public async Task < DSCResponse > GenerateCodeAsync ( DSCCodeType cType ) { var response = new DSCResponse ( ) ; var msg = new Dictionary < string , string > ( ) ; var serviceTrack = await _serviceTrackRepo . GetSingleAsync ( x => x . CodeType . Equals ( cType . ToString ( ) , StringComparison . OrdinalIgnoreCase ) ) ; var result = string . Empty ; if ( serviceTrack != null ) { var letters = serviceTrack . AvailableLetters ; var lettersLength = serviceTrack . LettersLength ; var start = serviceTrack . StartValue ; var max = serviceTrack . MaxInd ; Enum . TryParse ( serviceTrack . NumberPosition , out DSCPosition numPosition ) ; for ( int i = 0 ; i < lettersLength ; i ++ ) { Random rnd = new Random ( ) ; var index = rnd . Next ( letters . Length ) ; result += letters [ index ] ; } switch ( numPosition ) { case DSCPosition . Right : result = string . Concat ( result , max ) ; break ; case DSCPosition . Left : result = string . Concat ( max , result ) ; break ; } serviceTrack . MaxInd ++ ; var success = await _serviceTrackRepo . ModifyAsync ( serviceTrack ) ; if ( ! success ) { msg . Add ( " " , " " ) ; } } response . ResponseData = result ; response . ErrorMessage = msg ; return response ; }
generate code as an asynchronous operation.
generate code as an asynchronous operation .
None
cType
DSCCodeType
Type of the c.
Type of the c .