public ActionResult Create(SavedRideCreate model)
        {
            if (!ModelState.IsValid)
            {
                return(View(model));
            }

            if (CreateSavedRideService().CreateSavedRide(model))
            {
                TempData["SaveResult"] = "Saved Ride established";
                return(RedirectToAction("Index"));
            }

            ModelState.AddModelError("", "Error creating Saved Ride");
            return(View(model));
        }
Beispiel #2
0
        public bool CreateSavedRide(SavedRideCreate model)
        {
            using (var ctx = new ApplicationDbContext())
            {
                var entity = new SavedRide()
                {
                    Id          = model.Id,
                    Name        = model.Name,
                    Description = model.Description,
                    CreatedUtc  = DateTimeOffset.Now,
                    LocationId  = model.LocationId,
                    RideStatsId = model.RideStatsId
                };

                ctx.SavedRides.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }