예제 #1
0
        //
        // GET: /AdventureReview/Create
        public ActionResult Create()
        {
            var model = new AdventureReviewModel();

            var adventureTypeList = AdventureTypeRepository.GetAdventureTypes();
            //adventureTypeList.Insert(0, new AdventureType(){Name = "-Select Adventure Type-"});
            model.SelectableTypes = adventureTypeList;

            return View(model);
        }
예제 #2
0
        public ActionResult Create(AdventureReviewModel adventurereview, FormCollection formCollection)
        {
            var adventureTypeList = AdventureTypeRepository.GetAdventureTypes();
            var adventureType = adventureTypeList.FirstOrDefault(t => t.Id == adventurereview.AdventureTypeId);

            adventurereview.Review.AdventureType = adventureType;

            if (ModelState.IsValid)
            {
                GetDataCardsFromFormCollection(adventurereview, formCollection);

                var review = AdventureReviewRepository.SaveAdventureReview(adventurereview.Review);

                return RedirectToAction("Details",new {review.Id});
            }

            return View(adventurereview);
        }
예제 #3
0
        private static void GetDataCardsFromFormCollection(AdventureReviewModel adventurereview, FormCollection formCollection)
        {
            for (int i = 0; i < adventurereview.DataCardCount; i++)
            {
                var title =
                    formCollection.GetValue(string.Format("dataCardTitle{0}", i)).AttemptedValue;

                var body = formCollection.GetValue(string.Format("dataCardBody{0}", i)).AttemptedValue;

                if (!string.IsNullOrEmpty(title) && !string.IsNullOrEmpty(body))
                {
                    adventurereview.Review.DataCards.Add(new AdventureDataCard { Title = title, Body = body });
                }
            }
        }