Ejemplo n.º 1
0
        public async Task <IActionResult> PutPlace([FromRoute] int id, [FromBody] Place place)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != place.Id)
            {
                return(BadRequest());
            }

            _context.Entry(place).State = EntityState.Modified;

            try
            {
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!PlaceExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> CreateNewPlace([FromBody] Place place)
        {
            var newId = _context.Places.Select(x => x.Id).Max() + 1;

            place.Id          = newId;
            place.LastUpdated = DateTime.Now;

            await _context.AddAsync(place);

            int rowAffected = await _context.SaveChangesAsync();

            if (rowAffected > 0)
            {
                await _hubContext.Clients.All.SendAsync("AddedNewPlace", place.Id, place.Name);
            }

            return(Ok(place));
        }