public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Vydra = await _context.Vydras.Include(v => v.Children).AsNoTracking().FirstOrDefaultAsync(m => m.TattooID == id); if (Vydra != null) { if (Vydra.Children.Count == 0) { _context.Vydras.Remove(Vydra); await _context.SaveChangesAsync(); } else { foreach (var item in Vydra.Children) { item.Mother = null; } _context.Vydras.Remove(Vydra); await _context.SaveChangesAsync(); //return RedirectToPage("./DeleteError"); } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { /*if (!ModelState.IsValid) * { * return Page(); * }*/ //old place object Place placeold = await _context.Places .Include(p => p.Vydry).SingleOrDefaultAsync <Place>(p => p.Name == PlaceData.OriginalName && p.LocationId == PlaceData.OriginalLocationId); //new place object Place placenew = new Place() { LocationId = PlaceData.LocationId, Name = PlaceData.Name }; //insert new over old _context.Places.Add(placenew); foreach (var item in placeold.Vydry) { item.PlaceName = placenew.Name; item.LocationId = placenew.LocationId; } //remove old place _context.Places.Remove(placeold); //_context.Attach(Place).State = EntityState.Modified; await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Attach(Location).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!LocationExists(Location.LocationID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { /*if (!ModelState.IsValid) * { * return Page(); * }*/ Vydra.founderID = GetUserId(); _vydraLogic.PlaceLocationSplit(Vydra, newPlace); _context.Attach(Vydra).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VydraExists(Vydra.TattooID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { /*if (!ModelState.IsValid) * { * return Page(); * }*/ Vydra.founderID = GetUserId(); Place = _context.Places.Include(p => p.Location).Include(p => p.Vydry).AsNoTracking().FirstOrDefault(p => p.Name == Vydra.PlaceName); Place.Name = Vydra.PlaceName; Vydra.LocationId = Place.LocationId; _context.Attach(Vydra).State = EntityState.Modified; try { await _context.SaveChangesAsync(); } catch (DbUpdateConcurrencyException) { if (!VydraExists(Vydra.TattooID)) { return(NotFound()); } else { throw; } } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { if (!ModelState.IsValid) { return(Page()); } _context.Locations.Add(Location); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { /*if (!ModelState.IsValid) * { * return Page(); * }*/ _context.Places.Add(Place); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { /*if (!ModelState.IsValid) * { * return Page(); * }*/ Vydra.founderID = GetUserId(); _vydraLogic.PlaceLocationSplit(Vydra, newPlace); _context.Vydras.Add(Vydra); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Vydra = await _context.Vydras.FindAsync(id); if (Vydra != null) { _context.Vydras.Remove(Vydra); await _context.SaveChangesAsync(); } return(RedirectToPage("./Index")); }
// To protect from overposting attacks, enable the specific properties you want to bind to, for // more details, see https://aka.ms/RazorPagesCRUD. public async Task <IActionResult> OnPostAsync() { /*if (!ModelState.IsValid) * { * return Page(); * }*/ Vydra.founderID = GetUserId(); //Place = _context.Places.Include(p => p.Location).Include(p => p.Vydry).AsNoTracking().FirstOrDefault(p => p.Name == Vydra.PlaceName); //Place.Name = Vydra.PlaceName; string[] data; data = Vydra.PlaceName.Split(';'); Vydra.LocationId = int.Parse(data[0]); Vydra.PlaceName = data[1]; //Vydra.LocationId = Place.LocationId; _context.Vydras.Add(Vydra); await _context.SaveChangesAsync(); return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(string id, int?Lid) { if (id == null) { return(NotFound()); } Place = await _context.Places.Include(p => p.Vydry).AsNoTracking().FirstOrDefaultAsync(m => m.Name == id && m.LocationId == Lid); if (Place != null) { if (Place.Vydry.Count == 0) { _context.Places.Remove(Place); await _context.SaveChangesAsync(); } else { return(RedirectToPage("../DeleteError")); } /*foreach (var item in Place.Vydry) * { * if (item.PlaceName == id && item.LocationID == Place.LocationId) * { * item.PlaceName = "Removed"; * item.LocationId = Place.LocationId; * _context.Vydras.Remove(item); * _context.Places.Remove(Place); * await _context.SaveChangesAsync(); * return RedirectToPage("../DeleteError"); * } * }*/ } return(RedirectToPage("./Index")); }
public async Task <IActionResult> OnPostAsync(int?id) { if (id == null) { return(NotFound()); } Location = await _context.Locations.Include(l => l.Places).AsNoTracking().FirstOrDefaultAsync(m => m.LocationID == id); if (Location != null) { if (Location.Places.Count == 0) { _context.Locations.Remove(Location); await _context.SaveChangesAsync(); } else { return(RedirectToPage("../DeleteError")); } } return(RedirectToPage("./Index")); }