public async Task <IActionResult> PutGarage(int id, GarageDto garage)
        {
            var garageObj = _mapper.Map <Garage>(garage);
            var garageDb  = await _unitOfWork.GarageRepos.GetByIdAsync(id).ConfigureAwait(false);

            if (garageDb == null)
            {
                return(BadRequest());
            }

            garageDb          = garageObj;
            garageDb.GarageId = id;
            _unitOfWork.GarageRepos.Update(garageDb);
            try
            {
                await _unitOfWork.CommitAsync().ConfigureAwait(false);
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!GarageExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(NoContent());
        }
        public async Task <ActionResult <GarageDto> > PostGarage(GarageDto garage)
        {
            var dto = _mapper.Map <Garage>(garage);
            await Task.Run(() => _unitOfWork.GarageRepos.AddAsync(dto)).ConfigureAwait(false);

            await _unitOfWork.CommitAsync().ConfigureAwait(false);

            return(CreatedAtAction("GetGarage", new { id = dto.GarageId }, garage));
        }
示例#3
0
        public async Task <GarageDto> GetGarageById(int garageId)
        {
            //valido que ID no sea nulo
            Throws.ThrowIfNotPositive(garageId, new BadRequestException("ID no puede ser negativo."));

            GarageDto garageDto = await _guardameLugarDacService.GetGarageById(garageId);

            //valido que exista el garage
            Throws.ThrowIfNull(garageDto, new NotFoundException("No se encontro el Garage."));

            return(garageDto);
        }
示例#4
0
        internal static GarageDto BuildGaragesData(IDataReader reader)
        {
            GarageDto garageDto = new GarageDto();

            garageDto.altura_maxima    = int.Parse(reader["altura_maxima"].ToString());
            garageDto.coordenadas      = (reader["coordenadas"].ToString());
            garageDto.direccion        = (reader["direccion"].ToString());
            garageDto.garage_id        = int.Parse(reader["garage_id"].ToString());
            garageDto.localidad_garage = int.Parse(reader["localidad_garage"].ToString());
            garageDto.nombre_localidad = (reader["nombre_localidad"].ToString());
            garageDto.lugar_autos      = int.Parse(reader["lugar_autos"].ToString());
            garageDto.lugar_bicicletas = int.Parse(reader["lugar_bicicletas"].ToString());
            garageDto.lugar_camionetas = int.Parse(reader["lugar_camionetas"].ToString());
            garageDto.lugar_motos      = int.Parse(reader["lugar_motos"].ToString());
            garageDto.nombre_garage    = (reader["nombre_garage"].ToString());
            garageDto.telefono         = (reader["telefono"].ToString());
            return(garageDto);
        }
示例#5
0
        public async Task <ActionResult> GetGarageById(int garageId)
        {
            try
            {
                GarageDto garageDto = await _garageService.GetGarageById(garageId);

                return(Response.Ok(garageDto));
            }
            catch (BaseException e)
            {
                _logger.LogInformation(ExceptionHandlerHelper.ExceptionMessageStringToLogger(e));
                return(Response.HandleExceptions(e));
            }
            catch (Exception e)
            {
                _logger.LogError(e, GetType().Name + "." + MethodBase.GetCurrentMethod().Name);
                return(Response.InternalServerError());
            }
        }
示例#6
0
        public async Task <GarageDto> GetGarageById(int garageId)
        {
            GarageDto     garageDto = null;
            SqlDataReader reader    = null;

            using (SqlCommand oCommand = await base.GetCommandAsync())
            {
                try
                {
                    oCommand.CommandType = CommandType.Text;
                    oCommand.CommandText = @"SELECT * FROM garages g inner join [guardameLugarDB].[dbo].localidades l on g.localidad_garage = l.localidad_id where garage_id = @garage_id order by l.nombre_localidad ;";

                    oCommand.AddParameter("garage_id", DbType.Int32, garageId);

                    IAsyncResult asyncResult = ExecuteAsync(oCommand, "GetGarageById");
                    reader = oCommand.EndExecuteReader(asyncResult);

                    while (await reader.ReadAsync())
                    {
                        garageDto = ModelBuilderHelper.BuildGaragesData(reader);
                    }
                    return(garageDto);
                }
                catch (Exception ex)
                {
                    _logger.LogError(ex, GetType().Name + "." + MethodBase.GetCurrentMethod().Name);
                    throw new AggregateException(_classFullName + ".Localidades()", ex);
                }
                finally
                {
                    if (reader != null && !reader.IsClosed)
                    {
                        reader.Close();
                    }
                    if (!TransactionOpened())
                    {
                        base.CloseCommand();
                    }
                }
            }
        }
        public ApiResponse <GarageDto> EditGarage(GarageDto garage)
        {
            if (garage == null)
            {
                return(new ApiResponse <GarageDto>(responseStatusCode: RestStatusCode.NotFound));
            }

            var garageRepo = _uow.GarageRepository.GetAll().FirstOrDefault();

            if (garageRepo == null)
            {
                return(new ApiResponse <GarageDto>(responseStatusCode: RestStatusCode.NotFound));
            }

            using (_uow.BeginTransaction())
            {
                garage.MergeObjects(garageRepo);
                _uow.GarageRepository.Update(garageRepo);
                _uow.CommitTransaction();
            }

            return(new ApiResponse <GarageDto>(responseResult: garageRepo.ToApi <GarageDto>()));
        }
 public async Task <IActionResult> EditGarage(GarageDto garage)
 {
     return(await Task.Run(() => CallApi(() => _garageService.EditGarage(garage))));
 }
        public async Task <GarageDto> GetGarageById(int garageId)
        {
            GarageDto garageDto = await _guardameLugarDac.GetGarageById(garageId);

            return(garageDto);
        }