public ActionResult Create(HotelCreate model) { if (ModelState.IsValid) { } return(View(model)); }
public async Task <ActionResult> Create(HotelCreate model) { try { if (!ModelState.IsValid) { return(View(model)); } var service = CreateHotelService(); if (!await service.CreateHotelAsync(model)) { ModelState.AddModelError("", "Hotel could not be created."); return(View(model)); } return(RedirectToAction("Index")); } catch { return(View(model)); } }
public IHttpActionResult Post([FromBody] HotelCreate hotel) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } HotelService hotelService = CreateHotelService(); if (!hotelService.CreateHotel(hotel)) { return(InternalServerError()); } return(Ok("The hotel has been created.")); }
public bool CreateHotel(HotelCreate hotel) { var entity = new Hotel() { OwnerId = _UserId, HotelName = hotel.Name, Location = hotel.Location, }; using (var ctx = new ApplicationDbContext()) { ctx.Hotels.Add(entity); return(ctx.SaveChanges() == 1); } }
public bool CreateHotel(HotelCreate model) { var entity = new Hotel { OwnerId = _userId, Name = model.Name, Address = model.Address, Comment = model.Comment, DestinationId = model.DestinationId, CreatedUtc = DateTimeOffset.Now }; using (var ctx = new ApplicationDbContext()) { ctx.Hotels.Add(entity); return(ctx.SaveChanges() == 1); } }
public ActionResult Create(HotelCreate model) { if (!ModelState.IsValid) { PopulateDestinations(); return(View(model)); } var service = CreateHotelService(); if (service.CreateHotel(model)) { TempData["SaveResult"] = "Your Hotel was created."; return(RedirectToAction("Index")); } PopulateDestinations(); ModelState.AddModelError("", "Hotel could not be created"); return(View(model)); }
//public bool CreateHotel(HotelCreate model) //{ // var hotel = new Hotel // { // Name = model.Name, // BuildingNumber = model.BuildingNumber, // StreetAddress = model.StreetAddress, // City = model.City, // State = model.State, // ZipCode = model.ZipCode, // NumOfRoomsAvail = model.NumOfRoomsAvail, // CreatedAt = DateTimeOffset.UtcNow // }; // using (var db = new ApplicationDbContext()) // { // db.Hotels.Add(hotel); // return db.SaveChanges() == 1; // } //} public async Task <bool> CreateHotelAsync(HotelCreate model) { //var hotelName = char.ToUpper(model.Name[0]) + model.Name.Substring(1); var hotelName = CapitalizeHotelName(model.Name); var hotel = new Hotel { Name = hotelName, BuildingNumber = model.BuildingNumber, StreetAddress = model.StreetAddress, City = model.City, State = model.State, ZipCode = model.ZipCode, CreatedAt = DateTimeOffset.UtcNow }; using (var db = new ApplicationDbContext()) { db.Hotels.Add(hotel); return(await db.SaveChangesAsync() == 1); } }