问题描述
p
公共课程预订
  {
$
      [Key]
      public int ReservationID {get;组; }¥b $ b       [必填]
      [StringLength(50,ErrorMessage =" {0}必须至少{2}个字符长",MinimumLength = 3)]¥b $ b       [显示(姓名="客户名称)]]¥b $ b       public string CustomerName {get;组; }¥b $ b     [范围(000000001,int.MaxValue,ErrorMessage ="客户护照必须为正数)")
      public int CustomerPassport {get;组; }¥b $ b       [EmailAddress] [显示(姓名="电子邮件")]
      public string CustomerEmail {get;组; }
      [DataType(DataType.Date)]
$
     公共日期时间? BirthDate {get;组; }
      [DataType(DataType.Date)]
      [EntranceDate]
      [DateGreaterThan(" LeaveDate")]
$
     公共日期时间? EntranceDate {get;组; }  
      [DataType(DataType.Date)]
$
      public DateTime LeaveDate {get;组; }¥b $ b       public string HotelName {get;组; }
  }
公共类城市
  {
      [Key]
      public int CityID {get;组; }¥b $ b       [必需] [StringLength(50,ErrorMessage =" {0}必须至少{2}个字符。",MinimumLength = 3)]
    [显示(姓名="城市名称)]
&NBSP; &NBSP; &NBSP; public string CityName {get;组; }¥b $ b &NBSP; &NBSP; &NBSP; public virtual ICollection< Hotels>酒店{get;组; }¥b $ b &NBSP; }
公共舱酒店
&NBSP; {
&NBSP; &NBSP; &NBSP; [Key]
&NBSP; &NBSP; &NBSP; public int HotelID {get;组; }¥b $ b &NBSP; &NBSP; &NBSP; [必填]
&NBSP; &NBSP; &NBSP; [StringLength(50,ErrorMessage =" {0}必须至少{2}个字符。",MinimumLength = 3)]
&NBSP; &NBSP; &NBSP; public string HotelName {get;组; }¥b $ b &NBSP; &NBSP; &NBSP; public string CityName {get;组; }¥b $ b &NBSP; &NBSP; &NBSP;公共虚拟ICollection< Reservations>预订{get;组; }
&NBSP; }
公共类TravelContext:DbContext
&NBSP; {
&NBSP; &NBSP; &NBSP; public TravelContext()
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; :base("TravelContext")
&NBSP; &NBSP; &NBSP; {
$
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; public DbSet< Cities>城市{get; set;}
&NBSP; &NBSP; public DbSet< Hotels>酒店{get;组; }¥b $ b &NBSP; &NBSP; public DbSet< Reservations>预订{get;组; }
&NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;
公共类TravelDbInitializer:DropCreateDatabaseAlways< TravelContext>
&NBSP; {
&NBSP; &NBSP; &NBSP; protected override void Seed(TravelContext context)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; base.Seed(context);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;城市city1 =新城市¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName =" London",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;城市city2 =新城市¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName =" Seatle",
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;城市city3 =新城市¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName =" New York",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;城市city4 =新城市¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName =" Manchester",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;酒店hotel1 =新酒店
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName =" QueenSheeba",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName = city1.CityName
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;酒店hotel2 =新酒店
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName =" PalmBeach",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName = city2.CityName
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;酒店hotel3 =新酒店
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName =" DeadSeaResort",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName = city3.CityName
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;酒店hotel4 =新酒店
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName =" MayamiBeach",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CityName = city4.CityName
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;预订booking1 =新预订
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerName =" Michael Weisberg",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerEmail =" [email protected]" ;,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerPassport = 345678,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName = hotel1.HotelName,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BirthDate = new DateTime(1986,10,30),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; EntranceDate = new DateTime(2016,12,20),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; LeaveDate = new DateTime(2016,12,25),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;预订reservation2 =新预订
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerName =" Moshe Yachelson",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerEmail =" [email protected]",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerPassport = 123456,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;酒店名称= hotel2.HotelName,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BirthDate = new DateTime(1988,05,15),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; EntranceDate = new DateTime(2016,09,20),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; LeaveDate = new DateTime(2016,09,23)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;预订预订3 =新预订
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerName =" John McDonald",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerEmail =" [email protected]" ;,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerPassport = 12345,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName = hotel3.HotelName,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BirthDate = new DateTime(1990,10,5),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; EntranceDate = new DateTime(2015,12,29),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; LeaveDate = new DateTime(2016,01,01)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;预订预订4 =新预订
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerName =" ElishevaKogan",
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerEmail =" [email protected]" ;,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; CustomerPassport = 45678,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; HotelName = hotel4.HotelName,
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; BirthDate = new DateTime(1980,12,01),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; EntranceDate = new DateTime(2015,11,01),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; LeaveDate = new DateTime(2015,11,04),
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; };
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Cities.Add(city1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Cities.Add(city2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Cities.Add(city3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Cities.Add(city4);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Hotels.Add(hotel1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Hotels.Add(hotel2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Hotels.Add(hotel3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Hotels.Add(hotel4);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Reservations.Add(reservation1);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Reservations.Add(reservation2);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Reservations.Add(reservation3);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.Reservations.Add(reservation4);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; context.SaveChanges();
&NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; }
public class EntranceDateAttribute:ValidationAttribute
&NBSP; {
$
&NBSP; &NBSP; &NBSP;公开覆盖bool IsValid(对象值)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DateTime dateStart =(DateTime)值;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; //会议必须在将来开始。
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return(dateStart> DateTime.Now.AddDays(-1));
&NBSP; &NBSP; &NBSP; }
公共类DateGreaterThanAttribute:ValidationAttribute
&NBSP; {
$
&NBSP; &NBSP; &NBSP; public DateGreaterThanAttribute(string dateToCompareToFieldName)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DateToCompareToFieldName = dateToCompareToFieldName;
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP;私有字符串DateToCompareToFieldName {get;组; }
&NBSP; &NBSP; &NBSP; protected override ValidationResult IsValid(object value,ValidationContext validationContext)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DateTime earlyDate =(DateTime)值;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; DateTime laterDate =(DateTime)validationContext.ObjectType.GetProperty(DateToCompareToFieldName).GetValue(validationContext.ObjectInstance,null);
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(laterDate> earlyDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回ValidationResult.Success;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;否则
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回新的ValidationResult("日期不晚于");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; }
公共类AddNewReservations:预订
&NBSP; {
&NBSP; &NBSP; &NBSP; public virtual ICollection< Hotels>酒店{get;组; }¥b $ b &NBSP; &NBSP; &NBSP; public IEnumerable< SelectListItem> HotelItems
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; get {return new SelectList(Hotels," HotelName"," HotelName"); }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; }
公共类AddNewHotels:酒店
&NBSP; {
$
&NBSP; &NBSP; &NBSP;公共虚拟ICollection< Cities>城市{get;组; }¥b $ b &NBSP; &NBSP; &NBSP; public IEnumerable< SelectListItem> CityItems
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; get {return new SelectList(Cities," CityName"," CityName"); }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; }
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP;
公共类HomeController:控制器
&NBSP; {
&NBSP; &NBSP; &NBSP; // GET:首页
&NBSP; &NBSP; &NBSP;公共ActionResult指数()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看();
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP;公共ViewResult AddHotel()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; AddNewHotels newHotel = new AddNewHotels();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var citiesList = db.Cities.ToList();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(citiesList!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; newHotel.Cities = citiesList;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 返回查看(newHotel);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
$
&NBSP; &NBSP; &NBSP; public ViewResult AddCity()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看();
&NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; [HttpPost]
&NBSP; &NBSP; &NBSP;公共ActionResult AddCity(城市)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(city!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var checkCity = db.Cities.Where(x => x.CityName == city.CityName).FirstOrDefault();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(checkCity == null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; db.Cities.Add(city);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; db.SaveChanges();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return RedirectToAction(" ShowCities");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; [HttpPost]
&NBSP; &NBSP; &NBSP;公共ActionResult AddHotel(AddNewHotels酒店)
&NBSP; &NBSP; &NBSP; {
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(hotel!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var checkHotel = db.Hotels.Where(x => x.HotelName == hotel.HotelName).FirstOrDefault();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(checkHotel == null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; db.Hotels.Add(hotel);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; db.SaveChanges();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return RedirectToAction(" ShowHotels");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; public ActionResult AddReservation()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; AddNewReservations newReservation = new AddNewReservations();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var hotelsList = db.Hotels.ToList();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(hotelsList!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; newReservation.Hotels = hotelsList;
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View(newReservation);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; [HttpPost]
&NBSP; &NBSP; &NBSP; public ActionResult AddReservation(AddNewReservations预订)
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(reservation!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var checkReservation = db.Reservations.Where(x => x.ReservationID == reservation.ReservationID).FirstOrDefault();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(checkReservation == null&& ModelState.IsValid)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; db.Reservations.Add(预订);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; db.SaveChanges();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 返回RedirectToAction(" ShowReservations");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; 返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; }
$
&NBSP; &NBSP; &NBSP;公共ActionResult ShowCities()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var citiesList = db.Cities.ToList< Cities>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(citiesList!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View(citiesList);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; public ActionResult ShowHotels()
&NBSP; &NBSP; &NBSP; {
$
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var hotels = db.Hotels.ToList< Hotels>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(hotels!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看(酒店);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; public ActionResult ShowReservations()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var reservations = db.Reservations.ToList< Reservations>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(预订!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看(预订);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回查看("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; public ActionResult SortHotelByCity()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var hotelList = db.Hotels.ToList< Hotels>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(hotelList!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var newList = hotelList.OrderBy(s => s.CityName);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View(" ShowHotels",newList);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回视图("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP;公共ActionResult SortHotelByHotel()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var hotelList = db.Hotels.ToList< Hotels>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; if(hotelList!= null)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var newList = hotelList.OrderBy(s => s.HotelName);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View(" ShowHotels",newList);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;返回视图("错误");
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; public ActionResult SortReservationByCustomer()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var reservList = db.Reservations.ToList< Reservations>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var newList = reservList.OrderBy(s => s.CustomerName);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View("ShowReservations",newList);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; public ActionResult SortReservationByHotel()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var reservList = db.Reservations.ToList< Reservations>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var newList = reservList.OrderBy(s => s.HotelName);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View("ShowReservations",newList);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; &NBSP; &NBSP; public ActionResult SortReservationByDate()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP;使用(var db = new TravelContext())
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var reservList = db.Reservations.ToList< Reservations>();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; var newList = reservList.OrderBy(s => s.EntranceDate);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; return View("ShowReservations",newList);
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; &NBSP; &NBSP; }
&NBSP; }
&NBSP;
@model Travel.Models.Cities
@ {
&NBSP; ViewBag.Title =" AddCity"; $
}
@using(Html.BeginForm(" AddCity"," Home",FormMethod.Post,new {@ class =" form-horizontal",role =" form"})))
{
&NBSP; @ Html.AntiForgeryToken()
&NBSP; < div class =" form-horizontal">
&NBSP; &NBSP; &NBSP; < hr />
&NBSP; &NBSP; &NBSP; @ Html.ValidationSummary(true,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; @ Html.HiddenFor(model => model.CityID)
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.CityName,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.CityName,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.CityName,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-offset-2 col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < input type =" submit"值= QUOT; AddCity" class =" btn btn-default" />
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; < / div>
}
< div>
&NBSP; @ Html.ActionLink(" Back to Main"," Index")
< / div>
&NBSP;&NBSP;
@model Travel.Models.AddNewHotels
@ {
&NBSP; ViewBag.Title =" AddHotel"; $
}
@using(Html.BeginForm(" AddHotel"," Home",FormMethod.Post,new {@ class =" form-horizontal",role =" form"})))
{
&NBSP; @ Html.AntiForgeryToken()
&NBSP; < div class =" form-horizontal">
&NBSP; &NBSP; &NBSP; < hr />
&NBSP; &NBSP; &NBSP; @ Html.ValidationSummary(true,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; @ Html.HiddenFor(model => model.HotelID)
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.HotelName,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.HotelName,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.HotelName,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.CityName,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DropDownListFor(m => m.CityName,Model.CityItems)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.CityName,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-offset-2 col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < input type =" submit"值= QUOT; AddHotel" class =" btn btn-default" />
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; < / div>
}
< div>
&NBSP; @ Html.ActionLink(" Back to Main"," Index")
< / div>
&NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP;
@model Travel.Models.AddNewReservations
@ {
Layout ="〜/ Views / Shared / _Layout.cshtml"; $
&NBSP; ViewBag.Title =" AddReservation";
}
@using(Html.BeginForm(" AddReservation"," Home",FormMethod.Post,new {@ class =" form-horizontal",role =" form"})))
{
&NBSP; @ Html.AntiForgeryToken()
&NBSP; < div class =" form-horizontal">
&NBSP; &NBSP; &NBSP; < hr />
&NBSP; &NBSP; &NBSP; @ Html.ValidationSummary(true,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; @ Html.HiddenFor(model => model.ReservationID)
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.CustomerName,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.CustomerName,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.CustomerName,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.CustomerPassport,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.CustomerPassport,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.CustomerPassport,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.CustomerEmail,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.CustomerEmail,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.CustomerEmail,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.BirthDate,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.BirthDate,new {htmlAttributes = new {@class =" form-control datecontrol",@ PryHolder ="输入出生日期}}})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.BirthDate,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.EntranceDate,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.EntranceDate,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.EntranceDate,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.LeaveDate,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.EditorFor(model => model.LeaveDate,new {htmlAttributes = new {@class =" form-control"}}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.LeaveDate,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.LabelFor(model => model.HotelName,htmlAttributes:new {@class =" control-label col-md-2"})
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DropDownListFor(m => m.HotelName,Model.HotelItems)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ValidationMessageFor(model => model.HotelName,"",new {@class =" text-danger"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < div class =" form-group">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" col-md-offset-2 col-md-10">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ * 什么是价值?* @¥b $ b &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < input type =" submit"值= QUOT; AddReservation" class =" btn btn-default" />
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; < / div>
}
< div>
&NBSP; @ Html.ActionLink(" Back to Main"," Index")
< / div>
@ {
&NBSP; Layout ="〜/ Views / Shared / _Layout.cshtml";
&NBSP; }
<!DOCTYPE html>
< html>
< head>
&NBSP; < meta name =" viewport"含量="宽度=设备宽度" />
&NBSP; < title>错误< / title>
< / head>
< body>
&NBSP; < div>
&NBSP; &NBSP; &NBSP; < h1 class =" text-danger">错误。< / h1>
&NBSP; &NBSP; &NBSP; < h2 class =" text-danger">处理您的请求时出错。请检查您的数据< / h2>
&NBSP; < / div>
< / body>
< / html>
@ {
&NBSP; ViewBag.Title =" Index";
}
< h2>欢迎来到HotelApp!请从菜单中选择< / h2>
@model IEnumerable< Travel.Models.Cities>
@using System.Web.Mvc
< div>
&NBSP; < h4>所有城市< / h4>
&NBSP; < hr />
&NBSP; @foreach(模特中的var项目)
&NBSP; {
&NBSP; &NBSP; &NBSP; < dl class =" dl-horizontal">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.CityName)
&NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.CityName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; < / dl>
&NBSP; }
< / div>
< div> @ Html.ActionLink(" Back to Main"," Index")< / div>
&NBSP;
@model IEnumerable< Travel.Models.Hotels>
@using System.Web.Mvc
< div>
&NBSP; < h4>所有酒店< / h4>
&NBSP; @ Html.ActionLink("按城市排序","SortHotelByCity","主页")|
&NBSP; @ Html.ActionLink("Sort By Hotel","SortHotelByHotel","Home")
&NBSP; < hr />
&NBSP; @foreach(模特中的var项目)
&NBSP; {
&NBSP; &NBSP; &NBSP; < dl class =" dl-horizontal">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.HotelName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.HotelName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.CityName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.CityName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
$
&NBSP; &NBSP; &NBSP; < / dl>
&NBSP; }
< / div>
< div> @ Html.ActionLink(" Back to Main"," Index")< / div>
@model IEnumerable< Travel.Models.Reservations>
@using System.Web.Mvc
< div>
&NBSP; < h4>所有预订< / h4>
&NBSP; @ Html.ActionLink("Sort By Hotel","SortReservationByHotel","Home")|
&NBSP; @ Html.ActionLink("按日期排序","SortReservationByDate","主页")|
&NBSP; @ Html.ActionLink(" Sort By Customer"," SortReservationByCustomer"," Home")
&NBSP; < hr />
&NBSP; @foreach(模特中的var项目)
&NBSP; {
&NBSP; &NBSP; &NBSP; < dl class =" dl-horizontal">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.CustomerName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.CustomerName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.CustomerPassport)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.CustomerPassport)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.CustomerEmail)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.CustomerEmail)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.BirthDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.BirthDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.EntranceDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.EntranceDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.LeaveDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.LeaveDate)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayNameFor(model => model.HotelName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / dt>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < dd>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.DisplayFor(model => item.HotelName)
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / DD> &NBSP; &NBSP; &NBSP; &NBSP;
&NBSP; &NBSP; &NBSP; < / dl>
&NBSP; }
< / div>
< div> @ Html.ActionLink(" Back to Main"," Index")< / div>
&NBSP;&NBSP; &NBSP;
<!DOCTYPE html>
< html>
< head>
&NBSP; < meta charset =" utf-8" />
&NBSP; < meta name =" viewport" content =" width = device-width,initial-scale = 1.0">
&NBSP; < title> @ ViewBag.Title - 我的ASP.NET应用程序< / title>
&NBSP; < link href ="〜/ Content / Site.css"的rel ="样式表"类型= QUOT;文本/ CSS" />
&NBSP; < link href ="〜/ Content / bootstrap.min.css"的rel ="样式表"类型= QUOT;文本/ CSS" />
$
< / head>
< body>
&NBSP; < div class =" navbar navbar-inverse navbar-fixed-top">
&NBSP; &NBSP; &NBSP; < div class =" container">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" navbar-header">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < button type =" button"类= QUOT;导航栏肘节"数据肘节= QUOT;折叠和QUOT; data-target =" .navbar-collapse">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < span class =" icon-bar">< / span>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < span class =" icon-bar">< / span>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < span class =" icon-bar">< / span>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / button>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ActionLink(" AddHotel"," AddHotel"," Home",new {area =""},new {@class =" navbar-brand"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ActionLink(" AddReservation"," AddReservation"," Home",new {area =""},new {@class =" navbar-brand"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ActionLink(" AddCity"," AddCity"," Home",new {area =""},new {@class =" navbar-brand"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ActionLink(" ShowHotels"," ShowHotels"," Home",new {area =""},new {@class =" navbar-brand"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ActionLink(" ShowCities"," ShowCities"," Home",new {area =""},new {@class =" navbar-brand"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; @ Html.ActionLink(" ShowReservations"," ShowReservations"," Home",new {area =""},new {@class =" navbar-brand"}))
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < div class =" navbar-collapse collapse">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < ul class =" nav navbar-nav">
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / ul>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < / div>
&NBSP; &NBSP; &NBSP; < / div>
&NBSP; < / div>
&NBSP; < div class =" container body-content">
&NBSP; &NBSP; &NBSP; @RenderBody()
&NBSP; &NBSP; &NBSP; < hr />
&NBSP; &NBSP; &NBSP; < footer>
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; < p为H.;&安培;副本; @ DateTime.Now.Year - Refael Kogan< / p>
&NBSP; &NBSP; &NBSP; < / footer>
&NBSP; < / div>
&NBSP; < script src ="〜/ Scripts / modernizr-2.6.2.js">< / script>
&NBSP; < script src ="〜/ Scripts / jquery-ui.unobtrusive.js">< / script>
&NBSP; < script src ="〜/ Scripts / jquery-1.10.2.min.js">< / script>
&NBSP; < script src ="〜/ Scripts / bootstrap.min.js">< / script>
&NBSP; < script src ="〜/ Scripts / locales / bootstrap-datepicker.en-GB.min.js">< / script>
< / body>
< / html>
公共类MvcApplication:System.Web.HttpApplication
&NBSP; {
&NBSP; &NBSP; &NBSP; protected void Application_Start()
&NBSP; &NBSP; &NBSP; {
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; Database.SetInitializer< TravelContext>(new TravelDbInitializer());
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; AreaRegistration.RegisterAllAreas();
&NBSP; &NBSP; &NBSP; &NBSP; &NBSP; RouteConfig.RegisterRoutes(RouteTable.Routes);
&NBSP; &NBSP; &NBSP; }¥b $ b &NBSP; }
< connectionStrings>
&NBSP; < add name =" TravelContext" connectionString =" Data Source =(LocalDb)\ v11.0; AttachDbFilename = | DataDirectory | \ Travelling.mdf; Integrated Security = True"的providerName = QUOT; System.Data.SqlClient的" />
$
< /&的ConnectionStrings GT;
&NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP; &NBSP;&NBSP;&NBSP; &NBSP; &NBSP; &NBSP;&NBSP; &NBSP; &NBSP;
p
public class Reservations
{
[Key]
public int ReservationID { get; set; }
[Required]
[StringLength(50,ErrorMessage="The {0} must be at least {2} characters long",MinimumLength=3)]
[Display(Name="CustomerName")]
public string CustomerName { get; set; }
[Range(000000001, int.MaxValue, ErrorMessage = "Customer Passport must be a positive number")]
public int CustomerPassport { get; set; }
[EmailAddress][Display(Name="Email")]
public string CustomerEmail { get; set; }
[DataType(DataType.Date)]
public DateTime? BirthDate { get; set; }
[DataType(DataType.Date)]
[EntranceDate]
[DateGreaterThan("LeaveDate")]
public DateTime? EntranceDate { get; set; }
[DataType(DataType.Date)]
public DateTime LeaveDate { get; set; }
public string HotelName { get; set; }
}
public class Cities
{
[Key]
public int CityID { get; set; }
[Required][StringLength(50,ErrorMessage="The {0} must be at least {2} characters long.",MinimumLength=3)]
[Display(Name="City Name")]
public string CityName { get; set; }
public virtual ICollection<Hotels> Hotels { get; set; }
}
public class Hotels
{
[Key]
public int HotelID { get; set; }
[Required]
[StringLength(50, ErrorMessage = "The {0} must be at least {2} characters long.", MinimumLength = 3)]
public string HotelName { get; set; }
public string CityName { get; set; }
public virtual ICollection<Reservations> Reservations { get; set; }
}
public class TravelContext:DbContext
{
public TravelContext()
: base("TravelContext")
{
}
public DbSet<Cities> Cities{get;set;}
public DbSet<Hotels> Hotels { get; set; }
public DbSet<Reservations> Reservations { get; set; }
}
public class TravelDbInitializer:DropCreateDatabaseAlways<TravelContext>
{
protected override void Seed(TravelContext context)
{
base.Seed(context);
Cities city1 = new Cities
{
CityName = "London",
};
Cities city2 = new Cities
{
CityName = "Seatle",
};
Cities city3 = new Cities
{
CityName = "New York",
};
Cities city4 = new Cities
{
CityName = "Manchester",
};
Hotels hotel1 = new Hotels
{
HotelName = "QueenSheeba",
CityName = city1.CityName
};
Hotels hotel2 = new Hotels
{
HotelName = "PalmBeach",
CityName = city2.CityName
};
Hotels hotel3 = new Hotels
{
HotelName = "DeadSeaResort",
CityName = city3.CityName
};
Hotels hotel4 = new Hotels
{
HotelName = "MayamiBeach",
CityName = city4.CityName
};
Reservations reservation1 = new Reservations
{
CustomerName = "Michael Weisberg",
CustomerEmail = "[email protected]",
CustomerPassport = 345678,
HotelName = hotel1.HotelName,
BirthDate = new DateTime(1986, 10, 30),
EntranceDate = new DateTime(2016, 12, 20),
LeaveDate = new DateTime(2016, 12, 25),
};
Reservations reservation2 = new Reservations
{
CustomerName = "Moshe Yachelson",
CustomerEmail = "[email protected]",
CustomerPassport = 123456,
HotelName = hotel2.HotelName,
BirthDate = new DateTime(1988, 05, 15),
EntranceDate = new DateTime(2016, 09, 20),
LeaveDate = new DateTime(2016, 09, 23)
};
Reservations reservation3 = new Reservations
{
CustomerName = "John McDonald",
CustomerEmail = "[email protected]",
CustomerPassport = 12345,
HotelName = hotel3.HotelName,
BirthDate = new DateTime(1990, 10, 5),
EntranceDate = new DateTime(2015, 12, 29),
LeaveDate = new DateTime(2016, 01, 01)
};
Reservations reservation4 = new Reservations
{
CustomerName = "ElishevaKogan",
CustomerEmail = "[email protected]",
CustomerPassport = 45678,
HotelName = hotel4.HotelName,
BirthDate = new DateTime(1980, 12, 01),
EntranceDate = new DateTime(2015, 11, 01),
LeaveDate = new DateTime(2015, 11, 04),
};
context.Cities.Add(city1);
context.Cities.Add(city2);
context.Cities.Add(city3);
context.Cities.Add(city4);
context.Hotels.Add(hotel1);
context.Hotels.Add(hotel2);
context.Hotels.Add(hotel3);
context.Hotels.Add(hotel4);
context.Reservations.Add(reservation1);
context.Reservations.Add(reservation2);
context.Reservations.Add(reservation3);
context.Reservations.Add(reservation4);
context.SaveChanges();
}
}
public class EntranceDateAttribute : ValidationAttribute
{
public override bool IsValid(object value)
{
DateTime dateStart = (DateTime)value;
// Meeting must start in the future time.
return (dateStart > DateTime.Now.AddDays(-1));
}
public class DateGreaterThanAttribute : ValidationAttribute
{
public DateGreaterThanAttribute(string dateToCompareToFieldName)
{
DateToCompareToFieldName = dateToCompareToFieldName;
}
private string DateToCompareToFieldName { get; set; }
protected override ValidationResult IsValid(object value, ValidationContext validationContext)
{
DateTime earlierDate = (DateTime)value;
DateTime laterDate = (DateTime)validationContext.ObjectType.GetProperty(DateToCompareToFieldName).GetValue(validationContext.ObjectInstance, null);
if (laterDate > earlierDate)
{
return ValidationResult.Success;
}
else
{
return new ValidationResult("Date is not later");
}
}
}
public class AddNewReservations:Reservations
{
public virtual ICollection<Hotels> Hotels { get; set; }
public IEnumerable<SelectListItem> HotelItems
{
get { return new SelectList(Hotels, "HotelName", "HotelName"); }
}
}
public class AddNewHotels:Hotels
{
public virtual ICollection<Cities> Cities { get; set; }
public IEnumerable<SelectListItem> CityItems
{
get { return new SelectList(Cities, "CityName", "CityName"); }
}
}
public class HomeController : Controller
{
// GET: Home
public ActionResult Index()
{
return View();
}
public ViewResult AddHotel()
{
using (var db = new TravelContext())
{
AddNewHotels newHotel = new AddNewHotels();
var citiesList = db.Cities.ToList();
if (citiesList!=null)
{
newHotel.Cities = citiesList;
return View(newHotel);
}
return View("Error");
}
}
public ViewResult AddCity()
{
return View();
}
[HttpPost]
public ActionResult AddCity(Cities city)
{
using (var db = new TravelContext())
{
if (city != null)
{
var checkCity = db.Cities.Where(x => x.CityName == city.CityName).FirstOrDefault();
if (checkCity == null)
{
db.Cities.Add(city);
db.SaveChanges();
return RedirectToAction("ShowCities");
}
return View("Error");
}
return View("Error");
}
}
[HttpPost]
public ActionResult AddHotel(AddNewHotels hotel)
{
using (var db = new TravelContext())
{
if (hotel != null)
{
var checkHotel = db.Hotels.Where(x => x.HotelName == hotel.HotelName).FirstOrDefault();
if (checkHotel == null)
{
db.Hotels.Add(hotel);
db.SaveChanges();
return RedirectToAction("ShowHotels");
}
return View("Error");
}
return View("Error");
}
}
public ActionResult AddReservation()
{
using (var db = new TravelContext())
{
AddNewReservations newReservation = new AddNewReservations();
var hotelsList = db.Hotels.ToList();
if (hotelsList!=null)
{
newReservation.Hotels = hotelsList;
return View(newReservation);
}
return View("Error");
}
}
[HttpPost]
public ActionResult AddReservation(AddNewReservations reservation)
{
using (var db = new TravelContext())
{
if (reservation != null)
{
var checkReservation = db.Reservations.Where(x => x.ReservationID == reservation.ReservationID).FirstOrDefault();
if (checkReservation == null && ModelState.IsValid)
{
db.Reservations.Add(reservation);
db.SaveChanges();
return RedirectToAction("ShowReservations");
}
return View("Error");
}
return View("Error");
}
}
public ActionResult ShowCities()
{
using (var db = new TravelContext())
{
var citiesList = db.Cities.ToList<Cities>();
if (citiesList != null)
{
return View(citiesList);
}
return View("Error");
}
}
public ActionResult ShowHotels()
{
using (var db = new TravelContext())
{
var hotels = db.Hotels.ToList<Hotels>();
if (hotels != null)
{
return View(hotels);
}
return View("Error");
}
}
public ActionResult ShowReservations()
{
using (var db = new TravelContext())
{
var reservations = db.Reservations.ToList<Reservations>();
if (reservations != null)
{
return View(reservations);
}
return View("Error");
}
}
public ActionResult SortHotelByCity()
{
using (var db = new TravelContext())
{
var hotelList = db.Hotels.ToList<Hotels>();
if (hotelList!=null)
{
var newList = hotelList.OrderBy(s => s.CityName);
return View("ShowHotels", newList);
}
return View("Error");
}
}
public ActionResult SortHotelByHotel()
{
using (var db = new TravelContext())
{
var hotelList = db.Hotels.ToList<Hotels>();
if (hotelList != null)
{
var newList = hotelList.OrderBy(s => s.HotelName);
return View("ShowHotels", newList);
}
return View("Error");
}
}
public ActionResult SortReservationByCustomer()
{
using (var db = new TravelContext())
{
var reservList = db.Reservations.ToList<Reservations>();
var newList = reservList.OrderBy(s => s.CustomerName);
return View("ShowReservations", newList);
}
}
public ActionResult SortReservationByHotel()
{
using (var db = new TravelContext())
{
var reservList = db.Reservations.ToList<Reservations>();
var newList = reservList.OrderBy(s => s.HotelName);
return View("ShowReservations", newList);
}
}
public ActionResult SortReservationByDate()
{
using (var db = new TravelContext())
{
var reservList = db.Reservations.ToList<Reservations>();
var newList = reservList.OrderBy(s => s.EntranceDate);
return View("ShowReservations", newList);
}
}
}
@model Travel.Models.Cities
@{
ViewBag.Title="AddCity";
}
@using (Html.BeginForm("AddCity", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.CityID)
<div class="form-group">
@Html.LabelFor(model => model.CityName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CityName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CityName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="AddCity" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to Main", "Index")
</div>
@model Travel.Models.AddNewHotels
@{
ViewBag.Title = "AddHotel";
}
@using (Html.BeginForm("AddHotel", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.HotelID)
<div class="form-group">
@Html.LabelFor(model => model.HotelName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.HotelName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.HotelName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CityName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(m => m.CityName, Model.CityItems)
@Html.ValidationMessageFor(model => model.CityName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
<input type="submit" value="AddHotel" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to Main", "Index")
</div>
@model Travel.Models.AddNewReservations
@{
Layout="~/Views/Shared/_Layout.cshtml";
ViewBag.Title = "AddReservation";
}
@using (Html.BeginForm("AddReservation", "Home", FormMethod.Post, new { @class = "form-horizontal", role = "form" }))
{
@Html.AntiForgeryToken()
<div class="form-horizontal">
<hr />
@Html.ValidationSummary(true, "", new { @class = "text-danger" })
@Html.HiddenFor(model => model.ReservationID)
<div class="form-group">
@Html.LabelFor(model => model.CustomerName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CustomerName, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CustomerName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CustomerPassport, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CustomerPassport, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CustomerPassport, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.CustomerEmail, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.CustomerEmail, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.CustomerEmail, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.BirthDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor( model=>model.BirthDate, new{htmlAttributes = new {@class = "form-control datecontrol", @PlaceHolder = "Enter Date of Birth"}})
@Html.ValidationMessageFor(model => model.BirthDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.EntranceDate, htmlAttributes: new { @class = "control-label col-md-2"})
<div class="col-md-10">
@Html.EditorFor(model=>model.EntranceDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.EntranceDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.LeaveDate, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.EditorFor(model => model.LeaveDate, new { htmlAttributes = new { @class = "form-control" } })
@Html.ValidationMessageFor(model => model.LeaveDate, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
@Html.LabelFor(model => model.HotelName, htmlAttributes: new { @class = "control-label col-md-2" })
<div class="col-md-10">
@Html.DropDownListFor(m => m.HotelName, Model.HotelItems)
@Html.ValidationMessageFor(model => model.HotelName, "", new { @class = "text-danger" })
</div>
</div>
<div class="form-group">
<div class="col-md-offset-2 col-md-10">
@* what is value?*@
<input type="submit" value="AddReservation" class="btn btn-default" />
</div>
</div>
</div>
}
<div>
@Html.ActionLink("Back to Main", "Index")
</div>
@{
Layout ="~/Views/Shared/_Layout.cshtml";
}
<!DOCTYPE html>
<html>
<head>
<meta name="viewport" content="width=device-width" />
<title>Error</title>
</head>
<body>
<div>
<h1 class="text-danger">Error.</h1>
<h2 class="text-danger">An error occurred while processing your request. Please Check your data</h2>
</div>
</body>
</html>
@{
ViewBag.Title = "Index";
}
<h2>Welcome To HotelApp! Please choose from the menu</h2>
@model IEnumerable<Travel.Models.Cities>
@using System.Web.Mvc
<div>
<h4>All Cities</h4>
<hr />
@foreach (var item in Model)
{
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.CityName)
</dt>
<dd>
@Html.DisplayFor(model => item.CityName)
</dd>
</dl>
}
</div>
<div>@Html.ActionLink("Back to Main", "Index")</div>
@model IEnumerable<Travel.Models.Hotels>
@using System.Web.Mvc
<div>
<h4>All Hotels</h4>
@Html.ActionLink("Sort By City", "SortHotelByCity", "Home")|
@Html.ActionLink("Sort By Hotel", "SortHotelByHotel", "Home")
<hr />
@foreach (var item in Model)
{
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.HotelName)
</dt>
<dd>
@Html.DisplayFor(model => item.HotelName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CityName)
</dt>
<dd>
@Html.DisplayFor(model => item.CityName)
</dd>
</dl>
}
</div>
<div>@Html.ActionLink("Back to Main", "Index")</div>
@model IEnumerable<Travel.Models.Reservations>
@using System.Web.Mvc
<div>
<h4>All Reservations</h4>
@Html.ActionLink("Sort By Hotel", "SortReservationByHotel", "Home")|
@Html.ActionLink("Sort By Date", "SortReservationByDate", "Home")|
@Html.ActionLink("Sort By Customer", "SortReservationByCustomer", "Home")
<hr />
@foreach (var item in Model)
{
<dl class="dl-horizontal">
<dt>
@Html.DisplayNameFor(model => model.CustomerName)
</dt>
<dd>
@Html.DisplayFor(model => item.CustomerName)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CustomerPassport)
</dt>
<dd>
@Html.DisplayFor(model => item.CustomerPassport)
</dd>
<dt>
@Html.DisplayNameFor(model => model.CustomerEmail)
</dt>
<dd>
@Html.DisplayFor(model => item.CustomerEmail)
</dd>
<dt>
@Html.DisplayNameFor(model => model.BirthDate)
</dt>
<dd>
@Html.DisplayFor(model => item.BirthDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.EntranceDate)
</dt>
<dd>
@Html.DisplayFor(model => item.EntranceDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.LeaveDate)
</dt>
<dd>
@Html.DisplayFor(model => item.LeaveDate)
</dd>
<dt>
@Html.DisplayNameFor(model => model.HotelName)
</dt>
<dd>
@Html.DisplayFor(model => item.HotelName)
</dd>
</dl>
}
</div>
<div>@Html.ActionLink("Back to Main", "Index")</div>
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>@ViewBag.Title - My ASP.NET Application</title>
<link href="~/Content/Site.css" rel="stylesheet" type="text/css" />
<link href="~/Content/bootstrap.min.css" rel="stylesheet" type="text/css" />
</head>
<body>
<div class="navbar navbar-inverse navbar-fixed-top">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
@Html.ActionLink("AddHotel", "AddHotel", "Home", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("AddReservation", "AddReservation", "Home", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("AddCity", "AddCity", "Home", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("ShowHotels", "ShowHotels", "Home", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("ShowCities", "ShowCities", "Home", new { area = "" }, new { @class = "navbar-brand" })
@Html.ActionLink("ShowReservations", "ShowReservations", "Home", new { area = "" }, new { @class = "navbar-brand" })
</div>
<div class="navbar-collapse collapse">
<ul class="nav navbar-nav">
</ul>
</div>
</div>
</div>
<div class="container body-content">
@RenderBody()
<hr />
<footer>
<p>© @DateTime.Now.Year - Refael Kogan</p>
</footer>
</div>
<script src="~/Scripts/modernizr-2.6.2.js"></script>
<script src="~/Scripts/jquery-ui.unobtrusive.js"></script>
<script src="~/Scripts/jquery-1.10.2.min.js"></script>
<script src="~/Scripts/bootstrap.min.js"></script>
<script src="~/Scripts/locales/bootstrap-datepicker.en-GB.min.js"></script>
</body>
</html>
public class MvcApplication : System.Web.HttpApplication
{
protected void Application_Start()
{
Database.SetInitializer<TravelContext>(new TravelDbInitializer());
AreaRegistration.RegisterAllAreas();
RouteConfig.RegisterRoutes(RouteTable.Routes);
}
}
<add name="TravelContext" connectionString="Data Source=(LocalDb)\v11.0;AttachDbFilename=|DataDirectory|\Travelling.mdf;Integrated Security=True" providerName="System.Data.SqlClient" />
</connectionStrings>
这篇关于首先是简单的asp mvc网站代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!