public Room AddRoom(RoomAddViewModel roomAddModel) { var findHouse = _adressProvider.GetHouses(roomAddModel.SelectStreetId) .Where(x => x.Number == roomAddModel.NumberHouse) .FirstOrDefault(); if (findHouse == null) { NumberHouse numberHouse = new NumberHouse { Number = roomAddModel.NumberHouse, StreetId = roomAddModel.SelectStreetId }; _numberHomeRepository.Add(numberHouse); _numberHomeRepository.SaveChanges(); findHouse = numberHouse; } roomAddModel.NumberHouseID = findHouse.Id; Room room; using (TransactionScope scope = new TransactionScope()) { room = new Room { HouseId = roomAddModel.NumberHouseID, Floor = roomAddModel.Floor, CountRooms = roomAddModel.CountRoom, NumberRoom = roomAddModel.NumberRoom, Price = Convert.ToDecimal(roomAddModel.price), Square = Convert.ToDecimal(roomAddModel.Square), Reserved = roomAddModel.Reserved, Sales = roomAddModel.Sales }; _roomsRepository.Add(room); _roomsRepository.SaveChanges(); foreach (var item in roomAddModel.Images) { var p = ImageToDataBase.ToBinaryArray(item); RoomImage roomImages = new RoomImage { Name = Guid.NewGuid().ToString() + ".jpg", RoomId = room.Id, Photo = p }; _roomImagesRepository.Add(roomImages); } _roomImagesRepository.SaveChanges(); scope.Complete(); } return(room); }
public async Task CreateRoom(string room) { if (!string.IsNullOrEmpty(room)) { var newRoom = new ChatRooms { Name = room }; await _roomRep.Add(newRoom); await Clients.All.SendAsync("room", newRoom); } }