Пример #1
0
        public ActionResult Create(AttractionViewModel attractionViewModel)
        {
            try
            {
                OperationService op = new OperationService();
                var attractionList  = op.GetAttractions();



                Attraction attraction = new Attraction
                {
                    Name         = attractionViewModel.Name,
                    Price        = attractionViewModel.Price,
                    AttractionId = attractionList == null || !attractionList.Any() ?
                                   "01"  : Convert.ToInt32(attractionList.Max(x => x.AttractionId)) >= 9 ? (Convert.ToInt32(attractionList.Max(x => x.AttractionId)) + 1).ToString() : $"0{Convert.ToInt32(attractionList.Max(x => x.AttractionId)) + 1}"
                };

                if (!op.SaveAttraction(attraction))
                {
                    throw new Exception();
                }

                return(RedirectToAction("Index"));
            }
            catch
            {
                return(View());
            }
        }
Пример #2
0
        // GET: Attractions
        public ActionResult Index()
        {
            OperationService op = new OperationService();
            var modelList       = op.GetAttractions();
            var returnModelList = modelList?.Select(x => new AttractionViewModel()
            {
                CreateDate   = x.CreateDate,
                Id           = x.Id,
                Price        = x.Price,
                Name         = x.Name,
                AttractionId = x.AttractionId
            }) ?? new List <AttractionViewModel>();

            return(View(returnModelList));
        }