Beispiel #1
0
        public ActionResult Save(Date date)
        {
            if (!ModelState.IsValid)
            {
                var viewModel = new DateFormViewModel
                {
                    Date            = date,
                    RestaurantTypes = _context.RestaurantTypes.ToList(),
                    Zipcodes        = _context.Zipcodes.ToList(),
                    DatePrices      = _context.DatePrices.ToList(),
                    DateTimeOfDays  = _context.DateTimeOfDays.ToList(),
                    DateTypes       = _context.DateTypes.ToList(),
                };

                return(View("MainDateForm", viewModel));
            }

            if (date.Id == 0)
            {
                _context.Dates.Add(date);
            }
            else
            {
                var dateInDb = _context.Dates.Single(c => c.Id == date.Id);

                /*TryUpdateModel(customerInDb); */  //Malicious users can mess-up database
                dateInDb.DayOfDate = date.DayOfDate;
                dateInDb.DateName  = date.DateName;
                dateInDb.StreetOne = date.StreetOne;
                dateInDb.StreetTwo = date.StreetTwo;
                dateInDb.ZipcodeId = date.ZipcodeId;
                dateInDb.willEat   = date.willEat;
                //dateInDb.IsActive = date.IsActive;
                //dateInDb.IsChatty = date.IsChatty;
                //dateInDb.IsArtsy = date.IsArtsy;
                dateInDb.RestaurantTypeId = date.RestaurantTypeId;
                dateInDb.DateTimeOfDayId  = date.DateTimeOfDayId;
                dateInDb.DatePriceId      = date.DatePriceId;
                dateInDb.DateTypeId       = date.DateTypeId;
                //Or use AutoMapper
            }
            _context.SaveChanges();
            return(RedirectToAction("Details", date));
        }
Beispiel #2
0
        public ActionResult New()
        {
            var dateTypes       = _context.DateTypes.ToList();
            var restaurantTypes = _context.RestaurantTypes.ToList();
            var dateTimeOfDays  = _context.DateTimeOfDays.ToList();
            var zipcodes        = _context.Zipcodes.ToList();
            var datePrices      = _context.DatePrices.ToList();
            var viewModel       = new DateFormViewModel
            {
                Date = new Date(),

                RestaurantTypes = restaurantTypes,
                DatePrices      = datePrices,
                DateTimeOfDays  = dateTimeOfDays,
                Zipcodes        = zipcodes,
                DateTypes       = dateTypes,
            };

            return(View("MainDateForm", viewModel));
        }
Beispiel #3
0
        public ActionResult Edit(int id)
        {
            var date = _context.Dates.SingleOrDefault(c => c.Id == id);

            if (date == null)
            {
                return(HttpNotFound());
            }
            var viewModel = new DateFormViewModel
            {
                Date            = date,
                RestaurantTypes = _context.RestaurantTypes,
                Zipcodes        = _context.Zipcodes,
                DatePrices      = _context.DatePrices,
                DateTimeOfDays  = _context.DateTimeOfDays,
                DateTypes       = _context.DateTypes,
            };

            return(View("MainDateForm", viewModel));
        }