Exemplo n.º 1
0
        public async Task <IActionResult> PutHouse(int id, House house)
        {
            if (id != house.Id)
            {
                return(BadRequest("You can only update a house with the same ID"));
            }

            try
            {
                if (IsSameHouse(house))
                {
                    return(BadRequest("House with the same properties already exist"));
                }
                _context.Entry(house).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!HouseExists(id))
                {
                    return(NotFound($"House with such ID {id} does not exist"));
                }
                else
                {
                    throw;
                }
            }

            return(Ok($"House with id: {id} is updated"));
        }
Exemplo n.º 2
0
        public async Task <IActionResult> PutFlat(int id, Flat flat)
        {
            if (id != flat.Id)
            {
                return(BadRequest("You can only update a Flat with the same ID"));
            }

            try
            {
                if (IsTheSameFlat(flat))
                {
                    return(BadRequest("Flat with the same properties already exist"));
                }
                _context.Entry(flat).State = EntityState.Modified;
                await _context.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!FlatExists(id))
                {
                    return(NotFound("Flat with ID {id} does not exist"));
                }
                else
                {
                    throw;
                }
            }

            return(Ok($"Flat with ID {id} is updated"));
        }