public JsonResult Reserved(RoomSearchInput resevations, Client client) { decimal TotalPrice = CalculateSingleRooms(resevations); if (resevations.CheckInDate.Year == 1) { resevations.CheckInDate = DateTime.Now; } if (resevations.CheckOutDate.Year == 1) { resevations.CheckOutDate = Helpers.ChangeTime(resevations.CheckInDate.AddDays(1), 14, 0, 0, 0); } var reserveEntity = new Reservations { FranchPad = resevations.Bed, CheckInDate = resevations.CheckInDate, CheckOutDate = resevations.CheckOutDate, ClientFullName = client.Name + " " + client.Surname, ClientNationalNumber = "11111111111", Person = resevations.Client, RoomTypeId = resevations.RoomType, TotalPrice = TotalPrice, CreateDate = DateTime.Now }; _reservationsRepository.Insert(reserveEntity); return(Json(true)); }
public JsonResult ReservationInput(RoomSearchInput resevations) { var checkinDate = resevations.CheckInDate; var checkoutDate = Helpers.ChangeTime(resevations.CheckOutDate, 14, 0, 0, 0); var model = CalculateRooms(checkinDate, checkoutDate, resevations.Client, resevations.Bed); return(Json(model)); }
private decimal CalculateSingleRooms(RoomSearchInput roomSearch) { if (roomSearch.CheckInDate.Year == 1) { roomSearch.CheckInDate = DateTime.Now; } if (roomSearch.CheckOutDate.Year == 1) { roomSearch.CheckOutDate = Helpers.ChangeTime(roomSearch.CheckInDate.AddDays(1), 14, 0, 0, 0); } var model = new ReservationViewModel(); var rooms = _roomTypesRepository.TableNoTracking.Include(x => x.RoomPrice).ToList(); int dayCount = (int)Math.Floor(roomSearch.CheckOutDate.Subtract(roomSearch.CheckInDate).TotalHours / 24); var days = GetDaysBetween(roomSearch.CheckInDate, roomSearch.CheckOutDate); int normalDayCount = dayCount - days.Count(); foreach (var item in rooms.Where(x => x.id == roomSearch.RoomType).ToList()) { var room = new RoomViewModel(); room.RoomType = item; room.Person = roomSearch.Client; room.ExtraBed = roomSearch.Client > 0 ? roomSearch.Bed : 0; foreach (var day in days.Take(days.Count() - 1).ToList()) { var roomprice = item.RoomPrice.LastOrDefault().RoomPrice1; if (day.DayOfWeek == DayOfWeek.Friday || day.DayOfWeek == DayOfWeek.Saturday) { if (roomSearch.Client == 1) { roomprice = roomprice * Convert.ToDecimal(1.3); roomprice = roomprice - (roomprice * Convert.ToDecimal(0.3)); } else { if (roomSearch.Bed == 0) { roomprice = roomprice * Convert.ToDecimal(1.3); } else { roomprice = (roomprice * Convert.ToDecimal(1.3)) * Convert.ToDecimal(1.2); } } room.ReservationDays.Add(new ReservationDays { Date = day, Price = roomprice }); } else { if (roomSearch.Client == 1) { roomprice = roomprice - (roomprice * Convert.ToDecimal(0.3)); } else { if (roomSearch.Bed > 0) { roomprice = roomprice * Convert.ToDecimal(1.2); } } room.ReservationDays.Add(new ReservationDays { Date = day, Price = roomprice }); } } room.TotalPrice = room.ReservationDays.Sum(s => s.Price); model.RoomTypes.Add(room); } return(model.RoomTypes.FirstOrDefault().TotalPrice); }