sources/src/Monetco.Host/Controllers/SimulatorController.cs
/// <summary>
/// Import responses from json array and replace for current ID
/// </summary>
/// <remarks>String must be in json format</remarks>
/// <param name="id">User ID from path</param>
/// <param name="value">Json string to import</param>
/// <response code="412">Wrong value format</response>
/// <response code="201">Responses were success imported</response>
/// <returns>Status code 201</returns>
Import responses from json array and replace for current ID
Import responses from json array and replace for current ID
[HttpPost("{id}/replace")]
        public IActionResult Replace([FromRoute]string id, [FromBody]List<SimulatorResponse> value)
        {
            if (value.Any(val => val.Scope.Name == "config"))
            {
                var configs = value.First(val => val.Scope.Name == "config").Content;
                var values = JsonConvert.DeserializeObject<Dictionary<string, string>>(configs);
                values.Add("{ss.guid}", Guid.NewGuid().ToString());
                values.Add("{ss.timestamp}", DateTimeOffset.Now.ToUnixTimeSeconds().ToString());
                values.Add("{ss.id}", id);
                value.FindAll(vals => vals.Scope.Name != "config").ForEach(el =>
                {
                    foreach(var item in values)
                    {
                        el.Content = el.Content.Replace(item.Key, item.Value);
                    }                
                });
            }
            value.ForEach(s => { s.Scope = Scopes.GetScopeFromName(s.Scope.Name);});
            if (_service.GetNewResponses().ContainsKey(id))
            {
                _service.GetNewResponses()[id] = value;
            } else
            {
                _service.GetNewResponses().Add(id, value);
            }
            return StatusCode(201);
        }
[ HttpPost ( " " ) ] public IActionResult Replace ( [ FromRoute ] string id , [ FromBody ] List < SimulatorResponse > value ) { if ( value . Any ( val => val . Scope . Name == " " ) ) { var configs = value . First ( val => val . Scope . Name == " " ) . Content ; var values = JsonConvert . DeserializeObject < Dictionary < string , string > > ( configs ) ; values . Add ( " " , Guid . NewGuid ( ) . ToString ( ) ) ; values . Add ( " " , DateTimeOffset . Now . ToUnixTimeSeconds ( ) . ToString ( ) ) ; values . Add ( " " , id ) ; value . FindAll ( vals => vals . Scope . Name != " " ) . ForEach ( el => { foreach ( var item in values ) { el . Content = el . Content . Replace ( item . Key , item . Value ) ; } } ) ; } value . ForEach ( s => { s . Scope = Scopes . GetScopeFromName ( s . Scope . Name ) ; } ) ; if ( _service . GetNewResponses ( ) . ContainsKey ( id ) ) { _service . GetNewResponses ( ) [ id ] = value ; } else { _service . GetNewResponses ( ) . Add ( id , value ) ; } return StatusCode ( 201 ) ; }
Import responses from json array and replace for current ID
Import responses from json array and replace for current ID
Status code 201
Status code 201
string
[FromRoute]
List<SimulatorResponse>
[FromBody]
id
User ID from path
User ID from path
value
Json string to import
Json string to import
remarks
String must be in json format
String must be in json format
response
Wrong value format
Wrong value format
response
Responses were success imported
Responses were success imported