public async Task <IActionResult> EditAsync(int id) { this.ViewData["categories"] = _categoryRepository.Categories.Select(x => new SelectListItem { Value = x.CategoryName, Text = x.CategoryName }).ToList(); RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(id); Category category = _categoryRepository.Categories.FirstOrDefault(p => p.CategoryId == rentalAsset.CategoryId); EditRentalAssetViewModel editRentalAssetViewModel = new EditRentalAssetViewModel { RentalAssetId = rentalAsset.RentalAssetId, Name = rentalAsset.Name, Price = rentalAsset.Price, Location = rentalAsset.Location, IsAvailable = rentalAsset.IsAvailable, Category = category.CategoryName, ExistingImagePath = rentalAsset.ImageUrl, Description = rentalAsset.Description, ExistingImages = rentalAsset.Images }; return(View(editRentalAssetViewModel)); }
public async Task <IActionResult> CheckoutAsync(int leaseId) { List <SelectListItem> paymentOptions = new List <SelectListItem> { new SelectListItem() { Text = "Debit Card", Value = "swipe" }, new SelectListItem() { Text = "Eco Cash", Value = "ecocash" } }; this.ViewData["paymentOptions"] = paymentOptions; Lease lease = await _leaseRepository.GetLeaseById(leaseId); RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(lease.RentalAssetId); var totalDays = (lease.leaseTo - lease.leaseFrom).TotalDays; decimal transactionTotal = rentalAsset.Price * (decimal)totalDays; TransactionCheckoutViewModel vm = new TransactionCheckoutViewModel() { AssetPricing = rentalAsset.Price, RentalDuration = totalDays, TransactionTotal = transactionTotal }; ViewBag.leaseId = leaseId; return(View(vm)); }
public async Task <RentalAsset> AddAsync(RentalAsset item) { await _appDbContext.RentalAssets.AddAsync(item); await _appDbContext.SaveChangesAsync(); return(item); }
public async Task EndBooking(int assetId) { RentalAsset rentalAsset = await _appDbContext.RentalAssets.FindAsync(assetId); rentalAsset.BookTillDate = null; rentalAsset.IsAvailable = true; _appDbContext.RentalAssets.Update(rentalAsset); await _appDbContext.SaveChangesAsync(); }
public async Task BookAsset(DateTime bookedTill, int assetId) { RentalAsset rentalAsset = await _appDbContext.RentalAssets.FindAsync(assetId); rentalAsset.BookTillDate = bookedTill; rentalAsset.IsAvailable = false; _appDbContext.RentalAssets.Update(rentalAsset); await _appDbContext.SaveChangesAsync(); }
public async Task <IActionResult> CheckoutAsync(TransactionCheckoutViewModel model) { //get the lease Lease lease = await _leaseRepository.GetLeaseById(model.LeaseId); RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(lease.RentalAssetId); string transactionType; if (lease.UserId == model.ServerId && model.TransactionType != null) { transactionType = model.TransactionType; } else { transactionType = "Cash"; } var totalDays = (lease.leaseTo - lease.leaseFrom).TotalDays; decimal transactionTotal = rentalAsset.Price * (decimal)totalDays; if (ModelState.IsValid) { var transaction = new Transaction { TransactionTotal = transactionTotal, ServerId = model.ServerId, TransactionDate = DateTime.Now, TransactionNotes = model.TransactionNotes, TransactionType = transactionType, LeaseId = lease.LeaseId, VendorUserId = lease.UserId, }; var ActiveLease = new ActiveLease { RentalAssetId = rentalAsset.RentalAssetId, LeaseId = lease.LeaseId }; var result = await _transactionRepository.CreateTransactionAsync(transaction); //success if (result > 0) { await _rentalAssetRepository.BookAsset(lease.leaseTo, rentalAsset.RentalAssetId); await _activeLeaseRepository.AddActiveLeaseAsync(ActiveLease); await _leaseRepository.RemoveUnPaidLeases(); } return(RedirectToAction("CheckoutComplete")); } return(View(model)); }
public async Task <IActionResult> EndBooking(int id) { RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(id); ActiveLease activeLease = _activeLeaseRepository.GetActiveLeaseByAssetId(rentalAsset.RentalAssetId); Lease lease = await _leaseRepository.GetLeaseById(activeLease.LeaseId); ApplicationUser user = await _userManager.FindByIdAsync(lease.UserId); if (rentalAsset == null) { ViewBag.ErrorMessage = $"The rental asset id={id} cannot be found"; return(View("NotFound")); } else { try { if (rentalAsset.BookTillDate < DateTime.Now) { // Calculate amount paid var totalDays = (lease.leaseTo - lease.leaseFrom).TotalDays; decimal AmountPaid = rentalAsset.Price * (decimal)totalDays; //Add invoice var invoice = new Invoice { RentalAssetId = rentalAsset.RentalAssetId, LeaseFrom = lease.leaseFrom, LeaseTo = lease.leaseTo, ApplicationId = user.Id, AmountPaid = AmountPaid }; await _invoiceRepository.AddInvoice(invoice); } await _rentalAssetRepository.EndBooking(id); await _activeLeaseRepository.RemoveLease(activeLease); return(RedirectToAction("BookedList")); } catch (Exception ex) { return(NotFound(ex.Message)); } } }
public async Task <IActionResult> CreateAsync(CreateRentalAssetViewModel model) { if (ModelState.IsValid) { List <Image> assetImages = new List <Image>(); String mainPhotoPath = null; if (model.Images.Count > 1) { for (int i = 0; i < model.Images.Count; i++) { if (i == 0) { mainPhotoPath = ProcessUploadedImage(model.Images[i]); continue; } string photoPath = ProcessUploadedImage(model.Images[i]); Image image = new Image { ImageName = model.Images[i].FileName, ImageUrl = photoPath }; assetImages.Add(image); } } var category = _categoryRepository.Categories.FirstOrDefault(p => p.CategoryName == model.Category); RentalAsset newRentalAsset = new RentalAsset { Name = model.Name, Price = model.Price, IsAvailable = model.IsAvailable, DateModified = DateTime.Today, CategoryId = category.CategoryId, ImageUrl = mainPhotoPath, Description = model.Description, Images = assetImages }; await _rentalAssetRepository.AddAsync(newRentalAsset); return(RedirectToAction("List", new { id = newRentalAsset.RentalAssetId })); } return(View()); }
public async Task <IActionResult> View(int Id) { Invoice invoice = _invoiceRepository.GetInvoice(Id); RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(invoice.RentalAssetId); var vm = new InvoiceDetailViewModel { InvoiceId = invoice.InvoiceId, RentalAssetLocation = rentalAsset.Location, RentalAssetName = rentalAsset.Name, RentalAssetPrice = rentalAsset.Price, LeaseFrom = invoice.LeaseFrom, LeaseTo = invoice.LeaseTo, AmountPaid = invoice.AmountPaid }; return(View(vm)); }
public async Task <IActionResult> TransactionDetailAsync(int Id) { Transaction transaction = await _transactionRepository.GetPurchaseByIdAsync(Id); Lease lease = transaction.Lease; RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(lease.RentalAssetId); VendorUser vendor = await _vendorUserManager.FindByIdAsync(lease.UserId); ApplicationUser server = await _userManager.FindByIdAsync(transaction.ServerId); var vm = new TransactionDetailViewModel { RentalAsset = rentalAsset, Transaction = transaction, VendorUser = vendor, Server = server, Lease = lease }; return(View(vm)); }
public async Task <IActionResult> EditAsync(EditRentalAssetViewModel model) { if (ModelState.IsValid) { List <Image> assetImages = new List <Image>(); List <Image> deleteImages = new List <Image>(); RentalAsset rentalAsset = await _rentalAssetRepository.GetItemByIdAsync(model.RentalAssetId); Category category = _categoryRepository.Categories.FirstOrDefault(p => p.CategoryName == model.Category); rentalAsset.Name = model.Name; rentalAsset.Price = model.Price; rentalAsset.Location = model.Location; rentalAsset.CategoryId = category.CategoryId; rentalAsset.IsAvailable = model.IsAvailable; rentalAsset.DateModified = DateTime.Today; rentalAsset.Description = model.Description; if (model.Images != null) { if (model.Images.Count > 1) { if (model.ExistingImagePath != null) { string filePath = Path.Combine(_webHostEnvironment.WebRootPath + model.ExistingImagePath); System.IO.File.Delete(filePath); } foreach (var item in rentalAsset.Images) { deleteImages.Add(item); string filePath = Path.Combine(_webHostEnvironment.WebRootPath + item.ImageUrl); System.IO.File.Delete(filePath); } for (int i = 0; i < model.Images.Count; i++) { if (i == 0) { rentalAsset.ImageUrl = ProcessUploadedImage(model.Images[i]); continue; } string photoPath = ProcessUploadedImage(model.Images[i]); Image image = new Image { ImageName = model.Images[i].FileName, ImageUrl = photoPath }; assetImages.Add(image); } } rentalAsset.Images = assetImages; } await _rentalAssetRepository.EditItemAsync(rentalAsset); foreach (var item in deleteImages) { _imageRepository.DeleteImage(item); } return(RedirectToAction("List")); } return(View()); }
public async Task <IActionResult> ViewAsync(int itemId) { RentalAsset unitItem = await _rentalAssetRepository.GetItemByIdAsync(itemId); return(View(unitItem)); }
public void Add(RentalAsset newAsset) { _context.Add(newAsset); _context.SaveChanges(); }
public async Task EditItemAsync(RentalAsset updatedItem) { _appDbContext.RentalAssets.Update(updatedItem); await _appDbContext.SaveChangesAsync(); }