Skip to content

Commit

Permalink
feat: remove db for preview
Browse files Browse the repository at this point in the history
  • Loading branch information
joshuasir committed Oct 29, 2024
1 parent cab01be commit 59c215a
Showing 1 changed file with 84 additions and 47 deletions.
131 changes: 84 additions & 47 deletions KarcisApp/Karcis/Controllers/HomeController.cs
Original file line number Diff line number Diff line change
Expand Up @@ -23,66 +23,103 @@ public HomeController(ILogger<HomeController> logger)
_logger = logger;
}


public async Task<IActionResult> IndexAsync()
{

var client = new HttpClient();

// get event data
var request = new HttpRequestMessage
try
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:42069/event?keyword=FEST"),
Content = new StringContent("", Encoding.UTF8, MediaTypeNames.Application.Json /* or "application/json" in older versions */),
};

var response = await client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

var events = JsonConvert.DeserializeObject<Events>(responseBody);
var HomeView = new HomeViewModel()
{
Event = events.events[0],
User = new UserModel()
using (var client = new HttpClient())
{
UserName = HttpContext.Session.GetString("UserName")

// get event data
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:42069/event?keyword=FEST"),
Content = new StringContent("", Encoding.UTF8, MediaTypeNames.Application.Json /* or "application/json" in older versions */),
};

var response = await client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

var events = JsonConvert.DeserializeObject<Events>(responseBody);
var HomeView = new HomeViewModel()
{
Event = events.events[0],
User = new UserModel()
{
UserName = HttpContext.Session.GetString("UserName")
}

};
return View(HomeView);
}
}
catch (Exception ex) {

Check warning on line 60 in KarcisApp/Karcis/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
var HomeView = new HomeViewModel()
{
Event = new EventViewModel() {
EventID = 0,
EventStart = DateTime.Now,
EventEnd = DateTime.Now.AddDays(7),
EventDescription= "Biggest event of your life",
EventLocation = "Zoom",
EventName = "Meeting with Boss"
},
User = new UserModel()
{
UserName = HttpContext.Session.GetString("UserName")
}

};
return View(HomeView);

};
return View(HomeView);
}

}

public async Task<IActionResult> Ticket()
{
var client = new HttpClient();
// request available ticket quantity
var request = new HttpRequestMessage
try {
using (var client = new HttpClient())
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:42069/ticket?EventName=FEST"),
Content = new StringContent("", Encoding.UTF8, MediaTypeNames.Application.Json /* or "application/json" in older versions */),
};
var response = await client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();
// request available ticket quantity
var request = new HttpRequestMessage
{
Method = HttpMethod.Get,
RequestUri = new Uri("http://localhost:42069/ticket?EventName=FEST"),
Content = new StringContent("", Encoding.UTF8, MediaTypeNames.Application.Json /* or "application/json" in older versions */),
};
var response = await client.SendAsync(request).ConfigureAwait(false);
response.EnsureSuccessStatusCode();

var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

// map to dictionary for static calling
var tickets = JsonConvert.DeserializeObject<List<TicketViewModel>>(responseBody);
var TicketsDict = new Dictionary<string, TicketViewModel>();

tickets.ForEach(e =>
{
if (!TicketsDict.ContainsKey(e.TicketType))
var responseBody = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

// map to dictionary for static calling
var tickets = JsonConvert.DeserializeObject<List<TicketViewModel>>(responseBody);
var TicketsDict = new Dictionary<string, TicketViewModel>();

tickets.ForEach(e =>
{
TicketsDict.Add(e.TicketType, e);
}
});
return View("MainTicket", TicketsDict);
if (!TicketsDict.ContainsKey(e.TicketType))
{
TicketsDict.Add(e.TicketType, e);
}
});
return View("MainTicket", TicketsDict);
}
}catch(Exception ex)

Check warning on line 114 in KarcisApp/Karcis/Controllers/HomeController.cs

View workflow job for this annotation

GitHub Actions / build

The variable 'ex' is declared but never used
{
var TicketsDict = new Dictionary<string, TicketViewModel>();
TicketsDict.Add("Golden", new TicketViewModel());
TicketsDict.Add("Platinum", new TicketViewModel());
TicketsDict.Add("Bronze", new TicketViewModel());
TicketsDict.Add("Silver", new TicketViewModel());
return View("MainTicket", TicketsDict);
}
}

[HttpPost]
Expand Down

0 comments on commit 59c215a

Please sign in to comment.