public IActionResult Login(UserModel um) { var users = userService.GetAllUsers(); foreach (var user in users) { if (um.Login == user.Login) { if (um.Password == user.Password) { activeUser = user; var data = Encoding.UTF8.GetBytes($"{um.Login},{um.Password}"); this.HttpContext.Session.Set("user", data); } } } if (activeUser != null) { um = activeUser; } if (ModelState.IsValid) { return(RedirectToAction("Index", "Home")); } return(Login()); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); _settings = _appSettings !.Value; var errors = new List <string>(); MainLayout !.CloseMenu(); _user = await _authenticationService !.LoggedInUserAsync(); if (string.IsNullOrWhiteSpace(OfferIdString) || !int.TryParse(OfferIdString, out var offerid) || offerid <= 0) { errors.Add(string.Format(Strings.Invalid, "offer id")); } else { _offer = await _offerService !.ReadAsync(offerid); if (_offer is not null) { _quantity = _offer.Quantity; } else { errors.Add(string.Format(Strings.NotFound, "offer", "id", offerid)); } } _errors = errors.ToArray(); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = await _authenticationService !.LoggedInUserAsync(); _oldestFirst = _settings !.Value.OldestFirst; var beans = (await _beanService !.GetAsync()).ToList(); _beans = new(); foreach (var bean in beans) { var model = new SellBeanModel { Id = bean.Id, Name = bean.Name, Price = bean.Price, MyHoldings = await _holdingService !.BeansHeldByUserAndBeanAsync(_user !.Id, bean.Id), Selected = false }; _beans.Add(model); } _selectedBean = _beans.FirstOrDefault(); await LoadHoldings(); _quantity = 0; _price = 0M; _days = 30; StateHasChanged(); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = (await _authenticationService !.LoggedInUserAsync()) !; await LoadNotices(_user?.Id ?? 0); }
public IActionResult Logout() { activeUser = null; var data = Encoding.UTF8.GetBytes(""); this.HttpContext.Session.Set("user", data); return(RedirectToAction("Login", "Home")); }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = await _authenticationService !.LoggedInUserAsync(); _settings = await _settingsService !.SettingsAsync(); }
public async Task TempBan( CommandContext ctx, DiscordMember user, string duration, [RemainingText] string reason = "Not provided.") { SilkDbContext db = DbFactory.CreateDbContext(); DiscordMember bot = ctx.Guild.CurrentMember; DateTime now = DateTime.Now; TimeSpan banDuration = GetTimeFromInput(duration); BanFailureReason? banFailed = CanBan(bot, ctx.Member, user); DiscordEmbedBuilder embed = new DiscordEmbedBuilder().WithAuthor(bot.Username, ctx.GetBotUrl(), ctx.Client.CurrentUser.AvatarUrl); if (banFailed is not null) { await SendFailureMessage(ctx, user, embed, banFailed); } else { DiscordEmbedBuilder banEmbed = new DiscordEmbedBuilder() .WithAuthor(ctx.User.Username, ctx.User.GetUrl(), ctx.User.AvatarUrl) .WithDescription($"You've been temporarily banned from {ctx.Guild.Name} for {duration} days.") .AddField("Reason:", reason); await user.SendMessageAsync(embed : banEmbed); await ctx.Guild.BanMemberAsync(user, 0, reason); GuildModel guild = db.Guilds.First(g => g.Id == ctx.Guild.Id); UserModel?bannedUser = db.Users.FirstOrDefault(u => u.Id == user.Id); string formattedBanReason = InfractionFormatHandler.ParseInfractionFormat("temporarily banned", banDuration.TotalDays + " days", user.Mention, reason, guild.Configuration.InfractionFormat ?? defaultFormat); UserInfractionModel infraction = CreateInfraction(formattedBanReason, ctx.User.Id, now); if (bannedUser is null) { bannedUser = new UserModel { Infractions = new List <UserInfractionModel>() }; db.Users.Add(bannedUser); bannedUser.Infractions.Add(infraction); } if (guild.Configuration.GeneralLoggingChannel != default) { embed.WithDescription(formattedBanReason); embed.WithColor(DiscordColor.Green); await ctx.Guild.GetChannel(guild.Configuration.GeneralLoggingChannel).SendMessageAsync(embed: embed); } EventService.Events.Add(new TimedInfraction(user.Id, ctx.Guild.Id, DateTime.Now.Add(banDuration), reason, e => _ = OnBanExpiration((TimedInfraction)e))); } }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = await _authenticationService !.LoggedInUserAsync(); await LoadBeans(); await LoadHoldings(); StateHasChanged(); }
public OrderModel( int id, OrderStatusModel status, DateTime orderTime, MarketplaceItemModel itemId, UserModel?recipient ) : base(id, status, orderTime) { Recipient = recipient; Item = itemId; }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = (await _authenticationService !.LoggedInUserAsync()) !; await LoadMyOffers(_user.Id); _offers = (await _offerService !.GetOtherOffersAsync(_user.Id)).ToList(); _mySales = (await _saleService !.GetForUserAsync(_user.Id)).ToList(); StateHasChanged(); }
private async Task BuyClick(bool small, int id) { _errors = Array.Empty <string>(); var errors = new List <string>(); if (id > 0) { var inputname = IdCreator(small ? _smallBuyQuantity : _largeBuyQuantity, id); var quantitystring = await _jSRuntime !.InvokeAsync <string>("beans.getValue", inputname); if (string.IsNullOrWhiteSpace(quantitystring) || !long.TryParse(quantitystring, out var quantity) || quantity <= 0) { errors.Add(string.Format(Strings.Invalid, "quantity")); } else { var bean = _beans !.SingleOrDefault(x => x.Id == id); if (bean is null) { errors.Add(String.Format(Strings.NotFound, "bean", "id", id)); } else { if (quantity > bean.Outstanding) { errors.Add(string.Format(Strings.NotEnoughBeans, bean.Name)); } else if (quantity * bean.Price > _user !.Balance) { errors.Add(string.Format(Strings.NSF, bean.Name, bean.Price.ToCurrency(2))); } else { var result = await _beanService !.BuyFromExchangeAsync(_user.Id, id, quantity); if (result.Successful) { await _jSRuntime !.InvokeVoidAsync("beans.clearValue", inputname); var parameters = new DialogParameters { { "Title", "Purchase Complete" }, { "Message", string.Format(Strings.PurchaseComplete, quantity, bean.Name) } }; await _dialogService !.Show <GenericDialog>(string.Empty, parameters).Result; _user = await _authenticationService !.LoggedInUserAsync(); await LoadBeans(); await LoadHoldings(); } else { errors.AddRange(result.Errors()); } } }
public OfferModel() : base() { Id = 0; UserId = 0; BeanId = 0; Quantity = 0; Price = 0M; Buy = false; OfferDate = default; ExpirationDate = default; Bean = null; User = null; }
public async Task Cases(CommandContext ctx, DiscordUser user) { var mBuilder = new DiscordMessageBuilder(); var eBuilder = new DiscordEmbedBuilder(); UserModel?userModel = await _dbService.GetGuildUserAsync(ctx.Guild.Id, user.Id); if (userModel is null || !userModel.Infractions.Any()) { mBuilder.WithReply(ctx.Message.Id); mBuilder.WithContent("User has no cases!"); await ctx.RespondAsync(mBuilder); } }
protected async override Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = await _authenticationService !.LoggedInUserAsync() !; _holdingDictionary = new(); _beans = new(); var beanids = (await _beanService !.BeanIdsAsync()).OrderBy(x => x).ToList(); if (beanids is not null && beanids.Any()) { foreach (var id in beanids) { _beans.Add((await _beanService !.ReadAsync(id)) !); var holdings = (await _holdingService !.GetForBeanAsync(_user !.Id, id)).ToList(); if (holdings is not null && holdings.Any()) { _holdingDictionary.Add(id, holdings); } } } if (string.IsNullOrWhiteSpace(BeanIdString) || !int.TryParse(BeanIdString, out var beanid) || beanid <= 0) { beanid = _holdingDictionary.Keys.First(); } _currentBean = beanid; _currentBeanName = _beans.Single(x => x.Id == _currentBean).Name; if (_holdingDictionary.ContainsKey(beanid)) { _holdings = _holdingDictionary[beanid]; } else { _holdings = _holdingDictionary.Any() ? _holdingDictionary[_holdingDictionary.Keys.First()] : new(); } }
protected override async Task OnInitializedAsync() { await base.OnInitializedAsync(); MainLayout !.CloseMenu(); _user = (await _authenticationService !.LoggedInUserAsync()) !; _holdings = new(); var beans = await _beanService !.GetAsync(); foreach (var bean in beans) { var holdings = await _holdingService !.GetForBeanAsync(_user.Id, bean.Id); if (holdings.Any()) { _holdings.Add(new(bean, holdings)); } } _offers = (await _offerService !.GetForUserAsync(_user.Id)).ToList(); _sales = (await _saleService !.GetForUserAsync(_user.Id, _days)).ToList(); _holdingsValue = await _holdingService !.TotalValueAsync(_user.Id); _holdingsCost = await _holdingService !.TotalCostAsync(_user.Id); _return = _holdingsValue - _holdingsCost; _returnPercent = _holdingsCost == 0M ? 0.0 : (double)(_return / _holdingsCost); }
public async Task <IActionResult> GetAsync(int userId) { UserModel?res = await UserTable.GetUserById(_dbConnection, userId); return(res == null?NotFound() : (IActionResult)Ok(res)); }
public bool Equals(UserModel?model) => model is not null && model.Id == Id;
public int CompareTo(UserModel?other) => Email.CompareTo(other?.Email);