public Task <ShopperProfileResponse> Handle(CreateShopperRequest request, CancellationToken cancellationToken) { var isUserExists = _dbContext.Shoppers.Where(shopper => shopper.Username.Equals(request.Username)).Any(); if (isUserExists) { throw new DuplicateUsernameException(); } var id = _idGenerator.CreateId(); var wishListId = _idGenerator.CreateId(); var createdDateTime = _clock.UtcNow; var newShopper = new Shopper(id, request.Username, wishListId); _dbContext.Shoppers.Add(newShopper); var wishList = new WishList(wishListId, id); _dbContext.WishLists.Add(wishList); _dbContext.SaveChanges(); var shopperProfile = new ShopperProfileResponse(); shopperProfile.Username = request.Username; shopperProfile.WishList = wishList; shopperProfile.ShoppingLists = new List <KeyValuePair <long, string> >(); return(Task.FromResult(shopperProfile)); }
public async Task DetermineAllItemsAsync(CancellationToken cancellationToken = default) { var restrictions = await _context.ItemRestrictions.ToListAsync(cancellationToken); var restrictionsToKeep = new HashSet <long>(); await foreach (var item in _context.Items.AsAsyncEnumerable().WithCancellation(cancellationToken)) { foreach (var rule in _rules) { foreach (var restriction in rule.GetDeterminations(item) .Where(d => d.Level != DeterminationLevel.Allowed) .GroupBy(d => new { d.Reason, d.Level }) .Select(g => new ItemRestriction(_idGenerator.CreateId()) { Automated = true, Item = item, ItemId = item.Id, Reason = g.Key.Reason, RestrictionLevel = g.Key.Level switch { DeterminationLevel.ManualReview => ItemRestrictionLevel.ManualReview, DeterminationLevel.Disallowed => ItemRestrictionLevel.Restricted, DeterminationLevel.Unequippable => ItemRestrictionLevel.Unequippable, _ => throw new Exception("Unexpected determination level was returned by a rule.") },
public async Task <object> LogMany([FromBody] List <object> records) { //Task.Run(() => //{ // logger.LogInformation("records count: {0}", records.Count); // var data = records.Select(i => // { // return new MainLogRecord // { // Content = JsonSerializer.Serialize(i), // CreateAt = DateTime.Now, // }; // }); // rm.RecordMany("bbb", data); //}); await queue.EnqueueAsync(records.Select(i => { // Random random = new Random(); return(new MainLogRecord { Id = idGenerator.CreateId(), Content = JsonSerializer.Serialize(i), // CreateAt = DateTime.Now.AddDays(random.NextInt64(-10, 10)), CreateAt = DateTime.Now, }); })); return(new { Code = 0, Message = "写入成功", }); }
public async Task <bool> Handle(RegisterNewUserWithoutPassCommand request, CancellationToken cancellationToken) { if (!request.IsValid()) { NotifyValidationErrors(request); return(false); } var user = new ApplicationUser { Id = Guid.NewGuid(), Email = request.Email, UserName = request.UserName, PhoneNumber = request.PhoneNumber, Uid = _idGenerator.CreateId() }; if (!string.IsNullOrEmpty(user.Email)) { var emailAlreadyExist = await _userManager.FindByEmailAsync(user.Email); if (emailAlreadyExist != null) { await _bus.RaiseEvent(new DomainNotification("email_already_existed", "E-mail already exist. If you don't remember your passwork, reset it.")); return(false); } } var usernameAlreadyExist = await _userManager.FindByNameAsync(user.UserName); if (usernameAlreadyExist != null) { await _bus.RaiseEvent(new DomainNotification("username_already_existed", "Username already exist. If you don't remember your passwork, reset it.")); return(false); } var id = await CreateUserWithProvider(user, request.Provider, request.ProviderId); if (id.HasValue) { await _bus.RaiseEvent(new UserRegisteredEvent(id.Value.ToString(), user.UserName, user.Email)); return(true); } return(false); }
public IActionResult Avatar() { var image = _drawing.Generate(200, 200); image.Seek(0, System.IO.SeekOrigin.Begin); var id = _id.CreateId(); return(File(image, "image/jpeg", $"{id}.jpeg")); }
public async Task <long> AddOrUpdate(ToDo dto) { if (dto.Id == default) { dto.Id = _idGen.CreateId(); } Console.WriteLine($"AddOrUpdate id {dto.Id} parentId {dto.ParentId} summary {dto.Summary}"); _data.AddOrUpdate(dto, ToDo.ToDoComparer); await SaveLocalStorage(); return(dto.Id); }
public async Task <IActionResult> Post([FromBody] DonationSubmissionDto dto) { var donatedAt = _serverTimeZone.TimeZoneNow(); var character = await _context.Characters.FindAsync(dto.CharacterId); if (character is null) { return(NotFound()); } if (!character.TeamId.HasValue) { return(Problem("Donations can only be applied to characters on a raid team.")); } var authResult = await _authorizationService.AuthorizeAsync(User, character.TeamId.Value, AppPolicies.LootMasterOrAdmin); if (!authResult.Succeeded) { return(Unauthorized()); } if (dto.ApplyThisMonth) { if (await _context.Raids.CountAsync(raid => raid.RaidTeamId == character.TeamId.Value && raid.StartedAt.Month == donatedAt.Month && raid.StartedAt.Year == donatedAt.Year) > 0) { return(Problem("Donations can only be applied to the current month before any raid occurs during the month.")); } donatedAt = donatedAt.AddDays(-donatedAt.Day); } _context.Donations.Add(new Donation(_idGenerator.CreateId()) { CopperAmount = dto.CopperAmount, DonatedAt = donatedAt, Character = character, CharacterId = character.Id, EnteredById = User.GetDiscordId().GetValueOrDefault() }); await _context.SaveChangesAsync(); _telemetry.TrackEvent("DonationAdded", User); return(Ok()); }
public Task <ShoppingList> Handle(CreateShoppingListRequest request, CancellationToken cancellationToken) { var owner = _dbContext.Shoppers.FirstOrDefault(shopper => shopper.Username.Equals(request.Username)); if (owner is null) { throw new UnregisteredShopperException(); } var id = _idGenerator.CreateId(); var createdDateTime = _clock.UtcNow; var shoppingList = new ShoppingList(id, owner.Id, (Name)request.ShoppingListName, createdDateTime); _dbContext.ShoppingLists.Add(shoppingList); _dbContext.SaveChanges(); return(Task.FromResult(shoppingList)); }
public async Task <IActionResult> Post([FromBody] DonationSubmissionDto dto) { var character = await _context.Characters.FindAsync(dto.CharacterId); if (character is null) { return(NotFound()); } _context.Donations.Add(new Donation(_idGenerator.CreateId()) { CopperAmount = dto.CopperAmount, DonatedAt = _serverTimeZone.TimeZoneNow(), Character = character, CharacterId = character.Id, EnteredById = User.GetDiscordId().GetValueOrDefault() }); await _context.SaveChangesAsync(); _telemetry.TrackEvent("DonationAdded", User); return(Ok()); }
public override long Next(EntityEntry entry) { return(_generator.CreateId()); }