HashSet<string> test= new()
{
"Service Medal",
"Loyalty Badge",
"Gold Operation",
"Silver Operation",
"Diamond Operation",
"Coin"
};
var descriptions = obj!["descriptions"]!.ToList();
Console.OutputEncoding = Encoding.UTF8;
foreach (var item in descriptions)
{
Console.WriteLine(item["values"]!.ToString().Where(x=> !test.Contains(<b>x</b>)));
}
private async Task BotOnMessageReceived(Message message)
{
_logger.LogInformation("Receive message type: {MessageType}", message.Type);
if (message.Type != MessageType.Text)
await _botClient.SendTextMessageAsync(message.Chat.Id, "Send only text commands!");
var action = message.Text!.Split(' ')[0] switch
{
"/start" => StartMessageService.StartCommand(_botClient, message),
"/help" => HelpMessageService.HelpCommand(_botClient, message),
"/add" => AddAccountService.AddCommand(_botClient, message),
"/parse" => ParseCommandService.ParseCommand(_botClient, message),
"/show" => ShowCommandService.ShowCommand(_botClient, message),
_ => BackToMainMenuService.BackToMainMenu(_botClient, message)
};
Message sentMessage = await action;
_logger.LogInformation("The message was sent with id: {SentMessageId}", sentMessage.MessageId);
}
public class StartMessageService
{
public static async Task<Message> StartCommand(ITelegramBotClient bot, Message message)
{
return await bot.SendTextMessageAsync(message.Chat.Id, "Welcome txt here");
}
}
public class AddAccountService
{
public static async Task<Message> AddCommand(ITelegramBotClient bot, Message message)
{
if(message.Text.Count(char.IsWhiteSpace) == 1)
{
string[] getData = message.Text.Split(" ");
var user = new UserInformation
{
TelegramUserId = message.Chat.Id.ToString()
};
user.Accounts.Add(new Account
{
SteamId = getData[1]
});
return await bot.SendTextMessageAsync(message.Chat.Id, "Saved");
}
return await bot.SendTextMessageAsync(message.Chat.Id, "Wrong command. Please, keep order of the commands.");
}
}
public static async Task<Message> AddCommand(ITelegramBotClient bot, Message message, dbContext context)
запись в таблице бд не появляется. Помогите, пожалуйста. CreateMap<User, ForUserDataDto>()
.ForMember(s => s.TelegramUserId, opt => opt.MapFrom(r => r.TelegramId))
.ForMember(x => x.Steam, v => v.MapFrom(t => t.Accounts.Select(a => new Steam { SteamId = a.SteamId })));
[HttpGet]
public async Task<ForUserDataDto> GetUsers()
{
var t = await _context.Users.Include(s => s.Accounts).ToListAsync();
var p = _mapper.Map<List<ForUserDataDto>>(t);
return p;
}
AutoMapper.AutoMapperMappingException: Missing type map configuration or unsupported mapping.
Mapping types:
List`1 -> ForUserDataDto
System.Collections.Generic.List`1[[azuresqltest.User, azuresqltest, Version=1.0.0.0, Culture=neutral, PublicKeyToken=null]] -> azuresqltest.Mapping.ForUserDataDto
at lambda_method61(Closure , Object , ForUserDataDto , ResolutionContext )
at azuresqltest.Controllers.GetUsersController.GetUsers() in C:\Users\Oybek\source\repos\azuresqltest\azuresqltest\Controllers\GetUsersController.cs:line 34
at lambda_method5(Closure , Object )
at Microsoft.AspNetCore.Mvc.Infrastructure.ActionMethodExecutor.AwaitableObjectResultExecutor.Execute(IActionResultTypeMapper mapper, ObjectMethodExecutor executor, Object controller, Object[] arguments)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeActionMethodAsync>g__Awaited|12_0(ControllerActionInvoker invoker, ValueTask`1 actionResultValueTask)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeNextActionFilterAsync>g__Awaited|10_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Rethrow(ActionExecutedContextSealed context)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.Next(State& next, Scope& scope, Object& state, Boolean& isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ControllerActionInvoker.<InvokeInnerFilterAsync>g__Awaited|13_0(ControllerActionInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeFilterPipelineAsync>g__Awaited|20_0(ResourceInvoker invoker, Task lastTask, State next, Scope scope, Object state, Boolean isCompleted)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Mvc.Infrastructure.ResourceInvoker.<InvokeAsync>g__Awaited|17_0(ResourceInvoker invoker, Task task, IDisposable scope)
at Microsoft.AspNetCore.Routing.EndpointMiddleware.<Invoke>g__AwaitRequestTask|6_0(Endpoint endpoint, Task requestTask, ILogger logger)
at Microsoft.AspNetCore.Authorization.AuthorizationMiddleware.Invoke(HttpContext context)
at Swashbuckle.AspNetCore.SwaggerUI.SwaggerUIMiddleware.Invoke(HttpContext httpContext)
at Swashbuckle.AspNetCore.Swagger.SwaggerMiddleware.Invoke(HttpContext httpContext, ISwaggerProvider swaggerProvider)
at Microsoft.AspNetCore.Diagnostics.DeveloperExceptionPageMiddleware.Invoke(HttpContext context)
return await _context.Users.Include(s => s.Accounts).ToListAsync();
вообще вот эта команда корректна написана ?? Она же должна выдать все данные включая и Accounts ?? что у тебя за клиент - отдать ему его ссылку.Session? Посоветуйте, плиз.
Метод, который бы обрабатывал запрос с формой я не вижу у тебя.
public IActionResult OnGet(string url)
{
Link link = _db.Links.FirstOrDefault(s => s.ShortedUrl == url);
if (link != null)
{
return Redirect(link.Url);
}
else
{
return Redirect(_configuration.GetSection("Link:ShortUrl").Value);
}
}
public IActionResult OnPost(string userLink) //Добавить страховку если не ввели ссылку
{
Random random = new Random(); //постоянно создается, сделать так чтобы один раз и vсе
string name = new string(Enumerable.Repeat(range, 6).Select(s => s[random.Next(s.Length)]).ToArray());
Link link = new Link
{
Url = userLink,
ShortedUrl = name
};
_db.Links.Add(link);
_db.SaveChanges();
//return RedirectToPage("Result", new { Result = name });
return RedirectToPage("Result" );
}
public class ResultModel : PageModel
{
public string Message { get; private set; } = "";
public string Result { get; set; }
private readonly IConfiguration _configuration;
private readonly IHttpContextAccessor _http;
public ResultModel(IConfiguration configuration, IHttpContextAccessor http)
{
_configuration = configuration;
_http = http;
}
public void OnGet(/*string Result*/)
{
var request = _http.HttpContext.Request;
request.ContentType = "text/html; charset=utf-8";
var form = request.Form;
string l = form["userLink"];
Message = _configuration.GetSection("Linklar:Value").Value + l;
}
public class ResultModel : PageModel
{
public string Message { get; private set; } = "";
public string Result { get; set; }
private readonly IConfiguration _configuration;
private readonly IHttpContextAccessor _http;
public ResultModel(IConfiguration configuration, IHttpContextAccessor http)
{
_configuration = configuration;
_http = http;
}
public void OnGet()
{
var request = _http.HttpContext.Request;
request.ContentType = "text/html; charset=utf-8";
var form = request.Form;
string l = form["userLink"];
Message = _configuration.GetSection("Linklar:Value").Value + l;
}
}
в данном случае смотрите, получаю переменную типа стринг со значением test, заходит внутрь блока if, а потом он идет дальше, а я хочу чтобы он внутри блока if остановился и принял следующие данные с шины, но никак не могу разобраться как это сделать, помогите пожалуйста