Ejemplo n.º 1
0
		public async Task<ActionResult<GenericResponse>> RenamePost(string botName, [FromBody] BotRenameRequest request) {
			if (string.IsNullOrEmpty(botName) || (request == null)) {
				ASF.ArchiLogger.LogNullError(nameof(botName) + " || " + nameof(request));

				return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsEmpty, nameof(botName) + " || " + nameof(request))));
			}

			if (string.IsNullOrEmpty(request.NewName) || request.NewName.Equals(SharedInfo.ASF) || Bot.Bots.ContainsKey(request.NewName)) {
				return BadRequest(new GenericResponse(false, string.Format(Strings.ErrorIsInvalid, nameof(request.NewName))));
			}

			if (!Bot.Bots.TryGetValue(botName, out Bot bot)) {
				return BadRequest(new GenericResponse(false, string.Format(Strings.BotNotFound, botName)));
			}

			bool result = await bot.Rename(request.NewName).ConfigureAwait(false);

			return Ok(new GenericResponse(result));
		}
Ejemplo n.º 2
0
        public async Task <ActionResult <GenericResponse> > RenamePost(string botName, [FromBody] BotRenameRequest request)
        {
            if (string.IsNullOrEmpty(botName))
            {
                throw new ArgumentNullException(nameof(botName));
            }

            if (request == null)
            {
                throw new ArgumentNullException(nameof(request));
            }

            if (Bot.Bots == null)
            {
                throw new InvalidOperationException(nameof(Bot.Bots));
            }

            if (string.IsNullOrEmpty(request.NewName) || !ASF.IsValidBotName(request.NewName !) || Bot.Bots.ContainsKey(request.NewName !))
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.ErrorIsInvalid, nameof(request.NewName)))));
            }

            if (!Bot.Bots.TryGetValue(botName, out Bot? bot))
            {
                return(BadRequest(new GenericResponse(false, string.Format(CultureInfo.CurrentCulture, Strings.BotNotFound, botName))));
            }

            bool result = await bot.Rename(request.NewName !).ConfigureAwait(false);

            return(Ok(new GenericResponse(result)));
        }