public IHttpActionResult CreateRoom(CreateRoomBindingModel model) { var userId = this.idProvider.GetId(); if (userId == null) { return(this.Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var roomNameExists = this.Data.Rooms.GetAll().Any(r => r.Name == model.Name); if (roomNameExists) { return(this.BadRequest("Room name already exists")); } var room = new Room { Name = model.Name }; this.Data.Rooms.Add(room); this.Data.SaveChanges(); return(Ok(string.Format("Room with id: {0}, successfully created", room.Id))); }
public async Task CreateRoomAsync(int hotelId, CreateRoomBindingModel bindingModel) { var room = Mapper.Map <Room>(bindingModel); await this.roomsRepository.AddAsync(room); await this.roomsRepository.SaveChangesAsync(); }
public async Task <bool> Insert(CreateRoomBindingModel model) { Room newRoom = new Room(model.Number, model.SeatsPerRow, model.Rows, model.CinemaId); this.DbContext.Rooms.Add(newRoom); int rowsAffected = await this.DbContext.SaveChangesAsync(); return(rowsAffected == 1); }
public async Task <IActionResult> Room(int id, CreateRoomBindingModel bindingModel) { if (this.ModelState.IsValid) { await this.roomsService.CreateRoomAsync(id, bindingModel); return(this.RedirectToAction(nameof(this.Details), new { id })); } var viewMode = this.hotelsServices.GetHotelById(id); return(this.View(viewMode)); }
public async Task <IHttpActionResult> Create(CreateRoomBindingModel model) { var room = this.service.GetByCinemaAndNumber(model.CinemaId, model.Number); if (room != null) { return(BadRequest("Room already exists")); } bool isCreated = await this.service.Insert(model); if (!isCreated) { return(BadRequest("Error while creating a room")); } return(Ok(room)); }
public void AddingRoomShouldAddRoom() { var room = new CreateRoomBindingModel() { Name = "new room", }; var httpResponse = this.controller.CreateRoom(room) .ExecuteAsync(CancellationToken.None).Result; Assert.AreEqual(HttpStatusCode.OK, httpResponse.StatusCode); var resultRoomName = this.dataMock.Rooms.GetAll() .Select(r => r.Name) .Last(); Assert.AreEqual(room.Name, resultRoomName); }
public IHttpActionResult CreateRoom(CreateRoomBindingModel model) { var userId = this.User.Identity.GetUserId(); if (userId == null) { return(this.Unauthorized()); } if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var room = new Room { Name = model.Name }; this.Data.Rooms.Add(room); this.Data.SaveChanges(); return(Ok(string.Format("Room with id: {0}, successfully created", room.Id))); }