/// <summary> /// /// </summary> /// <param name="rentalHistory"></param> /// <returns></returns> async Task ILogicApiActor.WriteRentalHistory(RentalHistory rentalHistory) { try { using (var client = new HttpClient()) { client.BaseAddress = new Uri(_rentalLogicAppEndpoint); client.DefaultRequestHeaders.Accept.Clear(); client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("text/plain")); var response = await client.PostAsJsonAsync(string.Empty, JsonConvert.SerializeObject(new { customerId = rentalHistory.CustomerId, inventoryId = rentalHistory.InventoryId, videoId = rentalHistory.VideoId, startDate = rentalHistory.StartDate.ToString("MMMM dd, yyyy"), endDate = rentalHistory.EndDate.ToString("MMMM dd, yyyy"), transactionId = rentalHistory.TransactionId })).ConfigureAwait(false); } } catch (Exception ex) { ActorEventSource.Current.ActorMessage(this, ex.Message); } }
private void RentalGrid() { var record = RentalHistory.Select(); dgvRentalRecord.DataSource = null; dgvRentalRecord.DataSource = record; }
public bool RentScooter(int scooterId, int customerId) { var now = DateTime.UtcNow; var scooter = _context.Scooters.FirstOrDefault(x => x.Id == scooterId); if (scooter == null || customerId == null) { return(false); } if (!scooter.Available || scooter.Damaged) { return(false); } var customer = _context.Customers.FirstOrDefault(x => x.Id == customerId); var rentalHistoryItem = new RentalHistory { Customer = customer, Scooter = scooter, RentalStart = now }; scooter.Available = false; _context.Update(scooter); _context.Add(rentalHistoryItem); _context.SaveChanges(); CreateRentalItem(scooter, customer, rentalHistoryItem); return(true); }
public bool AddUserRentalHistory(string userId, Car car) { RentalHistory rentalHistory = new RentalHistory() { Id = ObjectId.GenerateNewId().ToString(), Brand = car.Brand, Model = car.Model, RentedFrom = DateTime.Now, RentedUntil = (DateTime)car.RentedUntil }; ApplicationUser user = GetUserById(userId); user.RentalHistories.Add(rentalHistory); var replacedUser = _context.Users.ReplaceOne(u => u.Id == user.Id, user); return(replacedUser.IsAcknowledged); }
public Rental CreateRentalItem(Scooter scooter, Customer customer, RentalHistory rentalHistory) { var rentalItem = new Rental { RentalId = rentalHistory.Id.ToString(), CustomerId = customer.Id.ToString(), CustomerName = customer.Name, ScooterId = scooter.Id.ToString(), ScooterMake = scooter.Make, RentalStart = rentalHistory.RentalStart, RentalFinish = rentalHistory.RentalFinish, TotalTime = rentalHistory.TotalTime }; _context.Add(rentalItem); _context.SaveChanges(); return(rentalItem); }
/// <summary> ///Method for creating a personalized rentalhistory. Unfortunantely a major bug atm ///when clearing the cart (state.pickedmovies) which in turn makes the history not ///being able to update. No solution as of yet since everything is logged in database ///correctly, its only this query that does not display the movies of the recent rentals. ///Closing the program and opening again shows the correct history. /// </summary> /// <param name="id"></param> /// <returns></returns> public static IEnumerable RentalsHistory(Customer customer) { var rh = new List <RentalHistory>(); var rentals = customer.Rentals; foreach (var obj in rentals) { foreach (var item in obj.Movies) { var rHistory = new RentalHistory(); rHistory.MovieTitle = item.Title; rHistory.RentalDate = obj.Date; rHistory.DaysToReturn = rHistory.ReturnDays(rHistory.RentalDate); rh.Add(rHistory); } } return(rh); }
public void RentProduct(int assetId, int subscriberId) { var now = DateTime.Now; var product = GetRentalAsset(assetId); var subscriber = GetSubscriber(subscriberId); var distributionCenter = GetDistributionCenter(subscriber); var inventory = GetInventory(assetId, distributionCenter.Id); if (subscriber == null) { return; //Handle Feedback to user on Frontend } if (!IsAvailable(assetId, subscriberId)) { return; //Handle Feedback to user on Frontend } UpdateAssetAvail(inventory.Id); var rental = new Rental { RentalAsset = product, Subscriber = subscriber, DistributionCenter = distributionCenter, Since = now, Until = GetDefaultRentalPeriod(now) }; _context.Add(rental); var rentalHistory = new RentalHistory { RentedOut = now, RentalAsset = product, Subscriber = subscriber, DistributionCenter = distributionCenter }; _context.Add(rentalHistory); _context.SaveChanges(); }
public async Task WritePurchaseHistory(RentalHistory rentalHistory) { await logicAppProxy.WriteRentalHistory(rentalHistory); }
public async Task <IActionResult> Checkout(string Discount = null) { List <CartViewModel> lstCart = HttpContext.Session.Get <List <CartViewModel> >("ShoppingCartSession"); List <CartViewModel> lstCart2 = HttpContext.Session.Get <List <CartViewModel> >("ShoppingCartSession2"); List <CartViewModel> cartViewModels = new List <CartViewModel>(); List <CartViewModel> cartViewModels1 = new List <CartViewModel>(); foreach (var product in lstCart) { var studio = await _db.Studios.Where(u => u.ID == product.Game.StudioID).FirstOrDefaultAsync(); product.Studio = studio; cartViewModels.Add(product); } foreach (var product in lstCart2) { var studio = await _db.Studios.Where(u => u.ID == product.Game.StudioID).FirstOrDefaultAsync(); product.Studio = studio; cartViewModels1.Add(product); } SuperCartViewModel cartViewModel = new SuperCartViewModel() { CartVM1 = cartViewModels, CartVM2 = cartViewModels1 }; var user = await _db.ApplicationUsers.Where(u => u.Email == User.Identity.Name).FirstOrDefaultAsync(); var sum1 = lstCart.Sum(u => u.Amount * u.Game.Price); var sum2 = lstCart.Sum(u => u.Amount * (u.Game.Price * 0.1)); if (user.Balance >= (sum1 + sum2)) { Order order = new Order() { ApplicationUserID = user.Id, Total = sum1, PurchasedDate = DateTime.Now, }; _db.Add(order); _db.SaveChanges(); foreach (var product in lstCart) { var code = await _db.Codes.Where(u => u.GameID == product.Game.ID && u.Available == true).FirstOrDefaultAsync(); code.Available = false; var game = await _db.Games.Where(u => u.ID == product.Game.ID).FirstOrDefaultAsync(); game.AvailableCode -= 1; OrderDetail orderDetail = new OrderDetail() { OrderID = order.ID, CodeID = code.ID }; _db.Add(orderDetail); _db.SaveChanges(); } RentalHistory rentalHistory = new RentalHistory() { ApplicationUserID = user.Id, Total = sum2 }; _db.Add(rentalHistory); _db.SaveChanges(); foreach (var product in lstCart2) { var gameAccount = await _db.GameAccounts.Where(u => u.GameID == product.Game.ID && u.Available == true).FirstOrDefaultAsync(); gameAccount.Available = false; var game = await _db.Games.Where(u => u.ID == product.Game.ID).FirstOrDefaultAsync(); game.AvailableAccount -= 1; RentalDetail rentalDetail = new RentalDetail() { RentalHistoryID = rentalHistory.ID, GameAccountID = gameAccount.ID, StartDate = DateTime.Now, EndDate = DateTime.Now.AddHours(product.Amount), OnGoing = true }; _db.Add(rentalDetail); _db.SaveChanges(); } user.Balance -= (sum1 + sum2); await _db.SaveChangesAsync(); } cartViewModel.Total = sum1 + sum2; return(View(cartViewModel)); }