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(); }
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; } }
public void UpdateDataType(DataTypeModel dataType) { db.Entry(dataType).State = EntityState.Modified; db.SaveChanges(); }