Beispiel #1
0
        public async Task <ActionResult <HotelDto> > PostHotel(HotelDto hotel)
        {
            await _hotelRepo.CreateHotel(hotel);


            return(CreatedAtAction("GetHotel", new { id = hotel.Id }, hotel));
        }
Beispiel #2
0
        public HotelDto GetHotel(int id)
        {
            var hotelResult = new HotelDto();

            var result = _hotelRepository.GetHotelById(id);

            if (result != null)
            {
                hotelResult.Name          = result.Name;
                hotelResult.Address       = result.Address;
                hotelResult.Distance      = result.Distance;
                hotelResult.Description   = result.Description;
                hotelResult.HasGym        = result.HasGym;
                hotelResult.HasParking    = result.HasParking;
                hotelResult.HasPool       = result.HasPool;
                hotelResult.HasRestourant = result.HasRestourant;
                hotelResult.HasSpaCenter  = result.HasSpaCenter;
                hotelResult.HasWiFi       = result.HasWiFi;
                hotelResult.HotelID       = result.HotelID;
                hotelResult.IsPetFriendly = result.IsPetFriendly;
                hotelResult.Stars         = result.Stars;
                hotelResult.PhotoData     = result.PhotoData;
            }

            return(hotelResult);
        }
Beispiel #3
0
        public void Alterar(HotelDto hotelDto)
        {
            if (hotelDto.Id <= 0)
            {
                throw new ApplicationException("Operação inválida.");
            }

            var toUpdateHotel = Repository.Load(hotelDto.Id);

            if (toUpdateHotel == null)
            {
                throw new ApplicationException("O hotel em edição não foi encontrado na base de dados.");
            }

            toUpdateHotel.Nome      = hotelDto.Nome;
            toUpdateHotel.Descricao = hotelDto.Descricao;
            toUpdateHotel.Avaliacao = hotelDto.Avaliacao;
            toUpdateHotel.Endereco  = hotelDto.Endereco;
            toUpdateHotel.Comodidades.Clear();

            hotelDto.Comodidades.ForEach(comodidade =>
            {
                toUpdateHotel.Comodidades.Add(Repository.Query <ComodidadeEntity>().FirstOrDefault(c => c.Id == comodidade.Id));
            });

            Transaction(() =>
            {
                Repository.Update(toUpdateHotel);
            });
        }
Beispiel #4
0
        public ActionResult Create(CreateHotelViewModel newHotel, HttpPostedFileBase file)
        {
            if (ModelState.IsValid)
            {
                HotelDto hotelDto = new HotelDto();
                hotelDto.Name          = newHotel.Name;
                hotelDto.Stars         = newHotel.Stars;
                hotelDto.HasPool       = newHotel.HasPool;
                hotelDto.HasParking    = newHotel.HasParking;
                hotelDto.HasRestourant = newHotel.HasRestourant;
                hotelDto.HasGym        = newHotel.HasGym;
                hotelDto.HasSpaCenter  = newHotel.HasSpaCenter;
                hotelDto.HasWiFi       = newHotel.HasWiFi;
                hotelDto.IsPetFriendly = newHotel.IsPetFriendly;
                hotelDto.Description   = newHotel.Description;
                hotelDto.Distance      = newHotel.Distance;
                hotelDto.Address       = newHotel.Address;
                hotelDto.CityName      = newHotel.City;
                hotelDto.PhotoData     = FileToByteArray(file);
                _hotelsManager.AddHotel(hotelDto);

                return(RedirectToAction("Menage"));
            }
            else
            {
                return(View(newHotel));
            }
        }
Beispiel #5
0
 private void btnSave_Click(object sender, EventArgs e)
 {
     if (!ClientUtils.CheckEmpty(txtHotelName, "EMPTY_HOTEL_NAME") || !ClientUtils.CheckEmpty(txtFee, "EMPTY_FEE"))
     {
         return;
     }
     try
     {
         Convert.ToInt16(txtRoomCount.Text);
     }
     catch
     {
         txtRoomCount.Text = "0";
     }
     hotel = new HotelDto
     {
         HouseName   = txtHotelName.Text,
         Fee         = Convert.ToSingle(txtFee.Text),
         AgentFee    = Convert.ToSingle(txtAgentFee.Text),
         CoverPic    = pic,
         Description = txtDesc.Text,
         Remark      = txtRemark.Text,
         Pics        = otherPics,
         Location    = txtLocation.Text,
         RoomCount   = Convert.ToInt16(txtRoomCount.Text)
     };
     this.DialogResult = DialogResult.OK;
     this.Close();
 }
        /// <summary>
        /// Removes a Hotel From the Database
        /// </summary>
        /// <param name="ID"></param>
        /// <returns></returns>
        public async Task DeleteHotel(int ID)
        {
            HotelDto hotel = await GetHotel(ID);

            _context.Remove(hotel).State = Microsoft.EntityFrameworkCore.EntityState.Deleted;
            await _context.SaveChangesAsync();
        }
Beispiel #7
0
        public HotelDto MapHotelData(Hotel hotel)
        {
            try
            {
                var result = new HotelDto();
                result.Id          = hotel.Id;
                result.Code        = hotel.Code;
                result.Name        = hotel.Name;
                result.Description = hotel.Description;
                result.City        = hotel.City;
                result.Address     = hotel.Address;
                result.Email       = hotel.Email;

                Regex urlRegex = new Regex(@"(http(s)?://)?([\w-]+\.)+[\w-]+(/[\w- ;,./?%&=]*)?");
                if (urlRegex.IsMatch(hotel.Web))
                {
                    result.Web = hotel.Web;
                }

                result.CountryId       = hotel.CountryId;
                result.HotelCategoryId = hotel.HotelCategoryId;
                result.CountryName     = _countryRepository.GetCountryName(hotel.CountryId);
                result.HotelCategory   = _hotelRepository.GetHotelCategory(hotel.HotelCategoryId).Description;

                return(result);
            }
            catch (Exception ex)
            {
                throw new Exception("Something went wrong.");
            }
        }
Beispiel #8
0
 public HotelRepository()
 {
     Hotels = File.ReadAllLines("Repositories\\hoteldb.csv")
              .Skip(1)
              .Select(line => HotelDto.FromCsvLine(line))
              .ToList();
 }
Beispiel #9
0
        public bool CreateNewHotel(HotelDto hotelInfo)
        {
            if (string.IsNullOrEmpty(hotelInfo.Name))
            {
                return(false);
            }

            // Check name duplications
            var _hotel = new EMS.DataAccess.Model.Hotel();

            _hotel.Name = hotelInfo.Name;

            if (hotelInfo.ConferenceRooms.Count > 0)
            {
                AttachRooms(_hotel, hotelInfo.ConferenceRooms);
            }

            unitOfWorkDb.HotelRepository.Insert(_hotel);
            try
            {
                unitOfWorkDb.Save();
                return(true);
            }
            catch (Exception e)
            {
                // LOG
                return(false);
            }
        }
Beispiel #10
0
        public ActionResult Add(HotelDto hotel)
        {
            WebResult result = new WebResult
            {
                Code    = SystemConst.MSG_SUCCESS,
                Message = SystemConst.MSG_ERR_UNKNOWN
            };

            using (var db = new TravelEntities())
            {
                T_LiveProjects selectedHotel = new T_LiveProjects
                {
                    HouseName   = hotel.HouseName,
                    Fee         = hotel.Fee,
                    SupplierID  = hotel.SupplierID,
                    AgentFee    = hotel.AgentFee,
                    Pics        = hotel.Pics,
                    CoverPic    = hotel.CoverPic,
                    Description = hotel.Description,
                    Remark      = hotel.Remark,
                    Location    = hotel.Location,
                    RoomCount   = hotel.RoomCount
                };
                db.T_LiveProjects.Add(selectedHotel);
                db.SaveChanges();
            }

            return(Content(AppUtils.JsonSerializer(result)));
        }
Beispiel #11
0
        public ActionResult Modify(HotelDto hotel)
        {
            WebResult result = new WebResult
            {
                Code    = SystemConst.MSG_SUCCESS,
                Message = SystemConst.MSG_ERR_UNKNOWN
            };

            using (var db = new TravelEntities())
            {
                T_LiveProjects selectedHotel = db.T_LiveProjects.FirstOrDefault(a => a.HouseID == hotel.HouseID);
                selectedHotel.HouseName   = hotel.HouseName;
                selectedHotel.Fee         = hotel.Fee;
                selectedHotel.AgentFee    = hotel.AgentFee;
                selectedHotel.CoverPic    = hotel.CoverPic;
                selectedHotel.Description = hotel.Description;
                selectedHotel.Remark      = hotel.Remark;
                selectedHotel.Pics        = hotel.Pics;
                selectedHotel.Location    = hotel.Location;
                selectedHotel.RoomCount   = hotel.RoomCount;
                db.T_LiveProjects.Attach(selectedHotel);
                db.Entry(selectedHotel).State = System.Data.Entity.EntityState.Modified;
                db.SaveChanges();
            }

            return(Content(AppUtils.JsonSerializer(result)));
        }
Beispiel #12
0
        public ActionResult RoomCheckedIn(Guid id)
        {
            try
            {
                var item  = ServiceLocator.ReportDatabase.GetById(id);
                var model = new HotelDto()
                {
                    CustomerName = item.CustomerName,
                    Email        = item.Email,
                    PhoneNo      = item.PhoneNo,
                    RoomNo       = item.RoomNo,
                    CheckIn      = item.CheckIn,
                    CheckOut     = item.CheckOut,
                    IsCheckedIn  = true,
                    Id           = item.Id,
                    Version      = item.Version
                };
                ServiceLocator.CommandBus.Send(new ChangeCommand(item.Id, item.CustomerName, item.Email, item.PhoneNo, item.RoomNo, -1, item.CheckIn, item.CheckOut, true));
            }
            catch (ConcurrencyException err)
            {
                ViewBag.error = err.Message;
                ModelState.AddModelError("", err.Message);
                return(View());
            }

            return(RedirectToAction("Index"));
        }
        public async Task <IActionResult> PutHotel(int id, HotelDto hotelDto)
        {
            if (id != hotelDto.Id)
            {
                return(BadRequest());
            }

            try
            {
                await _hotel.UpdateHotel(hotelDto);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HotelExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Beispiel #14
0
        private bool IsCorrectHotel(HotelDto hotel)
        {
            return(hotel != null

                   && IsCorrectPropertyId(hotel.propertyID)

                   && !IsBlankHotelName(hotel.name));
        }
Beispiel #15
0
        /// <summary>
        /// Adds the specified hotel data transfer object.
        /// </summary>
        /// <param name="hotelDto">The hotel data transfer object.</param>
        public void Add(HotelDto hotelDto)
        {
            Guard.ArgumentNotNull(nameof(hotelDto), hotelDto);

            var hotel = Mapper.Map <HotelDto, HotelEntity>(hotelDto);

            hotelRepository.Create(hotel);
        }
Beispiel #16
0
        public ActionResult HotelDetails(int id)
        {
            HotelDto hotelmodel = new HotelDto();

            hotelmodel = _hotelsManager.GetHotel(id);

            hotelmodel.Rating = (float)_ratingManager.GetRatingByHotelID(id);

            return(View(hotelmodel));
        }
        // POST api/<controller>
        public List <HotelViewModel> HotelList(HotelDto value)
        {
            if (ModelState.IsValid)
            {
            }

            //call CodingExercise.Mapping
            //call CodingExercise.Business

            return(new List <HotelViewModel>());
        }
Beispiel #18
0
        public async Task <bool> BuyHotelAsync(int userId)
        {
            var logger = new Logger();
            await logger.WriteLogAsync($"{DateTime.Now} - Hotel purchase service triggered");

            var hotelKey    = (userId, BookingType.Hotel);
            var hotelKeyIds = _db.Find(hotelKey);
            var isBuying    = true;

            if (hotelKeyIds != null)
            {
                if (hotelKeyIds.Count != 0)
                {
                    foreach (var id in hotelKeyIds)
                    {
                        var hotelServiceUrl = BuyingServiceUrls.HOTEL_URL;
                        var hotelData       = new HotelDto()
                        {
                            BookingId = id
                        };

                        var body     = JsonConvert.SerializeObject(hotelData);
                        var response = await _client.PutAsync(hotelServiceUrl, new StringContent(body, Encoding.UTF8, "application/json"));

                        var responseData = false;
                        if (response.StatusCode == HttpStatusCode.OK)
                        {
                            dynamic a = JsonConvert.DeserializeObject(await response.Content.ReadAsStringAsync());
                            responseData = a.status;
                        }

                        if (responseData == true)
                        {
                            isBuying = true;
                            _db.Remove(hotelKey);
                        }
                        else
                        {
                            isBuying = false;
                        }
                    }
                }
                else
                {
                    isBuying = false;
                }
            }
            else
            {
                isBuying = false;
            }

            return(isBuying);
        }
Beispiel #19
0
        public IActionResult PostHotelToCity([FromBody] HotelDto hotelDTO, long cityId)
        {
            City  city  = _cityRepository.GetCity(cityId, true);
            Hotel hotel = _mapper.Map <Hotel>(hotelDTO);

            city.HotelList.Add(hotel);
            _cityRepository.Save();
            CityDto returnCityDto = _mapper.Map <CityDto>(city);

            return(Created("null", returnCityDto));
        }
Beispiel #20
0
        public bool BuyHotel([FromBody] HotelDto dto)
        {
            var isBuying      = false;
            var buyingHotelId = dto.Id;

            if (buyingHotelId != -1)
            {
                isBuying = true;
            }

            return(isBuying);
        }
Beispiel #21
0
        public void MapHotelData_HotelExist_AllDataMustBeCorrect()
        {
            //Arrange
            var mockContryRepository = new Mock <ICountryRepository>();
            var mockHotelRepository  = new Mock <IHotelRepository>();

            var mockedCountry = "Macedonia";
            var expectedHotel = new HotelDto
            {
                Id              = 3,
                Code            = "03",
                Name            = "Diplomat Hotel",
                Description     = "Description",
                City            = "Ohrid",
                Address         = "BB",
                Email           = "*****@*****.**",
                CountryId       = 1,
                HotelCategoryId = 1,
                Web             = "http://diplomat.mk",
                CountryName     = "Macedonia",
                HotelCategory   = "4 STARS"
            };
            var hotel = new Hotel {
                Id = 3, Code = "03", Name = "Diplomat Hotel", Description = "Description", City = "Ohrid", Address = "BB", Email = "*****@*****.**", CountryId = 1, HotelCategoryId = 1, Web = "http://diplomat.mk"
            };
            var mockedHotelCategory = new HotelCategory {
                Id = 1, Code = "03", Description = "4 STARS"
            };

            mockContryRepository.Setup(x => x.GetCountryName(It.IsAny <int>())).Returns(mockedCountry);
            mockHotelRepository.Setup(x => x.GetHotelCategory(It.IsAny <int>())).Returns(mockedHotelCategory);
            //Act
            var searchService = new SearchService(mockContryRepository.Object, mockHotelRepository.Object);
            var result        = searchService.MapHotelData(hotel);

            //Assert
            //Assert.Equal(expectedHotel.Id, result.Id);
            //Assert.Equal(expectedHotel.Code, result.Code);
            result.Name.Should().Be(expectedHotel.Name);
            result.Code.Should().Be(expectedHotel.Code);

            Assert.Equal(expectedHotel.Name, result.Name);
            Assert.Equal(expectedHotel.Description, result.Description);
            Assert.Equal(expectedHotel.City, result.City);
            Assert.Equal(expectedHotel.Address, result.Address);
            Assert.Equal(expectedHotel.Email, result.Email);
            Assert.Equal(expectedHotel.CountryId, result.CountryId);
            Assert.Equal(expectedHotel.HotelCategoryId, result.HotelCategoryId);
            Assert.Equal(expectedHotel.CountryName, result.CountryName);
            Assert.Equal(expectedHotel.HotelCategory, result.HotelCategory);
            Assert.Equal(expectedHotel.Web, result.Web);
        }
Beispiel #22
0
 public void Intialize()
 {
     hotelDto = new HotelDto
     {
         CustomerName = "test",
         Email        = "*****@*****.**",
         PhoneNo      = "1234567890",
         RoomNo       = 305,
         CheckIn      = DateTime.Now,
         CheckOut     = DateTime.Now,
         IsCheckedIn  = false
     };
 }
Beispiel #23
0
        public async Task <bool> DeleteHotel(int id)
        {
            HotelDto hotel = await GetHotel(id);

            if (hotel == null)
            {
                return(false);
            }
            _context.Entry(hotel).State = EntityState.Deleted;
            await _context.SaveChangesAsync();

            return(true);
        }
Beispiel #24
0
 private void modifyHotel()
 {
     if (dgHotel.SelectedCells.Count == 0)
     {
         MessageBox.Show(LangBase.GetString("NOT_SELECT_HOTEL"));
         return;
     }
     else
     {
         int      rowIndex    = dgHotel.SelectedCells[0].RowIndex;
         HotelDto hotel       = hotels[rowIndex];
         AddHotel modifyHotel = new AddHotel(hotel);
         if (isModify)
         {
             if (modifyHotel.ShowDialog() == DialogResult.OK)
             {
                 modifyHotel.hotel.HouseID = hotel.HouseID;
                 string    str_result = WebCall.PostMethod <HotelDto>(WebCall.ModifyHotel, modifyHotel.hotel);
                 WebResult result     = AppUtils.JsonDeserialize <WebResult>(str_result);
                 if (result.Code.Equals(SystemConst.MSG_SUCCESS))
                 {
                     hotel.HouseName    = modifyHotel.hotel.HouseName;
                     hotel.Fee          = modifyHotel.hotel.Fee;
                     hotel.AgentFee     = modifyHotel.hotel.AgentFee;
                     hotel.CoverPic     = modifyHotel.hotel.CoverPic;
                     hotel.Pics         = modifyHotel.hotel.Pics;
                     hotel.Description  = modifyHotel.hotel.Description;
                     hotel.Remark       = modifyHotel.hotel.Remark;
                     hotel.Location     = modifyHotel.hotel.Location;
                     hotel.RoomCount    = modifyHotel.hotel.RoomCount;
                     dgHotel.DataSource = null;
                     dgHotel.DataSource = hotels;
                 }
                 else
                 {
                     ClientUtils.WarningCode(result.Message);
                 }
             }
         }
         else
         {
             if (modifyHotel.ShowDialog() == DialogResult.OK)
             {
                 hotels.RemoveAt(rowIndex);
                 hotels.Add(modifyHotel.hotel);
                 dgHotel.DataSource = null;
                 dgHotel.DataSource = hotels;
             }
         }
     }
 }
Beispiel #25
0
        public HotelDto CreateHotel(HotelDto hotelDto, int userId, int tenantId, List <MemoryStream> files, string path)
        {
            if (GetHotel(hotelDto.HotelId, tenantId) != null)
            {
                return(EditHotel(hotelDto, userId, tenantId, files, path, 1));
            }
            ValidateHotel(hotelDto, tenantId);
            var hotelObj = Mapper.Map <Hotel>(hotelDto);

            foreach (var hotelName in hotelDto.TitleDictionary)
            {
                hotelObj.HotelTranslations.Add(new HotelTranslation
                {
                    Title       = hotelName.Value,
                    Description = hotelDto.DescriptionDictionary[hotelName.Key],
                    Language    = hotelName.Key,
                });
            }

            hotelObj.TenantId      = tenantId;
            hotelObj.CityId        = hotelDto.CityId;
            hotelObj.Latitude      = hotelDto.Latitude;
            hotelObj.Longitude     = hotelDto.Longitude;
            hotelObj.Star          = hotelDto.Star;
            hotelObj.CreationTime  = Strings.CurrentDateTime;
            hotelObj.CreatorUserId = userId;
            hotelObj.CurrencyId    = hotelDto.CurrencyId;


            //foreach (var roleper in hotelDto.HotelFeature)
            //{
            //    hotelObj.HotelFeature.Add(new HotelFeature
            //    {
            //        FeatureId = roleper.FeatureId
            //    });
            //}
            _hotelFeatureService.InsertRange(hotelObj.HotelFeature);

            _hotelTranslationService.InsertRange(hotelObj.HotelTranslations);
            _hotelService.Insert(hotelObj);

            SaveChanges();
            var imageId = 1;

            foreach (var memoryStream in files)
            {
                _manageStorage.UploadImage(path + "\\" + "Hotel-" + hotelObj.HotelId, memoryStream, imageId.ToString());
                imageId++;
            }
            return(hotelDto);
        }
Beispiel #26
0
        public IHttpActionResult PostHotel(HotelDto hotelDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Hotel hotel = Mapper.Map <HotelDto, Hotel>(hotelDto);

            db.Hotels.Add(hotel);
            db.SaveChanges();

            return(Created(new Uri(Request.RequestUri + "/" + hotel.ID), hotelDto));
        }
Beispiel #27
0
        public IHttpActionResult CreateHotel (HotelDto hotelDto)
        {
            if (!ModelState.IsValid)
                return BadRequest();

            var hotel = Mapper.Map<HotelDto, Hotel>(hotelDto);

            _context.Hotels.Add(hotel);
            _context.SaveChanges();

            hotelDto.Id = hotel.Id;

            return Created(new Uri(Request.RequestUri + "/" + hotel.Id), hotelDto);
        }
Beispiel #28
0
        public void UpdateHotel(int id, HotelDto hotelDto)
        {
            if (!ModelState.IsValid)
                throw new HttpResponseException(HttpStatusCode.BadRequest);

            var hotelInDb = _context.Hotels.SingleOrDefault(c => c.Id == id);

            if (hotelInDb == null)
                throw new HttpResponseException(HttpStatusCode.NotFound);

            Mapper.Map<HotelDto, Hotel>(hotelDto, hotelInDb);

            _context.SaveChanges();
        }
Beispiel #29
0
        public async Task <IActionResult> PutHotel(int id, HotelDto hotel)
        {
            if (id != hotel.Id)
            {
                return(BadRequest());
            }

            if (!await _hotelRepo.PutHotel(hotel))
            {
                return(NotFound());
            }

            return(NoContent());
        }
        public async Task <IActionResult> CreateHotel([FromBody] HotelDto hotelDto)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest());
            }
            var response = await _hotelService.CreateHotel(hotelDto);

            if (response.Error != null)
            {
                return(BadRequest(response));
            }

            return(Ok(response));
        }
Beispiel #31
0
 public void UpdateHotel(HotelDto input)
 {
     var instanse = Mapper.Map<Hotel>(input);
     this.unitOfWork.Entities<Hotel, int>().Update(instanse);
 }