private void btnpicAddEnrollmentDocument_Click(object sender, EventArgs e) { List <Data.Models.File> UploadedFiles = Common.FileHandeling.FileHandeling.UploadFile( UseMultipleFileSelect: true, AutomaicallyAddFileToDatabase: false, ImagesOnly: false); LookupEnrollentDocumentType EDT = (LookupEnrollentDocumentType)lookupEnrollentDocumentTypeBindingSource.Current; foreach (Data.Models.File f in UploadedFiles) { EnrollmentDocument ED = new EnrollmentDocument() { LookupEnrollmentDocumentTypeID = Convert.ToInt32(cboDocumentType.SelectedValue), File = f, LookupEnrollentDocumentType = EDT }; CurrentEnrollment.EnrollmentDocuments.Add(ED); } //foreach (EnrollmentDocument EDItem in CurrentEnrollment.EnrollmentDocuments) //{ // Dbconnection.EnrollmentDocuments.Attach(EDItem); // Dbconnection.Entry(EDItem).Reference(a => a.LookupEnrollentDocumentType).Load(); //} this.refreshDocumentUploads(); }
private void dgvFileUploads_DataBindingComplete(object sender, DataGridViewBindingCompleteEventArgs e) { var gridView = (DataGridView)sender; foreach (DataGridViewRow row in gridView.Rows) { if (!row.IsNewRow) { EnrollmentDocument EnrollmentDocumentObj = (EnrollmentDocument)(row.DataBoundItem); //var IndividualObj = ContactDetailObj.Individual; row.Cells[colFileName.Index].Value = EnrollmentDocumentObj.File.FileName.ToString(); row.Cells[colDocumentType.Index].Value = EnrollmentDocumentObj.LookupEnrollentDocumentType.EnrollmentDocumentType.ToString(); row.Cells[colFileExtension.Index].Value = EnrollmentDocumentObj.File.FileExtension.ToString(); } } }
private void btnpicAddFiles_Click(object sender, EventArgs e) { List <Data.Models.File> UploadedFiles = Common.FileHandeling.FileHandeling.UploadFile( UseMultipleFileSelect: true, AutomaicallyAddFileToDatabase: false, ImagesOnly: false); LookupEnrollentDocumentType EDT = null; using (var Dbconnection = new MCDEntities()) { EDT = (from a in Dbconnection.LookupEnrollentDocumentTypes where a.LookupEnrollmentDocumentTypeID == (int)Common.Enum.EnumEnrollentDocumentTypes.Facilitator_Report select a).FirstOrDefault <LookupEnrollentDocumentType>(); }; int iLookupEnrollmentDocumentTypeID = Convert.ToInt32(cboAttachmentType.SelectedValue); if (iLookupEnrollmentDocumentTypeID != (int)Common.Enum.EnumEnrollentDocumentTypes.ID_Documents) { using (var Dbconnection = new MCDEntities()) { using (System.Data.Entity.DbContextTransaction dbTran = Dbconnection.Database.BeginTransaction()) { try { //CRUD Operations foreach (Data.Models.File f in UploadedFiles) { EnrollmentDocument ED = new EnrollmentDocument() { LookupEnrollmentDocumentTypeID = iLookupEnrollmentDocumentTypeID, File = f, FileID = 0, EnrollmentID = CurrentEnrollmentID }; Dbconnection.EnrollmentDocuments.Add(ED); } ////saves all above operations within one transaction Dbconnection.SaveChanges(); //commit transaction dbTran.Commit(); } catch (Exception ex) { if (ex is DbEntityValidationException) { foreach (DbEntityValidationResult entityErr in ((DbEntityValidationException)ex).EntityValidationErrors) { foreach (DbValidationError error in entityErr.ValidationErrors) { MessageBox.Show(error.ErrorMessage, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } } } else { MessageBox.Show(ex.Message, "Error Message", MessageBoxButtons.OK, MessageBoxIcon.Error); } //Rollback transaction if exception occurs dbTran.Rollback(); } } }; } else { MetroMessageBox.Show(this, "To Link the ID documents, update the student profile by using the student update button.", "Info", MessageBoxButtons.OK, MessageBoxIcon.Information); } refreshEnrollmentDocuments(); //foreach (EnrollmentDocument EDItem in CurrentEnrollment.EnrollmentDocuments) //{ // Dbconnection.EnrollmentDocuments.Attach(EDItem); // Dbconnection.Entry(EDItem).Reference(a => a.LookupEnrollentDocumentType).Load(); //} }