Ejemplo n.º 1
0
        public async Task <IActionResult> Put(int residenceTypeId, ResidenceType residenceType)
        {
            try
            {
                residenceType.ResidenceTypeId = residenceTypeId;
                var upd = await _repo.GetResidenceTypeAsyncById(residenceTypeId);

                if (upd == null)
                {
                    return(NotFound());
                }

                _repo.Update(residenceType);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/ResidenceType/{residenceType.ResidenceTypeId}", residenceType));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ApiReturnMessages.DbFailed));
            }

            return(BadRequest());
        }
Ejemplo n.º 2
0
        public async Task <IActionResult> Put(int residenceId, ResidenceDto residence)
        {
            try
            {
                residence.ResidenceId = residenceId;

                var upd = await _repo.GetResidenceAsyncById(residenceId);

                if (upd == null)
                {
                    return(NotFound());
                }

                _mapper.Map(residence, upd);

                //Validate data integrity in ViaCep Api
                upd = await _repo.GetAddressByViaCepApiAsync(upd);

                if (upd.ZipCode == null)
                {
                    return(NotFound(ApiReturnMessages.ZipCodeNotFound));
                }

                _repo.Update(upd);

                if (await _repo.SaveChangesAsync())
                {
                    return(Created($"/api/Residence/{residence.ResidenceId}", residence));
                }
            }
            catch (System.Exception)
            {
                return(this.StatusCode(StatusCodes.Status500InternalServerError, ApiReturnMessages.DbFailed));
            }

            return(BadRequest());
        }