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());
        }
Example #3
0
        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);
        }
Example #4
0
 public async Task AddHuntingSpotAsync(HuntingSpot huntingSpot)
 {
     _context.HuntingSpot.Add(huntingSpot);
     await _context.SaveChangesAsync();
 }