50 lines
1.3 KiB
C#
50 lines
1.3 KiB
C#
using System;
|
|
using System.Collections.Generic;
|
|
using System.Linq;
|
|
using System.Threading.Tasks;
|
|
using bahnplan.web.database;
|
|
using bahnplan.web.database.Tables;
|
|
using LinqToDB;
|
|
using Microsoft.AspNetCore.Http;
|
|
using Microsoft.AspNetCore.Mvc;
|
|
using Microsoft.AspNetCore.Mvc.RazorPages;
|
|
using Microsoft.Extensions.Logging;
|
|
|
|
namespace bahnplan.web.Pages {
|
|
public class DeleteModel : PageModel {
|
|
public User AuthorizedUser;
|
|
|
|
public void OnGet() {
|
|
if (HttpContext.Session.GetString("authorized") != "true")
|
|
return;
|
|
|
|
var uid = int.Parse(HttpContext.Session.GetString("uid"));
|
|
using var db = new Database.DbConn();
|
|
AuthorizedUser = db.Users.FirstOrDefault(p => p.UserId == uid);
|
|
var id = int.Parse(Request.Query["id"]);
|
|
|
|
switch (Request.Query["item"]) {
|
|
case "trip": {
|
|
db.Trips.Delete(p => p.TripId == id);
|
|
db.Legs.Delete(p => p.TripId == id);
|
|
break;
|
|
}
|
|
case "leg": {
|
|
var tripid = db.Legs.First(p => p.LegId == id).TripId;
|
|
db.Legs.Delete(p => p.LegId == id);
|
|
if (!db.Legs.Any(p => p.TripId == tripid))
|
|
db.Trips.Delete(p => p.TripId == tripid);
|
|
break;
|
|
}
|
|
case "ticket": {
|
|
db.Legs.Where(p => p.LegId == id).Set(p => p.TicketId, 0).Update();
|
|
break;
|
|
}
|
|
case "card": {
|
|
db.Cards.Delete(p => p.CardId == id);
|
|
break;
|
|
}
|
|
}
|
|
}
|
|
}
|
|
} |