public ActionResult Create(BarCreate model)
 {
     if (ModelState.IsValid)
     {
     }
     return(View(model));
 }
        public bool CreateBar(BarCreate model)
        {
            var entity =
                new Bar
            {
                OwnerId       = _userId,
                Name          = model.Name,
                Address       = model.Address,
                Comment       = model.Comment,
                ServesFood    = model.ServesFood,
                DestinationId = model.DestinationId,
                CreatedUtc    = DateTimeOffset.Now
            };

            using (var ctx = new ApplicationDbContext())
            {
                ctx.Bars.Add(entity);
                return(ctx.SaveChanges() == 1);
            }
        }
Beispiel #3
0
        public ActionResult Create(BarCreate model)
        {
            if (!ModelState.IsValid)
            {
                PopulateDestinations();
                return(View(model));
            }

            var service = CreateBarService();

            if (service.CreateBar(model))
            {
                TempData["SaveResult"] = "Your Bar was created.";
                return(RedirectToAction("Index"));
            }

            PopulateDestinations();
            ModelState.AddModelError("", "Bar could not be created");
            return(View(model));
        }