public async Task <IActionResult> AddRoom(RoomBindingModel roomBindingModel) { // Check that the binding model is valid. if (!ModelState.IsValid) { return(RedirectToAction("Index")); } // If that's the case, create a model from the binding model. var roomCategoryModel = await _roomCategoryService.GetRoomCategoryById(roomBindingModel.RoomCategoryId); if (roomCategoryModel == null) { return(BadRequest("Could not find the room category")); } var roomModel = new RoomModel { Name = roomBindingModel.Name, RoomCategoryModel = roomCategoryModel }; var successful = await _roomService.AddRoomAsync(roomModel); if (!successful) { return(BadRequest("Could not add the room.")); } return(RedirectToAction("Index")); }
public async Task <ActionResult> AddRoom(RoomViewModel model) { if (!ModelState.IsValid) { ViewBag.Types = _roomService.GetTypes(); ViewBag.Companies = _roomService.GetCompanies(); return(View()); } var roomToAdd = _mapper.Map <QuestRoom>(model); int?validationTypeId = _roomService.GetAllTypes().Where(x => x.Name == roomToAdd.DecorationType.Name).Select(x => x.Id).FirstOrDefault(); int?validationCompanyId = _roomService.GetAllCompanies().Where(x => x.Name == roomToAdd.Company.Name).Select(x => x.Id).FirstOrDefault(); if (validationTypeId != null && validationCompanyId != null) { roomToAdd.DecorationTypeId = int.Parse(validationTypeId.ToString()); roomToAdd.DecorationType = null; roomToAdd.CompanyId = int.Parse(validationCompanyId.ToString()); roomToAdd.Company = null; await _roomService.AddRoomAsync(roomToAdd); return(RedirectToAction("Index")); } return(View("Error")); }
public async Task <ActionResult> AddRoom([FromBody] RoomDTO newRoom, [FromRoute] long hotelId) { var newRoomView = mapper.Map <RoomDTO, RoomViewModel>(newRoom); await roomService.AddRoomAsync(newRoomView, hotelId); return(Ok()); }
public async Task <AddRoomResponse> Handle(AddRoomCommand request, CancellationToken cancellationToken) { var room = _mapper.Map <Domain.Models.Room>(request); var response = await _roomService.AddRoomAsync(room); return(new AddRoomResponse { Id = response }); }
public async Task <IActionResult> AddRoom(RoomViewModel newRoom, long hotelId) { if (ModelState.IsValid) { await roomService.AddRoomAsync(newRoom, hotelId); return(RedirectToAction(nameof(HotelController.HotelInfo), "Hotel", new { hotelId })); } return(View(newRoom)); }
public async Task <IActionResult> OnPostAsync() { if (ModelState.IsValid) { if (await _roomService.AddRoomAsync(Room)) { Message = "Success"; } return(RedirectToPage("./Index")); } return(Page()); }
public RoomAccesActor(IRoomService roomService) { _roomService = roomService; Receive<LoadActiveRoomsMessage>(message => { var sender = Sender; var self = Self; _roomService.GetRoomsAsync().SafelyPipeTo( task => new ActiveRoomsMessage(task.Result), task => new FailedToLoadActiveRoomsMessage(task.Exception?.InnerException), sender, self); }); Receive<CreateRoomMessage>(message => { var sender = Sender; var self = Self; var room = new Room { Name = message.Name, CreateTime = message.CreateTime, Users = new List<User>() }; _roomService.AddRoomAsync(room).SafelyPipeTo( task => new RoomCreatedMessage(task.Result), task => new FailedToCreateMessage(message.Creator, task.Exception?.InnerException), sender, self); }); Receive<GetUsersInRoomMessage>(message => { var sender = Sender; var self = Self; _roomService.GetUsersInRoomAsync(message.RoomId).SafelyPipeTo( task => new UsersInRoomMessage(message.RoomId, task.Result.ToList()), task => new FailedToGetUsersInRoomMessage(message.RoomId, task.Exception?.InnerException), sender, self); }); Receive<RemoveRoomMessage>(message => { var sender = Sender; var self = Self; _roomService.RemoveRoomAsync(message.Room).PipeFailureTo( task => new FailedToRemoveRoomMessage(message.Room.Id, task.Exception?.InnerException), sender, self); }); }
public async Task <IActionResult> Add(AddRoomDto addRoomDto) { if (!ModelState.IsValid) { var buildings = await _buildingService.ListBuildingsAsync(); var model = new AddRoomDto(); model.Buildings = buildings; return(View(model)); } await _roomService.AddRoomAsync(addRoomDto); var rooms = await _roomService.ListRoomsAsync(); int roomId = rooms.OrderByDescending(r => r.Id).FirstOrDefault().Id; return(RedirectToAction("show", "room", new { id = roomId })); }
public async Task <IActionResult> Create(CreateRoomModel createRoom) { var errorMessage = String.Empty; if (!createRoom.ValidateCreateModel(out errorMessage)) { ModelState.AddModelError(string.Empty, errorMessage); } else if (!RoomService.ValidateRoom(createRoom.Id, createRoom.RoomNumber, out errorMessage)) { ModelState.AddModelError(string.Empty, errorMessage); } else { await RoomService.AddRoomAsync(createRoom); return(RedirectToAction(nameof(Index))); } return(View()); }
public async Task <IActionResult> PostAddPropertyAsync([FromBody] RoomModel obj) { if (!ModelState.IsValid) { return(BadRequest()); } var response = await _roomService.AddRoomAsync(obj); _responseModel.Status = response.Status; _responseModel.Message = response.Message; if (_responseModel.Status) { return(Ok(_responseModel)); } else { return(BadRequest(_responseModel)); } }
public async Task <IActionResult> CreateRoom([FromBody] SaveRoomResource roomResource) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } var room = mapper.Map <SaveRoomResource, Room>(roomResource); room.AvailableFrom = DateTime.Now; room.PropertyType = await propertyService.FirstOrDefault(p => p.Id == roomResource.PropertyId); room.CreatedAt = DateTime.Now; room.CreatedBy = room.UserId.ToString(); await service.AddRoomAsync(room); await uow.CompleteAsync(); room = await service.GetRoom(room.Id); return(Ok(mapper.Map <Room, RoomResource>(room))); }
public async Task <RoomModel> Post([FromBody] ShortRoomModel roomModel) { return(_mapper.Map <RoomModel>(await _roomService.AddRoomAsync(roomModel))); }