Esempio n. 1
0
        public async Task <ReestrSetting> CreateReestrSetting(ReestrSetting reestr)
        {
            using (var connection = _applicationContextFactory.CreateConnection())
            {
                await connection.InsertAsync(reestr);

                return(reestr);
            }
        }
Esempio n. 2
0
        public async Task <Customer> CreateCustomer(Customer customer)
        {
            using (var connection = _factory.CreateConnection())
            {
                await connection.InsertAsync(customer);

                return(customer);
            }
        }
Esempio n. 3
0
        public async Task <BarrelStorage> CreateBarrelStorage(BarrelStorage barrelStorage)
        {
            using (var connection = _factory.CreateConnection())
            {
                await connection.InsertAsync(barrelStorage);

                return(barrelStorage);
            }
        }
Esempio n. 4
0
        public async Task <Report> CreateAsync(Report report)
        {
            using (var connection = _factory.CreateConnection())
            {
                int id = await connection.InsertAsync(report);

                report.Id = id;
                return(report);
            }
        }
Esempio n. 5
0
        public async Task <Recipe> CreateRecipe(Recipe recipe)
        {
            using (var connection = _factory.CreateConnection())
            {
                //string query = "INSERT INTO Recipes (`ShortName`, `LongName`, `Brix`, `StorageCondition`, `TransportationCondition`, `Сarbohydrates`, `VitaminC`, `EnergyValue`, `DryContent`) VALUES " +
                //    "(@ShortName,@LongName,@Brix,@StorageCondition,@TransportationCondition,@Сarbohydrates,@VitaminC,@EnergyValue,@DryContent)";

                await connection.InsertAsync(recipe);

                return(recipe);
            }
        }
Esempio n. 6
0
        public async Task <RoomInfo> SaveAsync(RoomInfo roomInfo)
        {
            using (var connection = _factory.CreateConnection())
            {
                roomInfo.Id = await connection.InsertAsync(roomInfo);

                return(roomInfo);
            }
        }
Esempio n. 7
0
        public async Task <IEnumerable <MultiRoomInfo> > FilterRooms(string ipAddress, DateTime from, DateTime to)
        {
            string query = @"SELECT *FROM MultiRoomInfos as r 
							Left join ActiveDevices as d on 
							r.deviceid=d.id where date>=@from and date<=@to and d.ipaddress=@ipAddress"                            ;

            using (var connection = _factory.CreateConnection())
            {
                var result = await connection.QueryAsync <MultiRoomInfo, ActiveDevice, MultiRoomInfo>(query,
                                                                                                      (r, d)
                                                                                                      =>
                {
                    r.ActiveDevice = d;
                    return(r);
                },
                                                                                                      new
                                                                                                      { from = from.Date.ToString("yyyy-MM-dd"), to = to.Date.ToString("yyyy-MM-dd"), ipAddress });

                return(result);
            }
        }
Esempio n. 8
0
        public async Task <Result> ChangeCredential(int id, string login, string password)
        {
            using (var connection = _factory.CreateConnection())
            {
                var query       = "Select *from users where login=@login";
                var existedUser = await connection.QueryFirstOrDefaultAsync <User>(query, new { login });

                if (existedUser != null)
                {
                    return(Result.CreateError("Пользователь с таким логином уже существует"));
                }

                var queryUpdate = "Update users set login=@login,password=@password where id =@id";

                var row = await connection.ExecuteAsync(queryUpdate, (id, password, login));

                return(new Result
                {
                    IsSuccess = row > 0
                });
            }
        }
Esempio n. 9
0
        public async Task TransferData()
        {
            List <RoomInfo> roomInfos = new List <RoomInfo>();

            using (var file = new StreamReader("log.log"))
            {
                int      i = 0;
                string   line;
                RoomInfo room = null;
                while ((line = await file.ReadLineAsync()) != null)
                {
                    if (!line.Contains("ADDED To Graph"))
                    {
                        room = new RoomInfo();
                        i    = 0;
                        continue;
                    }
                    i++;
                    var time = line.Split().TakeWhile(x => x != "[INF]");
                    var agg  = time.Aggregate((a, b) => a + " " + b);
                    var t    = DateTime.Parse(agg.Trim());
                    room.Date     = t;
                    room.DeviceId = 2;
                    if (i == 1)
                    {
                        var h = line.Split().ElementAt(11);
                        room.Humidity = double.Parse(h.Replace(".", ","));
                    }
                    if (i == 2)
                    {
                        var te = line.Split().ElementAt(11);
                        room.Temperature = double.Parse(te.Replace(".", ","));
                        roomInfos.Add(room);
                    }
                }
            }

            using (var connection = _factory.CreateConnection())
            {
                foreach (var item in roomInfos)
                {
                    await connection.InsertAsync(item);
                }
            }
        }
Esempio n. 10
0
        public async Task <Device> CreateAsync(Device device)
        {
            string query = "SELECT *FROM DEVICES WHERE ipaddress =@address";

            using (var connection = _factory.CreateConnection())
            {
                var dev = await connection.QueryFirstOrDefaultAsync <Device>(query, new { address = device.IPAddress });

                if (dev != null)
                {
                    return(dev);
                }


                int id = await connection.InsertAsync(device);

                device.Id = id;
                return(device);
            }
        }
Esempio n. 11
0
        public void Start()
        {
            using (var connection = _factory.CreateConnection())
            {
                try
                {
                    connection.Execute(Query.createMultiRoom);
                    connection.Execute(Query.addDeviceType);
                    //connection.Execute(Query.alterRoomInfos);
                    //connection.Execute(Query.dropReportTable);
                    //connection.Execute(Query.createReportTable);

                    System.Console.WriteLine("Success");
                }
                catch (Exception ex)
                {
                    System.Console.WriteLine(ex.Message);
                    System.Console.WriteLine(ex?.InnerException);
                }
            }
        }
        public async Task <IEnumerable <ActiveDevice> > GetActiveDevicesListsWithReports()
        {
            string query = @"SELECT *FROM ActiveDevices as ad
                            Left join Reports as r on ad.reportid=r.id
							where ad.isAdded = 1 and ad.isActive=1 and r.isclosed=0"                            ;

            using (var connection = _factory.CreateConnection())
            {
                var entities = await connection.QueryAsync <ActiveDevice, Report, ActiveDevice>(query,
                                                                                                (ad, r) =>
                {
                    ad.Report   = r;
                    ad.ReportId = r.Id;
                    return(ad);
                });

                return(entities);
            }
        }
        public async Task <Reestr> CreateReestr(Reestr reestr)
        {
            using (var connection = _factory.CreateConnection())
            {
                int    barrelNumber = 1;
                string firstQuery   = "SELECT * FROM Reestrs ORDER BY id DESC LIMIT 1";

                var result = await connection.QueryFirstOrDefaultAsync <Reestr>(firstQuery);

                if (result != null)
                {
                    barrelNumber = result.BarrelNumber + 1;
                }
                reestr.BarrelNumber = barrelNumber;
                await connection.InsertAsync(reestr);

                return(reestr);
            }
        }