public ActionResult Edit(Guid id)
        {
            var title = titleRepository.GetTitlebyId(id);

            TitleVM model = new TitleVM();

            if (title != null && title.Count > 0)
            {
                model = title[0];

                return(View(model));
            }

            return(RedirectToAction("List"));
        }
        public ActionResult PreviewRegistrationCard(Guid?Id)
        {
            if (Id == null)
            {
                return(HttpNotFound());
            }

            GuestRegistrationCardVM model = new GuestRegistrationCardVM();

            var reservation = reservationRepository.GetReservationById(Id.Value, LogInManager.LoggedInUserId).FirstOrDefault();

            #region Room Mapping

            //Get Room Mapping
            var selectedRooms = roomRepository.GetReservationRoomMapping(Id, null, LogInManager.LoggedInUserId);
            var roomIds       = string.Empty;
            var roomNumbers   = string.Empty;

            if (selectedRooms != null && selectedRooms.Count > 0)
            {
                foreach (var room in selectedRooms)
                {
                    roomIds     += string.Format("{0},", room.RoomId);
                    roomNumbers += string.Format("{0}, ", room.RoomNo);
                }

                if (!string.IsNullOrWhiteSpace(roomNumbers))
                {
                    //Remove Last Comma.
                    roomNumbers = Utility.Utility.RemoveLastCharcter(roomNumbers, ',');
                }
            }
            #endregion


            #region Profile

            var profile = new IndividualProfileVM();

            if (reservation.ProfileId.HasValue)
            {
                profile = profileRepository.GetIndividualProfileById(reservation.ProfileId.Value, LogInManager.LoggedInUserId).FirstOrDefault();
            }

            #endregion

            #region Title

            var title = new TitleVM();
            if (profile.TitleId.HasValue)
            {
                title = titleRepository.GetTitlebyId(profile.TitleId.Value).FirstOrDefault();
            }

            #endregion

            #region Room Type

            var roomType = new RoomTypeVM();
            if (reservation.RoomTypeId.HasValue)
            {
                roomType = roomTypeRepository.GetRoomTypeById(reservation.RoomTypeId.Value).FirstOrDefault();
            }

            #endregion

            #region Preference Mapping

            //Get Preference Mapping
            var selectedPreferences = preferenceRepository.GetReservationPreferenceMapping(reservation.Id, null, LogInManager.LoggedInUserId);

            var preferences = "";
            if (selectedPreferences != null && selectedPreferences.Count > 0)
            {
                preferences = String.Join(", ", selectedPreferences.Select(m => m.PreferenceDescription));

                if (!string.IsNullOrWhiteSpace(preferences))
                {
                    preferences = Utility.Utility.RemoveLastCharcter(preferences.Trim(), ',');
                }
            }

            model.Preferences = preferences;

            #endregion

            #region Package Mapping

            //Get Package Mapping
            var selectedPackages = reservationRepository.GetReservationPackageMapping(reservation.Id, null, LogInManager.LoggedInUserId).ToList();

            if (selectedPackages != null)
            {
                model.Packages = selectedPackages;

                //model.PackageName = selectedPackage.PackageName;
                //model.PackagePrice = CurrencyManager.ParseAmountToUserCurrency(selectedPackage.PackagePrice, LogInManager.CurrencyCode);
                //model.PackageTotalAmount = CurrencyManager.ParseAmountToUserCurrency(selectedPackage.TotalAmount, LogInManager.CurrencyCode);
            }

            #endregion


            model.Id                = reservation.Id;
            model.ConfirmationNo    = reservation.ConfirmationNumber;
            model.ProfileId         = reservation.ProfileId;
            model.Title             = title.Title;
            model.Email             = profile.Email;
            model.PhoneNo           = profile.TelephoneNo;
            model.Name              = (profile.FirstName + ' ' + profile.LastName);
            model.CarRegistrationNo = profile.CarRegistrationNo;

            #region Fetch Address
            var address = "";
            if (!string.IsNullOrWhiteSpace(profile.Address))
            {
                //address = profile.Address;
                address = profile.Address.Replace(",", Delimeter.SPACE);
            }
            else if (!string.IsNullOrWhiteSpace(profile.HomeAddress))
            {
                //address = profile.HomeAddress;
                address = profile.HomeAddress.Replace(",", Delimeter.SPACE);
            }

            model.Address = address;

            if (!string.IsNullOrWhiteSpace(profile.CityName))
            {
                //model.Address += !string.IsNullOrWhiteSpace(model.Address) ? (Delimeter.SPACE + profile.CityName) : profile.CityName;
                model.City = profile.CityName;
            }

            if (!string.IsNullOrWhiteSpace(profile.StateName))
            {
                //model.Address += !string.IsNullOrWhiteSpace(model.Address) ? (Delimeter.SPACE + profile.StateName) : profile.StateName;
                model.State = profile.StateName;
            }

            if (profile.CountryId.HasValue)
            {
                var country = countryRepository.GetCountryById(profile.CountryId.Value).FirstOrDefault();

                if (country != null)
                {
                    model.Country = country.Name;
                }
            }

            //Split Address

            //if (!string.IsNullOrWhiteSpace(model.Address))
            //{
            //    //var splitAddress = ExtensionMethod.SplitString(model.Address, 40);

            //    var splitAddress  = model.Address.SplitStringChunks(60);

            //    if (splitAddress != null && splitAddress.Length > 0)
            //    {
            //        model.Address1 = splitAddress[0];

            //        if (splitAddress.Length > 1) { model.Address2 = splitAddress[1]; }
            //        if (splitAddress.Length > 2) { model.Address3 = splitAddress[2]; }
            //    }
            //}

            model.ZipCode = profile.ZipCode;
            #endregion

            model.RoomNumer     = roomNumbers;
            model.ArrivalDate   = reservation.ArrivalDate.HasValue ? reservation.ArrivalDate.Value.ToString("dd-MMM-yyyy") : "";
            model.DepartureDate = reservation.DepartureDate.HasValue ? reservation.DepartureDate.Value.ToString("dd-MMM-yyyy") : "";
            model.NoOfNights    = reservation.NoOfNight;
            model.NoOfAdult     = reservation.NoOfAdult;
            model.NoOfChildren  = reservation.NoOfChildren;

            if (roomType != null)
            {
                model.RoomType = roomType.RoomTypeCode;
            }
            model.Rate           = CurrencyManager.ParseAmountToUserCurrency(reservation.Rate, LogInManager.CurrencyCode);
            model.ConfirmationNo = reservation.ConfirmationNumber;

            #region Record Activity Log
            RecordActivityLog.RecordActivity(Pages.SEARCH_ARRIVALS, "Generated guest registration card report.");
            #endregion

            //HTML to PDF
            string html = Utility.Utility.RenderPartialViewToString((Controller)this, "PreviewRegistrationCard", model);

            byte[] pdfBytes = Utility.Utility.GetPDF(html);

            //return File(pdfBytes, "application/pdf", string.Format("RegistrationCard_{0}.pdf", model.Id));
            return(File(pdfBytes, "application/pdf"));

            //return View(model);
        }