// public async Task<IActionResult> Create([Bind("RoomId,HotelId,RoomName,MaxOccupancy,NetRate,SellRate,CurrencyId")] Room room) public IActionResult Create(vmRoom ovmRoom, string[] amenitiesChecked ) { bool bIsSuccess = false; Hotel oHotel = _context.Hotel .Include(r => r.Rooms).Where(w => w.HotelId == ovmRoom.oRoom.HotelId).FirstOrDefault(); if (oHotel.Rooms.Count() >= 2) { ModelState.AddModelError("oRoom.HotelId", "Maximum limit 5 rooms for 1 hotel."); } if (ModelState.IsValid) { using (var oTrans = _context.Database.BeginTransaction()) { try { _context.Add(ovmRoom.oRoom); _context.SaveChanges(); foreach (string Amenities in amenitiesChecked) { RoomAmenities oRoomAmenities = new RoomAmenities(); oRoomAmenities.RoomId = ovmRoom.oRoom.RoomId; oRoomAmenities.AmenitiesId = Convert.ToInt32(Amenities); _context.Add(oRoomAmenities); _context.SaveChanges(); } bIsSuccess = true; } catch (Exception Ex) { oTrans.Rollback(); } finally { if (bIsSuccess) { oTrans.Commit(); } } } } return(RedirectToAction(nameof(Index))); }
public async Task <IActionResult> Create([Bind("CurrencyId,CurrencyCode,CurrencyName,IsActive")] Currency currency) { if (ModelState.IsValid) { _context.Add(currency); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(currency)); }
public async Task <IActionResult> Create([Bind("RoomAmenitiesId,RoomId,AmenitiesId")] RoomAmenities roomAmenities) { if (ModelState.IsValid) { _context.Add(roomAmenities); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(roomAmenities)); }
public async Task <IActionResult> Create([Bind("AmenitiesId,AmenitiesName,IsActive")] Amenities amenities) { if (ModelState.IsValid) { _context.Add(amenities); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(amenities)); }
public async Task <IActionResult> Create([Bind("HotelId,HotelName,Address,Latitude,Longitude,CommissionRate")] Hotel hotel, string[] RoomId ) { if (ModelState.IsValid) { _context.Add(hotel); await _context.SaveChangesAsync(); return(RedirectToAction(nameof(Index))); } return(View(hotel)); }
// public async Task<IActionResult> Create([Bind("BookingRoomId,BookingCode,ClientId,RoomId,CheckInDate,CheckOutDate,UniqueCode")] BookingRoom bookingRoom) public async Task <IActionResult> Create(BookingRoom p_oBookingRoom) { bool bIsSuccess = false; #region Validation if (p_oBookingRoom.CheckOutDate <= p_oBookingRoom.CheckInDate) { ModelState.AddModelError("CheckOutDate", "Check out date must more bigger than check in date"); } #endregion if (ModelState.IsValid) { // _context.Add(p_oBookingRoom); // await _context.SaveChangesAsync(); // return RedirectToAction(nameof(Index)); using (var oTrans = _context.Database.BeginTransaction()) { try { p_oBookingRoom.BookingCode = DateTime.Now.ToString("yyyyMMddhhmmssfff"); p_oBookingRoom.UniqueCode = RandomString(7, false); _context.Add(p_oBookingRoom); await _context.SaveChangesAsync(); bIsSuccess = true; } catch (Exception Ex) { oTrans.Rollback(); } finally { if (bIsSuccess) { oTrans.Commit(); } } } } if (bIsSuccess) { return(RedirectToAction(nameof(Index))); } return(View(p_oBookingRoom)); }