public IActionResult OnPost(IOTDeviceSmartMeter employee)
        {
            if (Photo != null)
            {
                // If a new photo is uploaded, the existing photo must be
                // deleted. So check if there is an existing photo and delete
                if (employee.PhotoPath != null)
                {
                    string filePath = Path.Combine(webHostEnvironment.WebRootPath,
                                                   "images", employee.PhotoPath);
                    System.IO.File.Delete(filePath);
                }
                // Save the new photo in wwwroot/images folder and update
                // PhotoPath property of the employee object
            }
            StreamReader streamReader = new StreamReader(ProcessUploadedFilePath());
            string       data         = streamReader.ReadToEnd();
            //List<IOTDeviceSmartMeter> IOTDEviceDetails = JsonConvert.DeserializeObject<List<IOTDeviceSmartMeter>>(data);


            var jsonremovenull = JsonConvert.SerializeObject(
                data,
                new JsonSerializerSettings {
                NullValueHandling = NullValueHandling.Ignore
            });


            var res = "";

            //IOTDEviceDetails.ForEach(p =>
            //{
            //    IOTDeviceSmartMeter IOTDEvice = new IOTDeviceSmartMeter()
            //    {
            //        EnergyAmountkWh = p.EnergyAmountkWh,
            //        VoltageReading = p.VoltageReading,
            //        PowerReading = p.PowerReading,
            //        DeviceId = p.DeviceId,
            //        ConnectionStatus = p.ConnectionStatus,
            //        EventProcessedUtcTime = p.EventProcessedUtcTime
            //    };
            // _BillingData.AddJsonIOTDeviceSmartMeter(IOTDEvice);
            //db.SaveChanges();
            _BillingData.AddJsonIOTDeviceSmartMeterJson(jsonremovenull);
            Message         = "Data Uploaded Successfully";
            TempData["msg"] = Message;
            //    });
            //ViewBag.Success = "File uploaded Successfully..";Stackholders
            //Employee = employeeRepository.Update(employee);
            return(RedirectToPage("/Stackholders/UploadJson"));
        }
示例#2
0
        public IOTDeviceSmartMeter AddJsonIOTDeviceSmartMeter(IOTDeviceSmartMeter newIOTDEvice)
        {
            //SqlParameter EnergyAmountkWh = new SqlParameter("@EnergyAmountkWh", newIOTDEvice.EnergyAmountkWh);
            //SqlParameter VoltageReading = new SqlParameter("@VoltageReading", newIOTDEvice.VoltageReading);
            //SqlParameter PowerReading = new SqlParameter("@PowerReading", newIOTDEvice.PowerReading);
            //SqlParameter ConnectionStatus = new SqlParameter("@ConnectionStatus", newIOTDEvice.ConnectionStatus);
            //SqlParameter DeviceId         = new SqlParameter("@DeviceId", newIOTDEvice.DeviceId);
            //SqlParameter EventProcessedUtcTime = new SqlParameter("@EventProcessedUtcTime", newIOTDEvice.EventProcessedUtcTime);


            //_context.Database.ExecuteSqlRaw("dbo.Insert_Select_AllIOTDeviceSmartMeter @EnergyAmountkWh, @VoltageReading,@PowerReading,@ConnectionStatus,@DeviceId,@EventProcessedUtcTime",
            // EnergyAmountkWh, VoltageReading, PowerReading,ConnectionStatus ,
            //DeviceId,EventProcessedUtcTime);
            //return newIOTDEvice;   Insert_Select_AllIOTDeviceSmartMeterJson
            _context.Database.ExecuteSqlRaw("dbo.Insert_Select_AllIOTDeviceSmartMeter  { 0},{ 1},{ 2},{ 3},{ 4},{ 5}",

                                            newIOTDEvice.EnergyAmountkWh, newIOTDEvice.VoltageReading, newIOTDEvice.PowerReading, newIOTDEvice.ConnectionStatus,
                                            newIOTDEvice.DeviceId, newIOTDEvice.EventProcessedUtcTime);
            return(newIOTDEvice);
        }