//string image, int challengeID, int studentID // שמירת שם הקובץ של תמונת האתגר בדאטה בייס public int putChallengeImage(StudentChallenge sc) { // התמונה מתקבלת מהצד לקוח כבייס 64, שומרים אותה במשתנה string base64StringData = sc.Image; // Your base 64 string data //מחלצים את סוג הקובץ מתוך הסטרינג של הבייס64 string type = base64StringData.Substring(base64StringData.IndexOf("/") + 1); //remove everything before the first / include type = type.Substring(0, type.IndexOf(";")); // remove everything after the first ; include // מגדירים ששם הקובץ יהיה המספר המזהה של האתגר עם הסיומת המתאימה string fileName = sc.ChallengeID.ToString() + 's' + sc.StudentID.ToString() + "." + type; // נתיב התמונה כדי לשמור את התמונה בתיקייה - נלקח מהמחלקה הסטטית שלנו בתוספת שם הקובץ string imagePath = PathOfImage.path + fileName; // חותכים את התחלת הסטרינג כי זה מיותר string cleandata = base64StringData.Replace("data:image/" + type + ";base64,", ""); // עושים המרה מבייס 64 למערך של ביטים byte[] data = System.Convert.FromBase64String(cleandata); MemoryStream ms = new MemoryStream(data); System.Drawing.Image img = System.Drawing.Image.FromStream(ms); // שומרים את התמונה בנתיב שהגדרנו img.Save(imagePath, System.Drawing.Imaging.ImageFormat.Png); // שומרים בטבלה בדאטה בייס את נתיב התמונה DBservices dbs = new DBservices(); return(dbs.putChallengeImage(fileName, sc.ChallengeID, sc.StudentID)); }
public int putStudentChallenge(StudentChallenge sc) { DBservices dbs = new DBservices(); return(dbs.updateStudentChallenge(sc)); }
public int postStudentChallenge(StudentChallenge sc) { DBservices dbs = new DBservices(); return(dbs.postStudentChallenge(sc)); }