Recently I started programming in MVC and I'm full of doubts.
I'm developing a hotel reservation system and after spending 3 days trying to calculate the total cost of an unsuccessful reservation, I've decided to ask for help with the code because I'm in doubt if I'm creating Controller
and Views
correctly.
In this system I have registered 4 different hotels, each hotel has several types of rooms and each room has a different daily rate, these rates vary according to the period of the year (seasons) and are calculated based on an initial and final date, whether the day falls on a Friday or a Saturday, whether the reservation is for a week or a month.
That is, I need to calculate the day by day between the date of arrival and the date of departure, check if the day is within a season and whether it is Friday or a Saturday, etc. and at the end have the full price of the reservation.
The registration of hotels, room types, seasons (low season, Christmas, summer, winter, Easter, etc.) work perfectly to the point where a Calcular reserva
button is called.
I can not make the calculation nor return some View
showing the Reserve Total . Here is the code:
Classes:
public class Hotel
{
public int HotelId { get; set; }
public string Nome { get; set; }
public virtual ICollection<Quarto> Quarto { get; set; }
}
public class Quarto
{
public int QuartoId { get; set; }
public string Nome { get; set; }
[DataType(DataType.Currency)]
public int HotelId { get; set; }
public virtual Hotel Hotel { get; set; }
public virtual ICollection<Temporada> Temporada { get; set; }
}
public class Temporada
{
public int TemporadaId { get; set; }
public string NomeTemporada { get; set; }
public DateTime Chegada { get; set; }
public DateTime Saida { get; set; }
[Display(Name = " Diaria Fora de Temporada")]
public decimal DiariaForaTemporada{ get; set; }
[Display(Name = "$ Diaria Temporada ")]
public decimal DiariaTemporada { get; set; }
[Display(Name = "$ Diaria Sexta/Sabado")]
public decimal DiariaSabado { get; set; }
[Display(Name = "$ Diaria Semana")]
public decimal Diaria Semana { get; set; }
[Display(Name = "$ Diaria Mes")]
public decimal DiariaMes { get; set; }
public int QuartoId { get; set; }
public int HotelId { get; set; }
public virtual Hotel Hotel { get; set; }
public virtual Quarto Quarto { get; set; }
}
Controller:
// GET: Admin/Temporada
public ActionResult TotalReserva()
{
return View();
}
// POST: Admin/Temporada
[HttpPost]
[ValidateAntiForgeryToken]
public ViewResult ValorDiaria(Temporada TotalReserva)
{
var dChegada = new DateTime(Chegada);
var dSaida = new DateTime(Saida);
var vlrdiaria = 0;
for (var curData = dChegada; curDate < dSaida; curDate = curDate.AddDays(1))
{
vlrdiaria += Convert.ToInt32(ValorDiaria(curDate));
}
return View(TotalReserva);
}
private ViewResult View(Func<ViewResult> ValorDiaria)
{
throw new NotImplementedException();
}
public static int ValrDiaria(DateTime Date)
{
var temporada = new List<Temporada>();
foreach (var temporada in temporadas)
if (temporada.ContainsDate(Date))
{
if (Date.DayOfWeek == DayOfWeek.Sexta) || (Date.DayOfWeek == DayOfWeek.Sexta)
{
return Convert.ToInt32(temporada.DiariaSabado);
}
else
{
return Convert.ToInt32(temporada.DiariaTemporada);
}
}
return Convert.ToInt32(temporada.DiariaBasica;
}