Ejemplo n.º 1
0
        public async Task <Response> UpdateBySerialNumber(string serialNumber, WaterMeterUpdateModel waterMeter)
        {
            WaterMeterModel targetWaterMeter = await _dbContext.WaterMeters.FirstOrDefaultAsync(w => w.SerialNumber.Equals(serialNumber));

            if (targetWaterMeter is null)
            {
                return new Response {
                           Message = "Счетчик не найден."
                }
            }
            ;

            WaterMeterModel convertWaterMeter = Mapper.Map <WaterMeterUpdateModel, WaterMeterModel>(waterMeter);

            return(await UpdateWaterMeterValues(targetWaterMeter, convertWaterMeter));
        }
Ejemplo n.º 2
0
        public async Task <IHttpActionResult> UpdateByBuildingId(int id, WaterMeterUpdateModel waterMeter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Response result = await _waterMetersService.UpdateByBuildingId(id, waterMeter);

            if (result.Ok)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }
Ejemplo n.º 3
0
        public async Task <Response> UpdateByBuildingId(int buildingId, WaterMeterUpdateModel waterMeter)
        {
            WaterMeterModel targetWaterMeter = await _dbContext.Buildings
                                               .Include(b => b.WaterMeter)
                                               .Where(b => b.Id == buildingId)
                                               .Select(b => b.WaterMeter)
                                               .FirstOrDefaultAsync();

            if (targetWaterMeter is null)
            {
                return new Response {
                           Message = "Счетчик не найден."
                }
            }
            ;

            WaterMeterModel convertWaterMeter = Mapper.Map <WaterMeterUpdateModel, WaterMeterModel>(waterMeter);

            return(await UpdateWaterMeterValues(targetWaterMeter, convertWaterMeter));
        }
Ejemplo n.º 4
0
        public async Task <IHttpActionResult> UpdateBySerialNumber(string serialNumber, WaterMeterUpdateModel waterMeter)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            Response result = await _waterMetersService.UpdateBySerialNumber(serialNumber, waterMeter);

            if (result.Ok)
            {
                return(Ok());
            }
            else
            {
                return(BadRequest(result.Message));
            }
        }