Skip to content

Commit

Permalink
#20 updated view (add is unknown posfix if property is empty)
Browse files Browse the repository at this point in the history
  • Loading branch information
sipakov committed May 22, 2023
1 parent 95192ae commit 6858e1a
Show file tree
Hide file tree
Showing 4 changed files with 78 additions and 27 deletions.
11 changes: 6 additions & 5 deletions AlgoTecture.TelegramBot/Controllers/MainController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -133,22 +133,23 @@ public async Task PressToManageContract()
}

[Action]
private async Task PressAddressToRentButton(string geoAdminFeatureId)
private async Task PressAddressToRentButton(TelegramToAddressModel telegramToAddressModel)
{
var chatId = Context.GetSafeChatId();
if (!chatId.HasValue) return;

var targetAddress = _telegramToAddressResolver.TryGetAddressListByChatId(chatId.Value).FirstOrDefault(x => x.FeatureId == geoAdminFeatureId);
var targetAddress = _telegramToAddressResolver.TryGetAddressListByChatId(chatId.Value).FirstOrDefault(x => x.FeatureId == telegramToAddressModel.FeatureId);

var targetSpace = await _spaceGetter.GetByCoordinates(targetAddress.latitude, targetAddress.longitude);

_telegramToAddressResolver.RemoveAddressListByChatId(chatId.Value);

if (targetSpace == null)
{
var formattedGeoAdminFeatureId = !string.IsNullOrEmpty(geoAdminFeatureId) ? geoAdminFeatureId.Split('_')[0] : string.Empty;
var formattedGeoAdminFeatureId = !string.IsNullOrEmpty(telegramToAddressModel.FeatureId) ? telegramToAddressModel.FeatureId.Split('_')[0] : string.Empty;
PushL("This space will soon be available for rent. Go to space properties or /start to try again");
var urlToAddressProperties = $"https://algotecture.io/webapi-qrcode/spacePropertyPage?featureId={formattedGeoAdminFeatureId}";

var urlToAddressProperties = $"https://algotecture.io/webapi-qrcode/spacePropertyPage?featureId={formattedGeoAdminFeatureId}&label={telegramToAddressModel.Address}";
RowButton("Go to space properties", urlToAddressProperties);
await SendOrUpdate();
}
Expand Down Expand Up @@ -194,7 +195,7 @@ private async Task EnterAddress()
Address = label.label
};
telegramToAddressList.Add(telegramToAddressModel);
RowButton(label.label, Q(PressAddressToRentButton, label.featureId));
RowButton(label.label, Q(PressAddressToRentButton, telegramToAddressModel));
}

if (!labels.Any())
Expand Down
26 changes: 26 additions & 0 deletions AlgoTecture.WebApi.QrCode/Models/GeoAdminBuildingViewModel.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
namespace AlgoTecture.WebApi.QrCode.Models;

public class GeoAdminBuildingViewModel
{
public string BuildingYear { get; set; }

public string BuildingCategory { get; set; }

public string BuildingClass { get; set; }

public string BuildingName { get; set; }

public string Levels { get; set; }

public string Area { get; set; }

public string FloorArea { get; set; }

public string Flats { get; set; }

public string PlaceName { get; set; }

public string MunicipalityId { get; set; }

public string MunicipalityName { get; set; }
}
24 changes: 12 additions & 12 deletions AlgoTecture.WebApi.QrCode/Pages/SpacePropertyPage.cshtml
Original file line number Diff line number Diff line change
Expand Up @@ -4,22 +4,22 @@
ViewData["Title"] = "Home page";
}
<div class="text-center">
<strong>@Model.GeoAdminBuilding.BuildingName</strong>
<strong>@Model.LabelAddress</strong>
</div>
<div class="text-left">
@{
<ol start="1">
<li><strong>Municipality Name</strong>: @Model.GeoAdminBuilding.MunicipalityName</li>
<li><strong>Municipality Id</strong>: @Model.GeoAdminBuilding.MunicipalityId</li>
<li><strong>Place Name</strong>: @Model.GeoAdminBuilding.PlaceName</li>
<li><strong>Building Name</strong>: @Model.GeoAdminBuilding.BuildingName</li>
<li><strong>Building Year</strong>: @Model.GeoAdminBuilding.BuildingYear</li>
<li><strong>Building Category</strong>: @Model.GeoAdminBuilding.BuildingCategory</li>
<li><strong>Building Class</strong>: @Model.GeoAdminBuilding.BuildingClass</li>
<li><strong>Levels</strong>: @Model.GeoAdminBuilding.Levels</li>
<li><strong>Area</strong>: @Model.GeoAdminBuilding.Area</li>
<li><strong>Floor Area</strong>: @Model.GeoAdminBuilding.FloorArea</li>
<li><strong>Flats</strong>: @Model.GeoAdminBuilding.Flats</li>
<li><strong>Municipality Name</strong>: @Model.GeoAdminBuildingView.MunicipalityName</li>
<li><strong>Municipality Id</strong>: @Model.GeoAdminBuildingView.MunicipalityId</li>
<li><strong>Place Name</strong>: @Model.GeoAdminBuildingView.PlaceName</li>
<li><strong>Building Name</strong>: @Model.GeoAdminBuildingView.BuildingName</li>
<li><strong>Building Year</strong>: @Model.GeoAdminBuildingView.BuildingYear</li>
<li><strong>Building Category</strong>: @Model.GeoAdminBuildingView.BuildingCategory</li>
<li><strong>Building Class</strong>: @Model.GeoAdminBuildingView.BuildingClass</li>
<li><strong>Levels</strong>: @Model.GeoAdminBuildingView.Levels</li>
<li><strong>Area</strong>: @Model.GeoAdminBuildingView.Area</li>
<li><strong>Floor Area</strong>: @Model.GeoAdminBuildingView.FloorArea</li>
<li><strong>Flats</strong>: @Model.GeoAdminBuildingView.Flats</li>
</ol>
<div class="text-center">
<button onclick="location.href='https://t.me/AlgoTectureRent_bot'" class="btn btn-primary" type="submit">
Expand Down
44 changes: 34 additions & 10 deletions AlgoTecture.WebApi.QrCode/Pages/SpacePropertyPage.cshtml.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
using AlgoTecture.Libraries.GeoAdminSearch;
using AlgoTecture.Libraries.GeoAdminSearch.Models;
using AlgoTecture.Libraries.GeoAdminSearch.Models.GeoAdminModels;
using AlgoTecture.WebApi.QrCode.Models;
using Microsoft.AspNetCore.Mvc.RazorPages;

namespace AlgoTecture.WebApi.QrCode.Pages;
Expand All @@ -10,7 +10,9 @@ public class SpacePropertyPage : PageModel
private readonly ILogger<SpacePageModel> _logger;
private readonly IGeoAdminSearcher _geoAdminSearcher;

public GeoAdminBuilding GeoAdminBuilding{ get; set; }
public GeoAdminBuildingViewModel GeoAdminBuildingView{ get; set; }

public string LabelAddress { get; set; }


public SpacePropertyPage(ILogger<SpacePageModel> logger, IGeoAdminSearcher geoAdminSearcher)
Expand All @@ -21,24 +23,46 @@ public SpacePropertyPage(ILogger<SpacePageModel> logger, IGeoAdminSearcher geoAd

public async Task OnGet()
{
int featureId = 1;
var data = Request.Query["featureId"];
var isValid = int.TryParse(data, out var value);
var featureId = 1;
var featureIdStr = Request.Query["featureId"];
var labelStr = Request.Query["label"];
var isValidFeatureIdStr = int.TryParse(featureIdStr, out var valueFeatureId);

if (isValid)
if (isValidFeatureIdStr)
{
featureId = value;
featureId = valueFeatureId;
}

LabelAddress = labelStr;

var buildingProperties = await _geoAdminSearcher.GetBuildingModel(new GeoAdminSearchBuildingModel()
{
Latitude = 0,
Longitude = 0,
FeatureId = featureId
});

GeoAdminBuilding = buildingProperties ?? throw new ArgumentNullException($"$Nothing found with featureId ={featureId}");


if (buildingProperties == null)
{
throw new ArgumentNullException($"$Nothing found with featureId ={featureId}");
}

const string isUnknownStr = "is unknown";
var formattedGeoAdminBuilding = new GeoAdminBuildingViewModel()
{
MunicipalityName = string.IsNullOrEmpty(buildingProperties.MunicipalityName) ? $"municipality name {isUnknownStr}" : buildingProperties.MunicipalityName,
MunicipalityId = buildingProperties.MunicipalityId == default ? $"municipality id {isUnknownStr}" : buildingProperties.MunicipalityId.ToString(),
PlaceName = string.IsNullOrEmpty(buildingProperties.PlaceName) ? $"place name {isUnknownStr}" : buildingProperties.PlaceName,
BuildingName = string.IsNullOrEmpty(buildingProperties.BuildingName) ? $"building name {isUnknownStr}" : buildingProperties.BuildingName,
BuildingYear = buildingProperties.BuildingYear == default ? $"building year {isUnknownStr}" : buildingProperties.BuildingYear.ToString(),
BuildingCategory = string.IsNullOrEmpty(buildingProperties.BuildingCategory) ? $"building category {isUnknownStr}" : buildingProperties.BuildingCategory,
BuildingClass = string.IsNullOrEmpty(buildingProperties.BuildingClass) ? $"building class {isUnknownStr}" : buildingProperties.BuildingClass,
Levels = buildingProperties.Levels == default ? $"levels {isUnknownStr}" : buildingProperties.Levels.ToString(),
Area = buildingProperties.Area == default ? $"area {isUnknownStr}" : buildingProperties.Area.ToString(),
FloorArea = buildingProperties.FloorArea == default ? $"floor area {isUnknownStr}" : buildingProperties.FloorArea.ToString(),
Flats = buildingProperties.Flats == default ? $"flats {isUnknownStr}" : buildingProperties.Flats.ToString(),
};

GeoAdminBuildingView = formattedGeoAdminBuilding;
}
}

0 comments on commit 6858e1a

Please sign in to comment.