/// <summary> /// Used to download image from Alerts collection /// </summary> /// <param name="alert">Single alert field</param> /// <param name="imgId">Id of downloading image</param> /// <param name="number">ordinal number, must be unique</param> /// <returns></returns> public string DownloadImage(Alerts alert, ObjectId imgId, int number) { var bucket = new GridFSBucket(db); var bytes = bucket.DownloadAsBytes(imgId); var image = BytesToImage(bytes); string path = alert.StudentFirstAndLastName + "\\" + alert.AlertName; //If Directory does not exists then... if (!(Directory.Exists(path))) { Directory.CreateDirectory(path); } string cleanString = Regex.Replace(alert.AddDate, @"[^0-9]", "_"); string fileName = cleanString + "_" + number + ".jpg"; path = Path.Combine(path, fileName); Bitmap b = new Bitmap(image); b.Save(path); return(path); }
/// <summary> /// Adding alert to AllertsHistory collection for current workstation /// </summary> /// <param name="alert">Allert to history.</param> /// <param name="previousStudentName">First and last name of previous student</param> /// <param name="previousUserName">Previous user name</param> public void AlertHistoryMakeNew(Alerts alert) { Console.WriteLine("1"); AlertsHistory newDocument = new AlertsHistory { WorkstationName = StationInformation.WorkstationName, StudentFirstAndLastName = alert.StudentFirstAndLastName, AddDate = alert.AddDate, AlertName = alert.AlertName, Link1 = alert.Link1, Link2 = alert.Link2, Link3 = alert.Link3 }; try { RefreshAlertsHistory(); alertHistoryCollection.InsertOne(newDocument); } catch (Exception ex) { MessageBox.Show("Wystąpił błąd podczas dodawania dokumentu <AlertsHistory> do bazy danych. Treść błędu: /n /n" + ex); } }