repository migration
This commit is contained in:
@@ -0,0 +1,165 @@
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Common.Utility;
|
||||
using WhiteLagoon.Domain.Entities;
|
||||
using WhiteLagoon.Web.ViewModels;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
public class AccountController : Controller
|
||||
{
|
||||
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly SignInManager<ApplicationUser> _signInManager;
|
||||
private readonly RoleManager<IdentityRole> _roleManager;
|
||||
|
||||
public AccountController(
|
||||
UserManager<ApplicationUser> userManager,
|
||||
RoleManager<IdentityRole> roleManager,
|
||||
SignInManager<ApplicationUser> signInManager)
|
||||
{
|
||||
_roleManager = roleManager;
|
||||
_userManager = userManager;
|
||||
_signInManager = signInManager;
|
||||
}
|
||||
|
||||
public IActionResult Login(string returnUrl=null)
|
||||
{
|
||||
|
||||
returnUrl??= Url.Content("~/");
|
||||
|
||||
LoginVM loginVM = new ()
|
||||
{
|
||||
RedirectUrl = returnUrl
|
||||
};
|
||||
|
||||
return View(loginVM);
|
||||
}
|
||||
|
||||
public async Task<IActionResult> Logout()
|
||||
{
|
||||
await _signInManager.SignOutAsync();
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
|
||||
public IActionResult AccessDenied()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Register(string returnUrl = null)
|
||||
{
|
||||
returnUrl ??= Url.Content("~/");
|
||||
if (!_roleManager.RoleExistsAsync(SD.Role_Admin).GetAwaiter().GetResult())
|
||||
{
|
||||
_roleManager.CreateAsync(new IdentityRole(SD.Role_Admin)).Wait();
|
||||
_roleManager.CreateAsync(new IdentityRole(SD.Role_Customer)).Wait();
|
||||
}
|
||||
|
||||
RegisterVM registerVM = new ()
|
||||
{
|
||||
RoleList = _roleManager.Roles.Select(x => new SelectListItem
|
||||
{
|
||||
Text = x.Name,
|
||||
Value = x.Name
|
||||
}),
|
||||
RedirectUrl = returnUrl
|
||||
};
|
||||
|
||||
return View(registerVM);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Register(RegisterVM registerVM)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
ApplicationUser user = new()
|
||||
{
|
||||
Name = registerVM.Name,
|
||||
Email = registerVM.Email,
|
||||
PhoneNumber = registerVM.PhoneNumber,
|
||||
NormalizedEmail = registerVM.Email.ToUpper(),
|
||||
EmailConfirmed = true,
|
||||
UserName = registerVM.Email,
|
||||
CreatedAt = DateTime.Now
|
||||
};
|
||||
|
||||
var result = await _userManager.CreateAsync(user, registerVM.Password);
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
if (!string.IsNullOrEmpty(registerVM.Role))
|
||||
{
|
||||
await _userManager.AddToRoleAsync(user, registerVM.Role);
|
||||
}
|
||||
else
|
||||
{
|
||||
await _userManager.AddToRoleAsync(user, SD.Role_Customer);
|
||||
}
|
||||
|
||||
await _signInManager.SignInAsync(user, isPersistent: false);
|
||||
if (string.IsNullOrEmpty(registerVM.RedirectUrl))
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return LocalRedirect(registerVM.RedirectUrl);
|
||||
}
|
||||
}
|
||||
|
||||
foreach (var error in result.Errors)
|
||||
{
|
||||
ModelState.AddModelError("", error.Description);
|
||||
}
|
||||
}
|
||||
registerVM.RoleList = _roleManager.Roles.Select(x => new SelectListItem
|
||||
{
|
||||
Text = x.Name,
|
||||
Value = x.Name
|
||||
});
|
||||
|
||||
return View(registerVM);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public async Task<IActionResult> Login(LoginVM loginVM)
|
||||
{
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
var result = await _signInManager
|
||||
.PasswordSignInAsync(loginVM.Email, loginVM.Password, loginVM.RememberMe, lockoutOnFailure:false);
|
||||
|
||||
|
||||
if (result.Succeeded)
|
||||
{
|
||||
var user = await _userManager.FindByEmailAsync(loginVM.Email);
|
||||
if (await _userManager.IsInRoleAsync(user, SD.Role_Admin))
|
||||
{
|
||||
return RedirectToAction("Index", "Dashboard");
|
||||
}
|
||||
else
|
||||
{
|
||||
if (string.IsNullOrEmpty(loginVM.RedirectUrl))
|
||||
{
|
||||
return RedirectToAction("Index", "Home");
|
||||
}
|
||||
else
|
||||
{
|
||||
return LocalRedirect(loginVM.RedirectUrl);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
ModelState.AddModelError("", "Invalid login attempt.");
|
||||
}
|
||||
}
|
||||
|
||||
return View(loginVM);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,138 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Common.Utility;
|
||||
using WhiteLagoon.Application.Services.Interface;
|
||||
using WhiteLagoon.Domain.Entities;
|
||||
using WhiteLagoon.Infrastructure.Data;
|
||||
using WhiteLagoon.Web.ViewModels;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
[Authorize(Roles = SD.Role_Admin)]
|
||||
public class AmenityController : Controller
|
||||
{
|
||||
private readonly IAmenityService _amenityService;
|
||||
private readonly IVillaService _villaService;
|
||||
|
||||
public AmenityController(IAmenityService amenityService, IVillaService villaService)
|
||||
{
|
||||
_amenityService = amenityService;
|
||||
_villaService = villaService;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
var amenities = _amenityService.GetAllAmenities();
|
||||
return View(amenities);
|
||||
}
|
||||
|
||||
public IActionResult Create()
|
||||
{
|
||||
AmenityVM amenityVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
})
|
||||
};
|
||||
return View(amenityVM);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Create(AmenityVM obj)
|
||||
{
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_amenityService.CreateAmenity(obj.Amenity);
|
||||
TempData["success"] = "The amenity has been created successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
obj.VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
});
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
public IActionResult Update(int amenityId)
|
||||
{
|
||||
AmenityVM amenityVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
}),
|
||||
Amenity = _amenityService.GetAmenityById(amenityId)
|
||||
};
|
||||
if (amenityVM.Amenity == null)
|
||||
{
|
||||
return RedirectToAction("Error", "Home");
|
||||
}
|
||||
return View(amenityVM);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Update(AmenityVM amenityVM)
|
||||
{
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_amenityService.UpdateAmenity(amenityVM.Amenity);
|
||||
TempData["success"] = "The amenity has been updated successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
amenityVM.VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
});
|
||||
return View(amenityVM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IActionResult Delete(int amenityId)
|
||||
{
|
||||
AmenityVM amenityVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
}),
|
||||
Amenity = _amenityService.GetAmenityById(amenityId)
|
||||
};
|
||||
if (amenityVM.Amenity == null)
|
||||
{
|
||||
return RedirectToAction("Error", "Home");
|
||||
}
|
||||
return View(amenityVM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Delete(AmenityVM amenityVM)
|
||||
{
|
||||
Amenity? objFromDb = _amenityService.GetAmenityById(amenityVM.Amenity.Id);
|
||||
if (objFromDb is not null)
|
||||
{
|
||||
_amenityService.DeleteAmenity(objFromDb.Id);
|
||||
TempData["success"] = "The amenity has been deleted successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
TempData["error"] = "The amenity could not be deleted.";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,362 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Identity;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Stripe;
|
||||
using Stripe.Checkout;
|
||||
using Syncfusion.DocIO;
|
||||
using Syncfusion.DocIO.DLS;
|
||||
using Syncfusion.DocIORenderer;
|
||||
using Syncfusion.Drawing;
|
||||
using Syncfusion.Pdf;
|
||||
using System.Security.Claims;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Common.Utility;
|
||||
using WhiteLagoon.Application.Contract;
|
||||
using WhiteLagoon.Application.Services.Interface;
|
||||
using WhiteLagoon.Domain.Entities;
|
||||
using WhiteLagoon.Infrastructure.Repository;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
public class BookingController : Controller
|
||||
{
|
||||
private readonly IBookingService _bookingService;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
private readonly IVillaService _villaService;
|
||||
private readonly UserManager<ApplicationUser> _userManager;
|
||||
private readonly IVillaNumberService _villaNumberService;
|
||||
private readonly IPaymentService _paymentService;
|
||||
private readonly IEmailService _emailService;
|
||||
public BookingController(IBookingService bookingService,
|
||||
IPaymentService paymentService,
|
||||
IVillaService villaService, IVillaNumberService villaNumberService,
|
||||
IWebHostEnvironment webHostEnvironment, UserManager<ApplicationUser> userManager,
|
||||
IEmailService emailService)
|
||||
{
|
||||
_emailService = emailService;
|
||||
_paymentService = paymentService;
|
||||
_userManager = userManager;
|
||||
_villaService = villaService;
|
||||
_villaNumberService = villaNumberService;
|
||||
_bookingService = bookingService;
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
[Authorize]
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public IActionResult FinalizeBooking(int villaId, DateOnly checkInDate, int nights)
|
||||
{
|
||||
var claimsIdentity = (ClaimsIdentity)User.Identity;
|
||||
var userId = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier).Value;
|
||||
|
||||
ApplicationUser user = _userManager.FindByIdAsync(userId).GetAwaiter().GetResult();
|
||||
|
||||
Booking booking = new()
|
||||
{
|
||||
VillaId = villaId,
|
||||
Villa = _villaService.GetVillaById(villaId),
|
||||
CheckInDate = checkInDate,
|
||||
Nights = nights,
|
||||
CheckOutDate = checkInDate.AddDays(nights),
|
||||
UserId = userId,
|
||||
Phone=user.PhoneNumber,
|
||||
Email=user.Email,
|
||||
Name=user.Name
|
||||
};
|
||||
booking.TotalCost = booking.Villa.Price * nights;
|
||||
return View(booking);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
[HttpPost]
|
||||
public IActionResult FinalizeBooking(Booking booking)
|
||||
{
|
||||
var villa = _villaService.GetVillaById(booking.VillaId);
|
||||
booking.TotalCost = villa.Price * booking.Nights;
|
||||
|
||||
booking.Status=SD.StatusPending;
|
||||
booking.BookingDate = DateTime.Now;
|
||||
|
||||
|
||||
|
||||
if (!_villaService.IsVillaAvailableByDate(villa.Id,booking.Nights,booking.CheckInDate))
|
||||
{
|
||||
TempData["error"] = "Room has been sold out!";
|
||||
//no rooms available
|
||||
return RedirectToAction(nameof(FinalizeBooking), new
|
||||
{
|
||||
villaId = booking.VillaId,
|
||||
checkInDate = booking.CheckInDate,
|
||||
nights = booking.Nights
|
||||
});
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
_bookingService.CreateBooking(booking);
|
||||
|
||||
var domain = Request.Scheme+"://"+Request.Host.Value+"/";
|
||||
|
||||
var options = _paymentService.CreateStripeSessionOptions(booking, villa, domain);
|
||||
|
||||
var session = _paymentService.CreateStripeSession(options);
|
||||
|
||||
_bookingService.UpdateStripePaymentID(booking.Id, session.Id, session.PaymentIntentId);
|
||||
Response.Headers.Add("Location", session.Url);
|
||||
return new StatusCodeResult(303);
|
||||
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public IActionResult BookingConfirmation(int bookingId)
|
||||
{
|
||||
Booking bookingFromDb = _bookingService.GetBookingById(bookingId);
|
||||
|
||||
if (bookingFromDb.Status == SD.StatusPending)
|
||||
{
|
||||
//this is a pending order, we need to confirm if payment was successful
|
||||
|
||||
var service = new SessionService();
|
||||
Session session = service.Get(bookingFromDb.StripeSessionId);
|
||||
|
||||
if (session.PaymentStatus == "paid")
|
||||
{
|
||||
_bookingService.UpdateStatus(bookingFromDb.Id, SD.StatusApproved,0);
|
||||
_bookingService.UpdateStripePaymentID(bookingFromDb.Id,session.Id,session.PaymentIntentId);
|
||||
|
||||
_emailService.SendEmailAsync(bookingFromDb.Email,"Booking Confirmation - White Lagoon", "<p>Your booking has been confirmed. Booking ID - " + bookingFromDb.Id+"</p>");
|
||||
}
|
||||
}
|
||||
|
||||
return View(bookingId);
|
||||
}
|
||||
|
||||
[Authorize]
|
||||
public IActionResult BookingDetails(int bookingId)
|
||||
{
|
||||
Booking bookingFromDb = _bookingService.GetBookingById(bookingId);
|
||||
|
||||
if (bookingFromDb.VillaNumber==0 && bookingFromDb.Status == SD.StatusApproved)
|
||||
{
|
||||
var availableVillaNumber = AssignAvailableVillaNumberByVilla(bookingFromDb.VillaId);
|
||||
|
||||
bookingFromDb.VillaNumbers = _villaNumberService.GetAllVillaNumbers().Where(u => u.VillaId == bookingFromDb.VillaId
|
||||
&& availableVillaNumber.Any(x => x == u.Villa_Number)).ToList();
|
||||
}
|
||||
|
||||
return View(bookingFromDb);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Authorize]
|
||||
public IActionResult GenerateInvoice(int id, string downloadType)
|
||||
{
|
||||
string basePath = _webHostEnvironment.WebRootPath;
|
||||
|
||||
WordDocument document = new WordDocument();
|
||||
|
||||
|
||||
// Load the template.
|
||||
string dataPath = basePath + @"/exports/BookingDetails.docx";
|
||||
using FileStream fileStream = new (dataPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite);
|
||||
document.Open(fileStream, FormatType.Automatic);
|
||||
|
||||
//Update Template
|
||||
Booking bookingFromDb = _bookingService.GetBookingById(id);
|
||||
|
||||
TextSelection textSelection = document.Find("xx_customer_name", false, true);
|
||||
WTextRange textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.Name;
|
||||
|
||||
textSelection = document.Find("xx_customer_phone", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.Phone;
|
||||
|
||||
textSelection = document.Find("xx_customer_email", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.Email;
|
||||
|
||||
textSelection = document.Find("XX_BOOKING_NUMBER", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = "BOOKING ID - " + bookingFromDb.Id;
|
||||
textSelection = document.Find("XX_BOOKING_DATE", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = "BOOKING DATE - " + bookingFromDb.BookingDate.ToShortDateString();
|
||||
|
||||
|
||||
textSelection = document.Find("xx_payment_date", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.PaymentDate.ToShortDateString();
|
||||
textSelection = document.Find("xx_checkin_date", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.CheckInDate.ToShortDateString();
|
||||
textSelection = document.Find("xx_checkout_date", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.CheckOutDate.ToShortDateString(); ;
|
||||
textSelection = document.Find("xx_booking_total", false, true);
|
||||
textRange = textSelection.GetAsOneRange();
|
||||
textRange.Text = bookingFromDb.TotalCost.ToString("c");
|
||||
|
||||
WTable table = new(document);
|
||||
|
||||
table.TableFormat.Borders.LineWidth = 1f;
|
||||
table.TableFormat.Borders.Color = Color.Black;
|
||||
table.TableFormat.Paddings.Top = 7f;
|
||||
table.TableFormat.Paddings.Bottom = 7f;
|
||||
table.TableFormat.Borders.Horizontal.LineWidth = 1f;
|
||||
|
||||
int rows = bookingFromDb.VillaNumber > 0 ? 3 : 2;
|
||||
table.ResetCells(rows, 4);
|
||||
|
||||
WTableRow row0 = table.Rows[0];
|
||||
|
||||
row0.Cells[0].AddParagraph().AppendText("NIGHTS");
|
||||
row0.Cells[0].Width=80;
|
||||
row0.Cells[1].AddParagraph().AppendText("VILLA");
|
||||
row0.Cells[1].Width = 220;
|
||||
row0.Cells[2].AddParagraph().AppendText("PRICE PER NIGHT");
|
||||
row0.Cells[3].AddParagraph().AppendText("TOTAL");
|
||||
row0.Cells[3].Width = 80;
|
||||
|
||||
WTableRow row1 = table.Rows[1];
|
||||
|
||||
row1.Cells[0].AddParagraph().AppendText(bookingFromDb.Nights.ToString());
|
||||
row1.Cells[0].Width = 80;
|
||||
row1.Cells[1].AddParagraph().AppendText(bookingFromDb.Villa.Name);
|
||||
row1.Cells[1].Width = 220;
|
||||
row1.Cells[2].AddParagraph().AppendText((bookingFromDb.TotalCost/bookingFromDb.Nights).ToString("c"));
|
||||
row1.Cells[3].AddParagraph().AppendText(bookingFromDb.TotalCost.ToString("c"));
|
||||
row1.Cells[3].Width = 80;
|
||||
|
||||
if (bookingFromDb.VillaNumber > 0)
|
||||
{
|
||||
WTableRow row2 = table.Rows[2];
|
||||
|
||||
row2.Cells[0].Width = 80;
|
||||
row2.Cells[1].AddParagraph().AppendText("Villa Number - " + bookingFromDb.VillaNumber.ToString());
|
||||
row2.Cells[1].Width = 220;
|
||||
row2.Cells[3].Width = 80;
|
||||
}
|
||||
|
||||
WTableStyle tableStyle = document.AddTableStyle("CustomStyle") as WTableStyle;
|
||||
tableStyle.TableProperties.RowStripe = 1;
|
||||
tableStyle.TableProperties.ColumnStripe = 2;
|
||||
tableStyle.TableProperties.Paddings.Top = 2;
|
||||
tableStyle.TableProperties.Paddings.Bottom = 1;
|
||||
tableStyle.TableProperties.Paddings.Left = 5.4f;
|
||||
tableStyle.TableProperties.Paddings.Right = 5.4f;
|
||||
|
||||
ConditionalFormattingStyle firstRowStyle = tableStyle.ConditionalFormattingStyles.Add(ConditionalFormattingType.FirstRow);
|
||||
firstRowStyle.CharacterFormat.Bold = true;
|
||||
firstRowStyle.CharacterFormat.TextColor = Color.FromArgb(255, 255, 255, 255);
|
||||
firstRowStyle.CellProperties.BackColor = Color.Black;
|
||||
|
||||
table.ApplyStyle("CustomStyle");
|
||||
|
||||
TextBodyPart bodyPart = new(document);
|
||||
bodyPart.BodyItems.Add(table);
|
||||
|
||||
document.Replace("<ADDTABLEHERE>", bodyPart, false, false);
|
||||
|
||||
|
||||
using DocIORenderer renderer = new ();
|
||||
MemoryStream stream = new();
|
||||
if (downloadType == "word")
|
||||
{
|
||||
|
||||
document.Save(stream, FormatType.Docx);
|
||||
stream.Position = 0;
|
||||
|
||||
return File(stream, "application/docx", "BookingDetails.docx");
|
||||
}
|
||||
else
|
||||
{
|
||||
PdfDocument pdfDocument = renderer.ConvertToPDF(document);
|
||||
pdfDocument.Save(stream);
|
||||
stream.Position = 0;
|
||||
|
||||
return File(stream, "application/pdf", "BookingDetails.pdf");
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = SD.Role_Admin)]
|
||||
public IActionResult CheckIn(Booking booking)
|
||||
{
|
||||
_bookingService.UpdateStatus(booking.Id, SD.StatusCheckedIn, booking.VillaNumber);
|
||||
TempData["Success"] = "Booking Updated Successfully.";
|
||||
return RedirectToAction(nameof(BookingDetails), new { bookingId = booking.Id });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = SD.Role_Admin)]
|
||||
public IActionResult CheckOut(Booking booking)
|
||||
{
|
||||
_bookingService.UpdateStatus(booking.Id, SD.StatusCompleted , booking.VillaNumber);
|
||||
TempData["Success"] = "Booking Completed Successfully.";
|
||||
return RedirectToAction(nameof(BookingDetails), new { bookingId = booking.Id });
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
[Authorize(Roles = SD.Role_Admin)]
|
||||
public IActionResult CancelBooking(Booking booking)
|
||||
{
|
||||
_bookingService.UpdateStatus(booking.Id, SD.StatusCancelled, 0);
|
||||
TempData["Success"] = "Booking Cancelled Successfully.";
|
||||
return RedirectToAction(nameof(BookingDetails), new { bookingId = booking.Id });
|
||||
}
|
||||
|
||||
|
||||
private List<int> AssignAvailableVillaNumberByVilla(int villaId)
|
||||
{
|
||||
List<int> availableVillaNumbers = new();
|
||||
|
||||
var villaNumbers = _villaNumberService.GetAllVillaNumbers().Where(u => u.VillaId == villaId);
|
||||
|
||||
var checkedInVilla = _bookingService.GetCheckedInVillaNumbers(villaId);
|
||||
|
||||
foreach(var villaNumber in villaNumbers)
|
||||
{
|
||||
if (!checkedInVilla.Contains(villaNumber.Villa_Number))
|
||||
{
|
||||
availableVillaNumbers.Add(villaNumber.Villa_Number);
|
||||
}
|
||||
}
|
||||
return availableVillaNumbers;
|
||||
}
|
||||
|
||||
|
||||
#region API Calls
|
||||
[HttpGet]
|
||||
[Authorize]
|
||||
public IActionResult GetAll(string status)
|
||||
{
|
||||
IEnumerable<Booking> objBookings;
|
||||
string userId = "";
|
||||
if (string.IsNullOrEmpty(status))
|
||||
{
|
||||
status = "";
|
||||
}
|
||||
|
||||
if (!User.IsInRole(SD.Role_Admin))
|
||||
{
|
||||
var claimsIdentity = (ClaimsIdentity)User.Identity;
|
||||
userId = claimsIdentity.FindFirst(ClaimTypes.NameIdentifier).Value;
|
||||
}
|
||||
|
||||
objBookings = _bookingService.GetAllBookings(userId, status);
|
||||
|
||||
return Json(new { data = objBookings });
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,51 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Stripe;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Common.Utility;
|
||||
using WhiteLagoon.Application.Services.Interface;
|
||||
using WhiteLagoon.Web.ViewModels;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
public class DashboardController : Controller
|
||||
{
|
||||
private readonly IDashboardService _dashboardService;
|
||||
|
||||
public DashboardController(IDashboardService dashboardService)
|
||||
{
|
||||
_dashboardService = dashboardService;
|
||||
}
|
||||
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
|
||||
public async Task<IActionResult> GetTotalBookingRadialChartData()
|
||||
{
|
||||
return Json(await _dashboardService.GetTotalBookingRadialChartData());
|
||||
}
|
||||
|
||||
public async Task<IActionResult> GetRegisteredUserChartData()
|
||||
{
|
||||
return Json(await _dashboardService.GetRegisteredUserChartData());
|
||||
}
|
||||
|
||||
public async Task<IActionResult> GetRevenueChartData()
|
||||
{
|
||||
return Json(await _dashboardService.GetRevenueChartData());
|
||||
}
|
||||
|
||||
public async Task<IActionResult> GetBookingPieChartData()
|
||||
{
|
||||
return Json(await _dashboardService.GetBookingPieChartData());
|
||||
}
|
||||
|
||||
public async Task<IActionResult> GetMemberAndBookingLineChartData()
|
||||
{
|
||||
return Json(await _dashboardService.GetMemberAndBookingLineChartData());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,158 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Syncfusion.Presentation;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Common.Utility;
|
||||
using WhiteLagoon.Application.Services.Interface;
|
||||
using WhiteLagoon.Web.ViewModels;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
public class HomeController : Controller
|
||||
{
|
||||
|
||||
private readonly IVillaService _villaService;
|
||||
private readonly IWebHostEnvironment _webHostEnvironment;
|
||||
|
||||
public HomeController(IVillaService villaService, IWebHostEnvironment webHostEnvironment)
|
||||
{
|
||||
_villaService = villaService;
|
||||
_webHostEnvironment = webHostEnvironment;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
HomeVM homeVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas(),
|
||||
Nights=1,
|
||||
CheckInDate =DateOnly.FromDateTime(DateTime.Now),
|
||||
};
|
||||
return View(homeVM);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult GetVillasByDate(int nights, DateOnly checkInDate)
|
||||
{
|
||||
|
||||
HomeVM homeVM = new()
|
||||
{
|
||||
CheckInDate = checkInDate,
|
||||
VillaList = _villaService.GetVillasAvailabilityByDate(nights,checkInDate),
|
||||
Nights = nights
|
||||
};
|
||||
|
||||
return PartialView("_VillaList",homeVM);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult GeneratePPTExport(int id)
|
||||
{
|
||||
var villa = _villaService.GetVillaById(id);
|
||||
if (villa is null)
|
||||
{
|
||||
return RedirectToAction(nameof(Error));
|
||||
}
|
||||
|
||||
string basePath = _webHostEnvironment.WebRootPath;
|
||||
string filePath = basePath + @"/Exports/ExportVillaDetails.pptx";
|
||||
|
||||
|
||||
using IPresentation presentation = Presentation.Open(filePath);
|
||||
|
||||
ISlide slide = presentation.Slides[0];
|
||||
|
||||
|
||||
IShape? shape = slide.Shapes.FirstOrDefault(u=>u.ShapeName== "txtVillaName") as IShape;
|
||||
if(shape is not null)
|
||||
{
|
||||
shape.TextBody.Text = villa.Name;
|
||||
}
|
||||
|
||||
shape = slide.Shapes.FirstOrDefault(u => u.ShapeName == "txtVillaDescription") as IShape;
|
||||
if (shape is not null)
|
||||
{
|
||||
shape.TextBody.Text = villa.Description;
|
||||
}
|
||||
|
||||
|
||||
shape = slide.Shapes.FirstOrDefault(u => u.ShapeName == "txtOccupancy") as IShape;
|
||||
if (shape is not null)
|
||||
{
|
||||
shape.TextBody.Text = string.Format("Max Occupancy : {0} adults", villa.Occupancy);
|
||||
}
|
||||
shape = slide.Shapes.FirstOrDefault(u => u.ShapeName == "txtVillaSize") as IShape;
|
||||
if (shape is not null)
|
||||
{
|
||||
shape.TextBody.Text = string.Format("Villa Size: {0} sqft", villa.Sqft);
|
||||
}
|
||||
shape = slide.Shapes.FirstOrDefault(u => u.ShapeName == "txtPricePerNight") as IShape;
|
||||
if (shape is not null)
|
||||
{
|
||||
shape.TextBody.Text = string.Format("USD {0}/night", villa.Price.ToString("C"));
|
||||
}
|
||||
|
||||
|
||||
shape = slide.Shapes.FirstOrDefault(u => u.ShapeName == "txtVillaAmenitiesHeading") as IShape;
|
||||
if(shape is not null)
|
||||
{
|
||||
List<string> listItems = villa.VillaAmenity.Select(x => x.Name).ToList();
|
||||
|
||||
shape.TextBody.Text = "";
|
||||
|
||||
foreach (var item in listItems)
|
||||
{
|
||||
IParagraph paragraph = shape.TextBody.AddParagraph();
|
||||
ITextPart textPart = paragraph.AddTextPart(item);
|
||||
|
||||
paragraph.ListFormat.Type = ListType.Bulleted;
|
||||
paragraph.ListFormat.BulletCharacter = '\u2022';
|
||||
textPart.Font.FontName = "system-ui";
|
||||
textPart.Font.FontSize = 18;
|
||||
textPart.Font.Color = ColorObject.FromArgb(144, 148, 152);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
shape = slide.Shapes.FirstOrDefault(u => u.ShapeName == "imgVilla") as IShape;
|
||||
if(shape is not null)
|
||||
{
|
||||
byte[] imageData;
|
||||
string imageUrl;
|
||||
try
|
||||
{
|
||||
imageUrl= string.Format("{0}{1}", basePath, villa.ImageUrl);
|
||||
imageData = System.IO.File.ReadAllBytes(imageUrl);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
imageUrl = string.Format("{0}{1}", basePath, "/images/placeholder.png");
|
||||
imageData = System.IO.File.ReadAllBytes(imageUrl);
|
||||
}
|
||||
slide.Shapes.Remove(shape);
|
||||
using MemoryStream imageStream = new(imageData);
|
||||
IPicture newPicture = slide.Pictures.AddPicture(imageStream, 60,120,300,200);
|
||||
|
||||
}
|
||||
|
||||
|
||||
|
||||
MemoryStream memoryStream = new();
|
||||
presentation.Save(memoryStream);
|
||||
memoryStream.Position = 0;
|
||||
return File(memoryStream,"application/pptx","villa.pptx");
|
||||
|
||||
|
||||
}
|
||||
|
||||
public IActionResult Privacy()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Error()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,99 @@
|
||||
using Microsoft.AspNetCore.Authorization;
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Services.Interface;
|
||||
using WhiteLagoon.Domain.Entities;
|
||||
using WhiteLagoon.Infrastructure.Data;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
[Authorize]
|
||||
public class VillaController : Controller
|
||||
{
|
||||
private readonly IVillaService _villaService;
|
||||
|
||||
public VillaController(IVillaService villaService)
|
||||
{
|
||||
_villaService = villaService;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
var villas = _villaService.GetAllVillas();
|
||||
return View(villas);
|
||||
}
|
||||
|
||||
public IActionResult Create()
|
||||
{
|
||||
return View();
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Create(Villa obj)
|
||||
{
|
||||
|
||||
if (obj.Name == obj.Description)
|
||||
{
|
||||
ModelState.AddModelError("name", "The description cannot exactly match the Name.");
|
||||
}
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
|
||||
_villaService.CreateVilla(obj);
|
||||
TempData["success"] = "The villa has been created successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Update(int villaId)
|
||||
{
|
||||
Villa? obj = _villaService.GetVillaById(villaId);
|
||||
if (obj == null)
|
||||
{
|
||||
return RedirectToAction("Error", "Home");
|
||||
}
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Update(Villa obj)
|
||||
{
|
||||
if (ModelState.IsValid && obj.Id > 0)
|
||||
{
|
||||
|
||||
_villaService.UpdateVilla(obj);
|
||||
TempData["success"] = "The villa has been updated successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
return View();
|
||||
}
|
||||
|
||||
public IActionResult Delete(int villaId)
|
||||
{
|
||||
Villa? obj = _villaService.GetVillaById(villaId);
|
||||
if (obj is null)
|
||||
{
|
||||
return RedirectToAction("Error", "Home");
|
||||
}
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Delete(Villa obj)
|
||||
{
|
||||
bool deleted = _villaService.DeleteVilla(obj.Id);
|
||||
if (deleted)
|
||||
{
|
||||
TempData["success"] = "The villa has been deleted successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
else
|
||||
{
|
||||
TempData["error"] = "Failed to delete the villa.";
|
||||
}
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,142 @@
|
||||
using Microsoft.AspNetCore.Mvc;
|
||||
using Microsoft.AspNetCore.Mvc.Rendering;
|
||||
using Microsoft.EntityFrameworkCore;
|
||||
using WhiteLagoon.Application.Common.Interfaces;
|
||||
using WhiteLagoon.Application.Services.Interface;
|
||||
using WhiteLagoon.Domain.Entities;
|
||||
using WhiteLagoon.Infrastructure.Data;
|
||||
using WhiteLagoon.Web.ViewModels;
|
||||
|
||||
namespace WhiteLagoon.Web.Controllers
|
||||
{
|
||||
|
||||
public class VillaNumberController : Controller
|
||||
{
|
||||
private readonly IVillaNumberService _villaNumberService;
|
||||
private readonly IVillaService _villaService;
|
||||
public VillaNumberController(IVillaNumberService villaNumberService, IVillaService villaService)
|
||||
{
|
||||
_villaService = villaService;
|
||||
_villaNumberService = villaNumberService;
|
||||
}
|
||||
|
||||
public IActionResult Index()
|
||||
{
|
||||
var villaNumbers = _villaNumberService.GetAllVillaNumbers();
|
||||
return View(villaNumbers);
|
||||
}
|
||||
|
||||
public IActionResult Create()
|
||||
{
|
||||
VillaNumberVM villaNumberVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
})
|
||||
};
|
||||
return View(villaNumberVM);
|
||||
}
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Create(VillaNumberVM obj)
|
||||
{
|
||||
//ModelState.Remove("Villa");
|
||||
|
||||
bool roomNumberExists = _villaNumberService.CheckVillaNumberExists(obj.VillaNumber.Villa_Number);
|
||||
|
||||
if (ModelState.IsValid && !roomNumberExists)
|
||||
{
|
||||
_villaNumberService.CreateVillaNumber(obj.VillaNumber);
|
||||
TempData["success"] = "The villa Number has been created successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
if (roomNumberExists)
|
||||
{
|
||||
TempData["error"] = "The villa Number already exists.";
|
||||
}
|
||||
obj.VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
});
|
||||
return View(obj);
|
||||
}
|
||||
|
||||
public IActionResult Update(int villaNumberId)
|
||||
{
|
||||
VillaNumberVM villaNumberVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
}),
|
||||
VillaNumber = _villaNumberService.GetVillaNumberById(villaNumberId)
|
||||
};
|
||||
if (villaNumberVM.VillaNumber == null)
|
||||
{
|
||||
return RedirectToAction("Error", "Home");
|
||||
}
|
||||
return View(villaNumberVM);
|
||||
}
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Update(VillaNumberVM villaNumberVM)
|
||||
{
|
||||
|
||||
if (ModelState.IsValid)
|
||||
{
|
||||
_villaNumberService.UpdateVillaNumber(villaNumberVM.VillaNumber);
|
||||
TempData["success"] = "The villa Number has been updated successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
|
||||
villaNumberVM.VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
});
|
||||
return View(villaNumberVM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
public IActionResult Delete(int villaNumberId)
|
||||
{
|
||||
VillaNumberVM villaNumberVM = new()
|
||||
{
|
||||
VillaList = _villaService.GetAllVillas().Select(u => new SelectListItem
|
||||
{
|
||||
Text = u.Name,
|
||||
Value = u.Id.ToString()
|
||||
}),
|
||||
VillaNumber = _villaNumberService.GetVillaNumberById(villaNumberId)
|
||||
};
|
||||
if (villaNumberVM.VillaNumber == null)
|
||||
{
|
||||
return RedirectToAction("Error", "Home");
|
||||
}
|
||||
return View(villaNumberVM);
|
||||
}
|
||||
|
||||
|
||||
|
||||
[HttpPost]
|
||||
public IActionResult Delete(VillaNumberVM villaNumberVM)
|
||||
{
|
||||
VillaNumber? objFromDb = _villaNumberService.GetVillaNumberById(villaNumberVM.VillaNumber.Villa_Number);
|
||||
if (objFromDb is not null)
|
||||
{
|
||||
_villaNumberService.DeleteVillaNumber(objFromDb.Villa_Number);
|
||||
TempData["success"] = "The villa number has been deleted successfully.";
|
||||
return RedirectToAction(nameof(Index));
|
||||
}
|
||||
TempData["error"] = "The villa number could not be deleted.";
|
||||
return View();
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user