private void btnLinkDocument_Click(object sender, EventArgs e) { try { //if (apt.Id == null) //{ // STD.BaseAlert.ShowAlert("Save Appointment", "Please save appointment first", BaseAlert.Buttons.Ok,BaseAlert.Icons.Warning); // //MessageBox.Show("Please save appointment first", "Error", MessageBoxButtons.OK); //} //else //{ using (Essential.UTL.SelectDocumentDialogue dialogue = new Essential.UTL.SelectDocumentDialogue()) { if (dialogue.ShowDialog(this) == DialogResult.OK) { DB.CAL_Attachment attachment = BL.CAL.CAL_Attachment.New; attachment.CalendarId = (Int64)apt.Id; attachment.DocumentId = dialogue.DocumentId; try { using (TransactionScope transaction = DataContext.GetTransactionScope()) { BL.EntityController.SaveCAL_Attachment(attachment, DataContext); DataContext.SaveChangesEntityCalendarContext(); DataContext.CompleteTransaction(transaction); } DataContext.EntityCalendarContext.AcceptAllChanges(); } catch (Exception ex) { DataContext.EntityCalendarContext.RejectChanges(); if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } UpdateAttachments(); } } //} } catch (Exception ex) { if (CDS.Shared.Exception.UserInterfaceExceptionHandler.HandleException(ref ex)) { throw ex; } } }
internal static String Save(DB.CAL_Attachment entry, DataContext dataContext) { try { if (dataContext.EntityCalendarContext.GetEntityState(entry) == System.Data.Entity.EntityState.Detached) { dataContext.EntityCalendarContext.CAL_Attachment.Add(entry); } } catch (System.Data.Entity.Validation.DbEntityValidationException ex) { return(dataContext.PackageValidationException()); } return("Success"); }