Пример #1
0
        public async Task <int> AddValueByHouseId(int houseId, int value)
        {
            var counter = await Context.Set <Counter>().Where(c => c.HouseId == houseId).FirstOrDefaultAsync();

            if (counter != null)
            {
                counter.Value = value;
                return(await Context.SaveChangesAsync());
            }
            throw new NullReferenceException($"Дом c id '{houseId}' не найден");
        }
Пример #2
0
        public async Task <int> CreateNewHouse(House house)
        {
            var street      = house.Street.FormatWhitespaces();
            var houseNumber = house.HouseNumber.FormatWhitespaces();

            house.Street      = street;
            house.HouseNumber = houseNumber;

            await _validator.Validate(house, null);

            await Context.Set <House>().AddAsync(house);

            return(await Context.SaveChangesAsync());
        }
        public async Task <int> Handle(CreateHomeRequest request, CancellationToken cancellationToken)
        {
            var home = new Home(request.Address);

            _db.Homes.Add(home);

            await _db.SaveChangesAsync();

            return(home.Id);
        }
Пример #4
0
        protected override async Task Handle(EditHomeRequest request, CancellationToken cancellationToken)
        {
            var home = await _db.Homes.SingleOrDefaultAsync(x => x.Id == request.Id);

            if (home == null)
            {
                throw DanfossApplicationException.HomeNotFoundException(request.Id);
            }

            home.Address = request.Address;
            await _db.SaveChangesAsync();
        }
        protected override async Task Handle(AddSensorValueBySensorRequest request, CancellationToken cancellationToken)
        {
            var sensor = await _db.Sensors
                         .Include(x => x.Values)
                         .SingleOrDefaultAsync(x => x.SerialNumber.ToLowerInvariant() == request.Serial.ToLowerInvariant());

            if (sensor == null)
            {
                throw DanfossApplicationException.SensorNotFoundException(request.Serial);
            }

            sensor.AddValue(request.Value);

            await _db.SaveChangesAsync();
        }
Пример #6
0
        public async Task <int> Handle(AddSensorRequest request, CancellationToken cancellationToken)
        {
            var home = await _db.Homes.SingleOrDefaultAsync(x => x.Id == request.HomeId);

            if (home == null)
            {
                throw DanfossApplicationException.HomeNotFoundException(request.HomeId);
            }

            var sensor = new Sensor(request.NewSensor.SerialNumber, request.NewSensor.SensorType, home);

            home.AddSensor(sensor);

            await _db.SaveChangesAsync();

            return(sensor.Id);
        }