public async Task <IActionResult> EditHuntingSpot(int id, HuntingSpot huntingSpot) { var hSpot = await _repository.UpdateHuntingSpotAsync(id, huntingSpot); if (hSpot == null) { return(NotFound()); } return(Ok(hSpot)); }
public async Task <IActionResult> PostHuntingSpotAsync(HuntingSpot huntingSpot) { if (!ModelState.IsValid) { return(BadRequest(ModelState)); } await _repository.AddHuntingSpotAsync(huntingSpot); return(Ok()); }
public async Task <HuntingSpot> UpdateHuntingSpotAsync(int id, HuntingSpot huntingSpot) { var hSpot = _context.HuntingSpot.FirstOrDefault(x => x.Id == id); if (hSpot == null) { return(null); } hSpot.Name = huntingSpot.Name; hSpot.Location = huntingSpot.Location; _context.HuntingSpot.Update(hSpot); await _context.SaveChangesAsync(); return(hSpot); }
public async Task AddHuntingSpotAsync(HuntingSpot huntingSpot) { _context.HuntingSpot.Add(huntingSpot); await _context.SaveChangesAsync(); }