public bool CreateAccommodation(AccommodationCreate model) { var entity = new Accommodation() { Name = model.Name, Id = model.Id, StreetAddress = model.StreetAddress, City = model.City, State = model.State, ZipCode = model.ZipCode, ReservationNumber = model.ReservationNumber, CheckIn = model.CheckIn, CheckOut = model.CheckOut }; using (var ctx = new ApplicationDbContext()) { ctx.Accommodations.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(AccommodationCreate model) { model.Id = (User.Identity.GetUserId()); if (!ModelState.IsValid) { return(View(model)); } var service = CreateAccommodationService(); if (service.CreateAccommodation(model)) { TempData["SaveResult"] = "Your accommodation was created."; return(RedirectToAction("Index")); } ; ModelState.AddModelError("", "Accommodation could not be created."); return(View(model)); }