public Hotels CreateHotel(string userId, CreateHotels hotelToAdd) { var user = this.unitOfWork.Users.GetUserById(userId, userId); if (user == null) { throw new Exception("Unable to find user"); } var newHotel = new Hotels { Name = hotelToAdd.Name, Address = hotelToAdd.Address, TaxRate = hotelToAdd.TaxRate, Latitude = hotelToAdd.Latitude, Longitude = hotelToAdd.Longitude, IsHidden = hotelToAdd.IsHidden }; var newHotelUserPermissions = new HotelUsers { UserId = user.Id, PermissionId = Convert.ToInt32(HotelUsersPermissionsEnum.FULL_ADMIN) }; newHotel.HotelUsers.Add(newHotelUserPermissions); this.dbContext.Hotels.Add(newHotel); return(newHotel); }
public SampleUnitTest() { (ParqueDasFlores, JardimBotanico, MarAtlantico) = CreateHotels.Create(); Calculator = new PriceCalculator(ParqueDasFlores, JardimBotanico, MarAtlantico); }
public ActionResult Create(CreateHotels hotelModel) { if (ModelState.IsValid) { var database = new BlogDbContext(); var touristId = this.User.Identity.GetUserId(); var hotel = new Hotel { Name = hotelModel.Name, Stars = hotelModel.Stars, Pool = hotelModel.Pool, Spa = hotelModel.Spa, Fitness = hotelModel.Fitness, ImageUrl = hotelModel.ImageUrl, PricePerNight = hotelModel.PricePerNight, TouristId = touristId }; database.Hotels.Add(hotel); database.SaveChanges(); return(RedirectToAction("HotelDetails", new { id = hotel.Id })); } return(View(hotelModel)); }
static void Main(string[] args) { (var ParqueDasFlores, var JardimBotanico, var MarAtlantico) = CreateHotels.Create(); PriceCalculator calculator = new PriceCalculator(ParqueDasFlores, JardimBotanico, MarAtlantico); Client cliente1 = new Client(ClientType.Regular, new DateTime(2020, 3, 16), new DateTime(2020, 3, 17), new DateTime(2020, 3, 18)); Client cliente2 = new Client(ClientType.Regular, new DateTime(2020, 3, 20), new DateTime(2020, 3, 21), new DateTime(2020, 3, 22)); Client cliente3 = new Client(ClientType.Fidelity, new DateTime(2020, 3, 26), new DateTime(2020, 3, 27), new DateTime(2020, 3, 28)); Console.WriteLine($@"Opção mais barata para o cliente 1: ""{calculator.FindCheaper(cliente1).Description}"""); Console.WriteLine($@"Opção mais barata para o cliente 2: ""{calculator.FindCheaper(cliente2).Description}"""); Console.WriteLine($@"Opção mais barata para o cliente 3: ""{calculator.FindCheaper(cliente3).Description}"""); Console.ReadKey(); }
public async Task <HttpResponseMessage> AddHotels(CreateHotels hotel) { return(await ErrorFactory.Handle(async() => { var userId = User?.Identity?.GetUserId(); if (userId == null) { throw new Exception("User not found."); } if (hotel == null) { throw new InvalidModelException("hotel cannot be null"); } if (hotel.TaxRate < 0 || hotel.TaxRate > 1) { throw new InvalidModelException("Tax rate must be greater than 0 and less than 1"); } using (var unitOfWork = new UnitOfWork()) { var finHotel = unitOfWork.Hotels.CreateHotel(userId, hotel); unitOfWork.Complete(); try { if (hotel.Image != null && !string.IsNullOrWhiteSpace(hotel.Image.Data)) { //This is added to help yogita with her base64 problems. hotel.Image.Data = hotel.Image.Data.Replace(' ', '+'); var data = ImageFactory.ConvertBase64ToArray(hotel.Image.Data); GalleryManager galMan = new GalleryManager(); var pictureId = await galMan.UploadImage(data, userId); if (pictureId == null) { throw new Exception(); } var tempHotel = unitOfWork.Hotels.SetHotelImageADMIN(userId, finHotel.Id, pictureId ?? Guid.NewGuid()); unitOfWork.Complete(); finHotel = tempHotel; } } catch (Exception) { //Maybe try to delete image. } return JsonFactory.CreateJsonMessage(OutgoingHotel.Parse(finHotel), HttpStatusCode.OK, this.Request); } }, this.Request)); }