public ActionResult Create(Hotel hotel, HttpPostedFileBase filesInput) { if (ModelState.IsValid) { string fileName = ""; if (filesInput != null) { try { fileName = Path.GetFileName(filesInput.FileName); string path = Path.Combine(Server.MapPath(_ImagesPath), fileName); filesInput.SaveAs(path); } catch (Exception) { throw; } } hotel.Image = fileName; var resultAdd = _hotelRepository.Add(hotel); if (resultAdd) { return(Content($"<script language='javascript' type='text/javascript'> alert('Thêm thành công'); window.location.href='https://localhost:44316/Admin/HotelsManagement' </script>")); } } return(View(hotel)); }
public async Task <bool> SaveHotel(string path) { path = "C://Users//Laur//Desktop//di2.jpg"; FileStream fs = new FileStream(path, FileMode.Open); MemoryStream ms = new MemoryStream(); fs.CopyTo(ms); Hotel hotel = new Hotel() { Name = "name", ImageData = ms.ToArray() }; _hotelRepository.Add(hotel); try { await _unitOfWork.CommitChangesAsync(); } catch (Exception e) { return(false); } return(true); }
public void Handle(CreateHotelCommand Message) { if (Message != null) { var hotel = _mapper.Map <Hotel>(Message); _repository.Add(hotel); } }
public IActionResult Crate([FromBody] Hotel hotel) { if (hotel == null) { return(BadRequest()); } _hotelRepositorio.Add(hotel); return(CreatedAtRoute("GetHotel", new { id = hotel.HotelId }, hotel)); }
async Task <HotelDTO> IService <HotelDTO, int> .Add(HotelDTO entity) { Hotel hotel = (await _hotelRepository.Get(prop => prop.Name == entity.Name)).FirstOrDefault(); if (hotel == null) { hotel = await _hotelRepository.Add(_mapper.Map <HotelDTO, Hotel>(entity)); } return(_mapper.Map <Hotel, HotelDTO>(hotel)); }
public int AddHotel(string name, string description, string resortName, string image, double latitude, double longitude) { var hotel = new Hotel() { Name = name, ResortName = resortName, Description = description, Image = image, Latitude = latitude, Longitude = longitude }; _hotelRepository.Add(hotel); _objectContext.SaveChanges(); return(hotel.Id); }
async Task IStartDataService.AddHotels() { PlacementType placement = await _placementTypeRepository.Get(1); City city = await _cityRepository.Get(1); await _hotelRepository.Add(new Hotel { Name = "КоралРиф", Stars = 5, PlacementType = placement, City = city }); }
public async Task <IActionResult> CreateTourist(int hotelId, TouristForUpdateDto touristForUpdateDto) { if (touristForUpdateDto == null) { return(BadRequest()); } var touristEntity = _mapper.Map <Tourist>(touristForUpdateDto); touristEntity.HotelId = hotelId; _hotelrepo.Add(touristEntity); if (await _unitOfWork.CompleteAsync()) { var touristToReturn = _mapper.Map <TouristForUpdateDto>(touristEntity); return(CreatedAtRoute("GetTourist", new { id = touristToReturn.Id }, touristToReturn)); } throw new Exception("Creating the torist guide failed on save"); }
public async Task <IActionResult> CreateRoom(int hotelId, RoomForUpdateDto roomForUpdateDto) { if (roomForUpdateDto == null) { return(BadRequest()); } var roomEntity = _mapper.Map <Room>(roomForUpdateDto); roomEntity.HotelId = hotelId; _hotelrepo.Add(roomEntity); if (await _unitOfWork.CompleteAsync()) { var roomToReturn = _mapper.Map <RoomForUpdateDto>(roomEntity); return(CreatedAtRoute("GetRoom", new { id = roomEntity.Id }, roomToReturn)); } throw new Exception("Creating the room failed on save"); }
public async Task AddHotel(Hotel hotel) { await _repository.Add(hotel); await _unit.Complete(); }