public void DeleteSensorData(string deviceId)
        {
            //TODO: omschrijven naar efficiente code
            //db.SensorData.Where(w => w.DeviceId == deviceId).Delete();
            var toBeDeleted = db.SensorData.Where(w => w.DeviceId == deviceId);

            db.SensorData.RemoveRange(toBeDeleted);
            db.SaveChanges();
        }
示例#2
0
        public void UploadImage(string id, IFormFile postedFile)
        {
            var dataSource = db.DataSource.Single(s => s.DeviceId == id);

            var filePath = Path.GetTempFileName();

            using (var stream = new MemoryStream())
            {
                postedFile.CopyTo(stream);
                dataSource.Image = stream.ToArray();
            }

            db.SaveChanges();
        }
        public void AddNotification(NotificationModel notification)
        {
            try
            {
                var validationContext = new System.ComponentModel.DataAnnotations.ValidationContext(notification);
                Validator.ValidateObject(notification, validationContext);
                db.Notification.Add(mapper.Map <SqlNotification>(notification));
                db.SaveChanges();

                notification.Created = DateTime.Now;
            }
            catch (ValidationException ex)
            {
                logger.Error(ex);
                throw;
            }
        }
示例#4
0
 public void UpdateDataType(DataTypeModel dataType)
 {
     db.Entry(dataType).State = EntityState.Modified;
     db.SaveChanges();
 }