public async Task <ActionResult <AliasDetailsView> > Post([FromBody] NewAlias newAlias) { var username = User.Identity.Name; var dbAlias = await _repository.Post(username, newAlias.AliasName); if (dbAlias == null) { return(BadRequest()); } return(CreatedAtAction(nameof(GetById), new { id = dbAlias.Id }, dbAlias)); }
public static void Alias(Statement statement) { switch (statement.Blocks.Length) { case 1: Program.Print(ConsoleColor.Magenta, "Aliases: command ~ alias ", ""); if (AliasFunc.Count == 0) { Program.Print(ConsoleColor.Blue, "Upset aliases"); } else { foreach (var item in AliasFunc) { Program.Print(ConsoleColor.Yellow, $"{item.Key} ~ {item.Value}"); } } break; case 2 when statement.Params != null && statement.Property == null: var helpAttrs = Attributes["help"]; foreach (var attr in statement.Params) { if (attr == helpAttrs["help"]) { HelpOf(statement); } else { Program.Print(ConsoleColor.Red, $"This '{attr}' parametr is not correct, use {statement.Command} /{Attributes["alias"]["help"]}"); break; } } break; case 3 when statement.Params != null && statement.Property != null: List <char> list = new List <char> { }; var aliasAttrs = Attributes["alias"]; foreach (var attr in statement.Params) { if (attr == aliasAttrs["help"] && !list.Contains(attr)) { list.Add(attr); HelpOf(statement); } else if (attr == aliasAttrs["add"] && !list.Contains(attr)) { list.Add(attr); foreach (var item in statement.Property) { if (TryAddAlias(item.Key, item.Value, statement.Params.ToArray().Contains(aliasAttrs["force"]))) { Program.Print(ConsoleColor.Blue, $"Alias successful added '{statement.Command} {item.Key}:{item.Value} /{attr}'"); } else { Program.Print(ConsoleColor.Red, $"The request to add was canceled -> '{statement.Command} {item.Key}:{item.Value} /{attr}'"); } } } else if (attr == aliasAttrs["remove"] && !list.Contains(attr)) { list.Add(attr); foreach (var item in statement.Property) { if (TryRemoveAlias(item.Key, statement.Params.ToArray().Contains(aliasAttrs["force"]))) { Program.Print(ConsoleColor.Blue, $"Alias successful removed '{statement.Command} {item.Key}:{item.Value} /{attr}'"); } else { Program.Print(ConsoleColor.Red, $"The removal request was canceled '{statement.Command} {item.Key}:{item.Value} /{attr}'"); } } } else if (attr == aliasAttrs["force"] && !list.Contains(attr)) { list.Add(attr); continue; } else if (list.Contains(attr)) { Program.Print(ConsoleColor.Red, $"This '{attr}' has done"); goto fin; } else { Program.Print(ConsoleColor.Red, $"This '{attr}' parametr is not correct"); goto fin; } } break; default: Program.Print(ConsoleColor.Red, $"Invalid using command: '{statement.Command}', -> '{statement.String}'"); break; } fin: Go(); bool TryAddAlias(string key, string value, bool force = false) { if (!CmdFunc.Keys.Contains(key)) { Program.Print(ConsoleColor.Red, $"Command: '{key}' is not found"); return(false); } else if (AliasFunc.ContainsKey(key) && !force) { Program.Print(ConsoleColor.Red, $"Command: '{key}' already has alias"); return(false); } else if (AliasFunc.ContainsValue(value) && !force) { Program.Print(ConsoleColor.Red, $"Alias: '{value}' is not availble"); return(false); } else if (force) { if (AliasFunc.ContainsKey(key)) { AliasFunc.Remove(key); } if (AliasFunc.ContainsValue(value)) { foreach (var item in AliasFunc) { if (item.Value == value) { AliasFunc.Remove(item.Key); } } } } AliasFunc.Add(key, value); if (!NewAlias.ContainsKey(key)) { NewAlias.Add(key, value); } return(true); } bool TryRemoveAlias(string key, bool force = false) { if (!CmdFunc.Keys.Contains(key)) { Program.Print(ConsoleColor.Red, $"Command: '{key}' is not found"); return(false); } else if (force) { bool isRm = AliasFunc.Remove(key); if (isRm && !NewAlias.ContainsKey(key)) { NewAlias.Add(key, ""); } return(isRm); } else { string answer = Prompt(color: ConsoleColor.DarkGreen, txt: "Are you sure complite process [ 'y' | 'n' ]").Trim(); if ("y" == answer) { bool isRm = AliasFunc.Remove(key); if (isRm && !NewAlias.ContainsKey(key)) { NewAlias.Add(key, ""); } return(isRm); } else if ("n" == answer) { return(false); } else { Program.Print(color: ConsoleColor.Red, txt: $"Invalid argument: {answer} "); return(false); } } } }