コード例 #1
0
 public ActionResult Create()
 {
     var model = new HotelCreateModel()
     {
         Boss = new BossCreateModel()
     };
     return View(model);
 }
コード例 #2
0
        public ActionResult Create(HotelCreateModel model)
        {
            bool allEmpty = string.IsNullOrEmpty(model.Boss?.FirstName) &&
                            string.IsNullOrEmpty(model.Boss?.SecondName) &&
                            string.IsNullOrEmpty(model.Boss?.MiddleName) &&
                            string.IsNullOrEmpty(model.Boss?.IndividualId);
            bool allFilled = !string.IsNullOrEmpty(model.Boss?.FirstName) &&
                             !string.IsNullOrEmpty(model.Boss.SecondName) &&
                             !string.IsNullOrEmpty(model.Boss.MiddleName) &&
                             !string.IsNullOrEmpty(model.Boss.IndividualId);

            if (!allEmpty && !allFilled)
                return View(model);

            if (ModelState.IsValid)
            {
                var hotel = _hotelCreateCommand.Execute(model);
                return RedirectToAction("Details", new {id = hotel.Id});
            }
            return View(model);
        }