public void EditList(Shopper toShopper, ShoppingList shoppingList) { using (var shopCtx = new ShoppingContext()) { var shopper = shopCtx.FindShopper(toShopper.Id); // replace existing shopping list shopCtx.ShoppingLists.Remove ( shopper.ShoppingLists.First(x => x.Id == shoppingList.Id) ); shopper.ShoppingLists.Add(shoppingList); // replace every old item foreach (var item in shoppingList.Items) { if (item.Id != 0) { shopCtx.ShoppingItems.Remove ( shopCtx.ShoppingItems.First(x => x.Id == item.Id) ); shopCtx.ShoppingItems.Add(item); } } shopCtx.SaveChanges(); } }
private async Task <int> InsertPaymentAndShopperAsync(PurchaseRequestDto request, Payment payment) { string cardNumber = request.CardNumber.Encrypt(_encryptionKey); string cvv = request.Cvv.Encrypt(_encryptionKey); var shopper = await _dbContext.Shoppers .Include(x => x.Payments) .SingleOrDefaultAsync(x => x.CardNumber == cardNumber && x.Cvv == cvv); if (shopper is null) { shopper = new Shopper() { CardNumber = cardNumber, Cvv = cvv, FirstName = request.FirstName, LastName = request.LastName, ExpireMonth = request.ExpireMonth, ExpireYear = request.ExpireYear }; _logger.LogInformation($"New shopper created: {request.FirstName} {request.LastName}"); } payment.Shopper = shopper; _dbContext.Payments.Add(payment); return(await _dbContext.SaveChangesAsync()); }
/// <summary> /// Determine whether the healthy shopper should get exposed by the infectious one. /// </summary> /// <param name="healthy"></param> /// <param name="infectious"></param> /// <returns></returns> bool ShouldExposeHealthy(Shopper healthy, Shopper infectious) { // Account for motion over the last frame by taking the min distance of the "swept" positions // TODO - compute actual min distance between the 2 segments // Cheap approximation for now var distance = Mathf.Min( Vector3.Distance(healthy.transform.position, infectious.transform.position), Vector3.Distance(healthy.transform.position, infectious.PreviousPosition), Vector3.Distance(healthy.PreviousPosition, infectious.transform.position) ); if (distance > ExposureDistanceMeters) { // Too far away return(false); } // Interpolate the probability parameters based on the distance var t = distance / ExposureDistanceMeters; var prob = ExposureProbabilityAtZeroDistance * (1.0f - t) + ExposureProbabilityAtMaxDistance * t; // The probability is given per second; since we might apply the random choice over multiple steps of deltaTime // length, we need to adjust the probability. // prob = 1 - (1-probPerFrame)^(1/deltaTime) // so var probPerFrame = 1.0f - Mathf.Pow(1.0f - prob, Time.deltaTime); return(UnityEngine.Random.value < probPerFrame); }
IEnumerator ProcessShopper(StoreSimulationQueue register, Shopper shopper, float waitTime) { //shopper.BillingTime = waitTime; yield return(new WaitUntil(() => shopper.Behavior == Shopper.BehaviorType.Billing)); shopper.Regsiter = register; }
/// <summary> /// Called by the shopper when it reaches the exit. /// </summary> /// <param name="s"></param> public void Spawn(Shopper s) { s.simulation = this; if (s.Behavior == Shopper.BehaviorType.ShoppingList) { var path = m_WaypointGraph.GenerateRandomPath(6); if (path != null) { s.SetPath(path); } } if (s.m_Path == null) { // Pick a random entrance for the start position var startWp = m_Entrances[UnityEngine.Random.Range(0, m_Entrances.Count)]; s.SetWaypoint(startWp); } // Randomize the movement speed between [.75, 1.25] of the default speed var speedMult = UnityEngine.Random.Range(.5f, 1f); s.Speed = ShopperSpeed * speedMult; if (m_NumInfectious < DesiredNumInfectious) { s.InfectionStatus = Shopper.Status.Infectious; m_NumInfectious++; } }
public void Despawn(Shopper s, bool removeShopper = true) { if (s.IsInfectious()) { m_NumInfectious--; } // Update running totals of healthy and exposed. if (s.IsHealthy()) { m_FinalHealthy++; NumHealthyChanged?.Invoke(m_FinalHealthy); } if (s.IsExposed()) { m_FinalExposed++; NumContagiousChanged?.Invoke(m_FinalExposed); } if (removeShopper) { m_AllShoppers.Remove(s); } Destroy(s.gameObject); }
static void Main(string[] args) { Console.WriteLine("Hello World!"); long answer; for (int i = 1; i <= 100; i++) { Stopwatch stopwatch = new Stopwatch(); // Begin timing. stopwatch.Start(); // Do something. Console.WriteLine("Attempt No. " + i); Shopper shopper = GenerateData(); answer = NumberOfOptionsMemo1(shopper.pairOfJeans, shopper.pairOfShoes, shopper.tops, shopper.skirts, shopper.dollarsBudget); Console.WriteLine("NumberOfOptionsMemo1: " + answer); // Stop timing. stopwatch.Stop(); // Write result. Console.WriteLine("Time elapsed: {0}", stopwatch.Elapsed); } //answer = NumberOfOptions(shopper.pairOfJeans, shopper.pairOfShoes, shopper.tops, shopper.skirts, shopper.dollarsBudget); //Console.WriteLine("NumberOfOptions: " + answer); //var summary = BenchmarkRunner.Run<Shopper>(); Console.ReadKey(); }
public async Task <IActionResult> Edit(int id, [Bind("ShopperId,FirstName,LastName,Address,ZipCode,Lattitude,Longitude,IdentityUserId")] Shopper shopper) { if (id != shopper.ShopperId) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shopper); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShopperExists(shopper.ShopperId)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } ViewData["IdentityUserId"] = new SelectList(_context.Users, "Id", "Id", shopper.IdentityUserId); return(View(shopper)); }
public void CheckOut() { // Arrange const string STATE = "South Dakota"; const decimal EXPECTED_TOTAL_WITHOUT_TAX = 1400.00M; const decimal EXPECTED_TAX = 63.00M; const decimal EXPECTED_TOTAL_DUE = EXPECTED_TOTAL_WITHOUT_TAX + EXPECTED_TAX; const int SHOPPER_ID = 1; const string SHOPPER_NAME = "Tiger"; const string SHOPPER_STATE = STATE; const int QUANTITY = 1; Shopper shopper = new Shopper(SHOPPER_ID, SHOPPER_NAME, SHOPPER_STATE); const decimal CALLAWAY_IRON_PRICE = 900.00M; const string CALLAWAY_IRON_NAME = "Mavrik Irons"; Item CallawayIrons = new Item(CALLAWAY_IRON_NAME, CALLAWAY_IRON_PRICE); shopper.Add(CallawayIrons, QUANTITY); const decimal CALLAWAY_DRIVER_PRICE = 500.00M; const string CALLAWAY_DRIVER_NAME = "Mavrik Driver"; Item CallawayDriver = new Item(CALLAWAY_DRIVER_NAME, CALLAWAY_DRIVER_PRICE); shopper.Add(CallawayDriver, QUANTITY); // Act decimal ActualTotalDue = shopper.CheckOut(); // Assert Assert.AreEqual(EXPECTED_TOTAL_DUE, ActualTotalDue); }
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)); }
IEnumerator Start() { Shopper s = new Shopper(); var rnd = new System.Random(); var tapeGroups = GameObject.FindGameObjectsWithTag("TapeGroup"); foreach (var tapeGroup in tapeGroups) { var genre = tapeGroup.GetComponent <TapeGroup>().GroupGenre; var movies = s.PopulateShelvesForGenre(genre).ToList(); var len = movies.Count; var children = tapeGroup.transform.GetComponentsInChildren <TapeMetadata>(); foreach (var child in children) { var randomNumber = rnd.Next(0, len); var randomMovie = movies[randomNumber]; var tex = new Texture2D(4, 4, TextureFormat.DXT1, false); child.MovieMetadata = randomMovie; using (var www = new WWW(randomMovie.PosterUrl)) { yield return(www); www.LoadImageIntoTexture(tex); var frontCover = GetChildObject(child.gameObject.transform, "TapeFront"); frontCover.GetComponent <Renderer>().material.mainTexture = tex; } } } }
public async Task <IActionResult> Edit(int id, [Bind("ShopperID,LastName,FirstName,Email")] Shopper shopper) { if (id != shopper.ShopperID) { return(NotFound()); } if (ModelState.IsValid) { try { _context.Update(shopper); await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!ShopperExists(shopper.ShopperID)) { return(NotFound()); } else { throw; } } return(RedirectToAction(nameof(Index))); } return(View(shopper)); }
public ShopperProfile() { this.CreateMap <ShopperMongo, Shopper>() .ConstructUsing(s => Shopper.CreateNew(s.Gender, s.ShopperID, s.FirstName, s.LastName, s.Email)) .ForMember(m => m.Id, opt => opt.MapFrom(mm => mm.ShopperID)) .ForMember(s => s.Address, opt => opt.MapFrom(mm => mm.Address)); this.CreateMap <AddressMongo, Address>() .ConstructUsing(a => Address.Create(a.AddressID, a.Street, a.Number, a.City, a.Zip, a.Country)); }
public void Run() { var cart = new Cart(); cart.AddElement(new Fruits()); cart.AddElement(new Milk()); var shopper = new Shopper(); cart.Accept(shopper); }
private void OnTriggerEnter2D(Collider2D collision) { Shopper shopper = collision.GetComponent <Shopper>(); if (shopper && shopper.GetComponentInChildren <Renderer>().material != shopper.flyeredMaterial) { NotifyAdvertiser(collision.gameObject); shopper.GetFlyered(); Destroy(gameObject); } }
private Product InitializeProduct(List <Unit> units, bool active) { MockRep = new Mock <IProductRepository>(); string name = "ProductName"; Shopper shopper = new Shopper(); string supplier = "Supplier"; List <Unit> Units = units.ToList(); Product product = new Product(MockRep.Object, shopper, name, supplier, Units, active); return(product); }
public void TestShopper() { int shopperId = 1; string shopperUsername = "******"; int shopperWishlistId = 1; var shopper = new Shopper(shopperId, shopperUsername, shopperWishlistId); shopper.Id.Should().Equals(shopperId); shopper.Username.Should().Equals(shopperUsername); shopper.WishListId.Should().Equals(shopperWishlistId); }
public static Shopper GenerateData() { Shopper shopper = new Shopper(); int thousand = (int)Math.Pow(10, 3); int billion = (int)Math.Pow(10, 9); Random rnd = new Random(); int araySize = rnd.Next(900, thousand + 1); int dollarsBudget = rnd.Next(50000000, billion + 1); //pairOfJeans List <int> pairOfJeans = new List <int>(); for (int i = 0; i < araySize; i++) { pairOfJeans.Add(rnd.Next(50000000, billion + 1)); } araySize = rnd.Next(900, thousand + 1); //pairOfShoes List <int> pairOfShoes = new List <int>(); for (int i = 0; i < araySize; i++) { pairOfShoes.Add(rnd.Next(50000000, billion + 1)); } araySize = rnd.Next(900, thousand + 1); //tops List <int> tops = new List <int>(); for (int i = 0; i < araySize; i++) { tops.Add(rnd.Next(50000000, billion + 1)); } araySize = rnd.Next(900, thousand + 1); //skirts List <int> Skirts = new List <int>(); for (int i = 0; i < araySize; i++) { Skirts.Add(rnd.Next(50000000, billion + 1)); } shopper.dollarsBudget = dollarsBudget; shopper.pairOfJeans = pairOfJeans; shopper.pairOfShoes = pairOfShoes; shopper.tops = tops; shopper.skirts = Skirts; return(shopper); }
public Shopper Register(Shopper information) { using (var shopCtx = new ShoppingContext()) { shopCtx.Shoppers.Add(information); shopCtx.SaveChanges(); return(shopCtx.MakeQuery(information.Username, information.PasswordHash) .First()); } }
// Start is called before the first frame update void Start() { shopper = GameObject.FindGameObjectWithTag("Player").GetComponent <Shopper>(); if (shopper == null) { return; } shopper.activeShopChange += ShopChanged; ShopChanged(); }
public void AddList(Shopper toShopper, ShoppingList shoppingList) { using (var shopCtx = new ShoppingContext()) { var shopper = shopCtx.FindShopper(toShopper.Id); shopCtx.Attach(shoppingList); shopper.ShoppingLists.Add(shoppingList); shopCtx.SaveChanges(); } }
public async Task <Shopper> AttachLatAndLong(Shopper shopper) { string url = "https://maps.googleapis.com/maps/api/place/nearbysearch/json?radius=2000&key=AIzaSyC2Uyq82S9tdxWSHz4c4eI4E1IEHqjkaFg&location=40.748817,-73.985428&type=grocery_or_supermarket&rankby=prominence"; HttpClient client = new HttpClient(); HttpResponseMessage response = await client.GetAsync(url); string jsonResult = await response.Content.ReadAsStringAsync(); JObject jObject = JObject.Parse(jsonResult); shopper.Latitude = (double)jObject["results"][0]["geometry"]["location"]["lat"]; shopper.Longitude = (double)jObject["results"][0]["geometry"]["location"]["lng"]; return(shopper); }
public Task <bool> Handle(NewShopperCommand newPaymentCommand, CancellationToken cancellationToken) { if (!newPaymentCommand.IsValid()) { NotifyValidationErrors(newPaymentCommand); return(Task.FromResult(false)); } var shopper = new Shopper(newPaymentCommand.Id, newPaymentCommand.FirstName, newPaymentCommand.LastName, newPaymentCommand.Email, newPaymentCommand.Gender, newPaymentCommand.BirthDate, newPaymentCommand.Address); repository.SaveAsync(shopper); return(Task.FromResult(true)); }
// Start is called before the first frame update void Start() { originalTotalTextColor = totalField.color; shopper = GameObject.FindGameObjectWithTag("Player").GetComponent <Shopper>(); if (shopper == null) { return; } shopper.activeShopChange += ShopChanged; confirmButton.onClick.AddListener(ConfirmTransaction); switchButton.onClick.AddListener(SwitchMode); ShopChanged(); }
public async Task <Shopper> CreateShopper(ShopperContent shopper) { ShopperContent content = new ShopperContent { PlatformIdentifier = _platformIdentifier, UserIdentifier = shopper.UserIdentifier }; Shopper newEntity = new Shopper { Contents = content }; var entity = await _context.Shoppers.AddAsync(newEntity); return(entity); }
public void CreateProduct_ValidInput_ProductIsCreated() { Mock <IProductRepository> MockRep = new Mock <IProductRepository>(); string name = "ProductName"; Shopper shopper = new Shopper(); string supplier = "Supplier"; List <Unit> Units = new List <Unit>(); bool active = true; Product product = new Product(MockRep.Object, shopper, name, supplier, Units, active); Assert.IsNotNull(product); Assert.AreEqual(name, product.Name); Assert.AreEqual(name, product.ProductVersions.Last().Name); Assert.AreEqual(shopper.Id, product.ProductVersions.Last().CreatedByID); Assert.IsTrue(Units.SequenceEqual(product.ProductVersions.Last().Units)); Assert.AreEqual(active, product.ProductVersions.Last().IsActive); }
public bool EnterTheQueue(Shopper shopper, Func <Queue <Shopper>, bool> func = null) { var condition = true; if (func != null) { condition = func(ShoppersQueue); } if (CanEnterQueue() && condition) { ShoppersQueue.Enqueue(shopper); return(true); } return(false); }
public async Task <SaveShopperResult> Handle(CreateShopperCommand command, CancellationToken cancellationToken) { var result = new SaveShopperResult(); if (await _userRepository.AnyAsync(x => x.Email.ToLower() == command.Email.ToLower())) { Notifications.Handle("E-mail em uso"); } if (await _shopperRepository.AnyAsync(x => x.Cpf.Number.Equals(command.Cpf.Number))) { Notifications.Handle("CPF em uso"); } if (Notifications.HasNotifications()) { return(null); } var user = User.New(command.Email, _passwordHasherService.Hash(command.Password), command.Name, EUserType.Shopper); command.Cpf.Type = EIdentiticationType.Cpf; var shopper = Shopper.New(user, command.Cpf); await _shopperRepository.AddAsync(shopper); if (!await CommitAsync()) { return(null); } await _shopperAddressRepository.AddAsync(ShopperAddress.New(shopper.Id, EAddressType.Home, command.Address, "registro")); if (!await CommitAsync()) { return(null); } result.Id = shopper.Id; return(result); }
public async Task GetPayment_WithEncryption_Success() { // Arrange var shopper = new Shopper { Id = 1, CardNumber = Encryption.Encrypt(TestConstants.TestCard, TestConstants.EncryptionKey), Cvv = Encryption.Encrypt(TestConstants.TestCvv, TestConstants.EncryptionKey), FirstName = "TestName", LastName = "TestLastName", ExpireMonth = 3, ExpireYear = 2025 }; var paymentDb = new Payment() { Id = Guid.NewGuid(), Amount = 123.5M, CreatedDate = DateTime.UtcNow, Currency = Currency.EUR, PaymentStatus = PaymentStatus.Successful, Merchant = new Merchant { Id = 1, Name = "Test Merchant" }, Shopper = shopper }; dbContext.Payments.Add(paymentDb); await dbContext.SaveChangesAsync(); // Act var payment = await sut.GetPaymentAsync(paymentDb.Id); // Assert Assert.NotNull(payment); Assert.Equal(shopper.FirstName, payment.FirstName); Assert.Equal(shopper.LastName, payment.LastName); Assert.Equal(CreditCard.GetMasked(TestConstants.TestCard), payment.CardNumber); Assert.Equal(TestConstants.TestCvv, payment.Cvv); Assert.Equal(shopper.ExpireYear, payment.ExpireYear); Assert.Equal(shopper.ExpireMonth, payment.ExpireMonth); Assert.Equal(PaymentStatus.Successful, payment.PaymentStatus); }
public int bankSimulation(Payment payment) { Shopper shopper = (from s in _shopperContext.Shopper where s.cardNumber == payment.cardNumber select s).FirstOrDefault <Shopper>(); if (shopper == null) { return(500); } if (shopper.credit - payment.amount < 0) { return(402); } if (Convert.ToDateTime(payment.expiryDate) < DateTime.Now) { return(402); } return(200); }