public virtual void Delete(T entity)
 {
     ChangeEntityState(entity, EntityState.Modified);
     _context.Entry(entity).Property("Deleted").CurrentValue = true;
 }
Пример #2
0
        /// <summary>
        /// Commits this instance.
        /// </summary>
        private void Commit()
        {
            using (new BusyCursor())
            {
                try
                {
                    if (_deletedItems.Count > 0)
                    {
                        foreach (var item in _deletedItems)
                        {
                            _context.TestDocuments.Remove(item);
                        }
                        _context.SaveChanges();
                        _deletedItems.Clear();
                    }

                    foreach (var document in _documents)
                    {
                        if (_context.Entry(document).State == EntityState.Added)
                        {
                            document.SubmitDate = DateTime.Now;
                            _context.TestDocuments.Add(document);

                            if (_addedDocumentPath.ContainsKey(document.TestDocumentId))
                            {
                                var source = _addedDocumentPath[document.TestDocumentId];

                                try
                                {
                                    ImportExportUtil.CopyDocumentToServer(document, GlobalSettings.Items[Setting.DocumentLibraryServer], source);
                                    TraceFactory.Logger.Debug("File copied");
                                    _addedDocumentPath.Remove(document.TestDocumentId);
                                }
                                catch (UnauthorizedAccessException)
                                {
                                    MessageBox.Show
                                    (
                                        "You do not have authorization to save {0} to the STB Document Server. This document will not be added.".FormatWith(source),
                                        "Unauthorized Access",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error
                                    );
                                }
                                catch (Exception ex)
                                {
                                    MessageBox.Show
                                    (
                                        "A error occurred when trying to save {0} to the STB Document Server. This document will not be added. Error: {1}".FormatWith(source, ex.Message),
                                        "Unauthorized Access",
                                        MessageBoxButtons.OK,
                                        MessageBoxIcon.Error
                                    );
                                }
                            }
                            else if (_importedDocumentData.ContainsKey(document.TestDocumentId))
                            {
                                var data = _importedDocumentData[document.TestDocumentId];
                                ImportExportUtil.WriteDocumentToServer(document, GlobalSettings.Items[Setting.DocumentLibraryServer], data);
                                TraceFactory.Logger.Debug("File imported");
                                _importedDocumentData.Remove(document.TestDocumentId);
                            }
                        }
                    }
                    _context.SaveChanges();
                }
                catch (Exception ex)
                {
                    TraceFactory.Logger.Error(ex);
                    MessageBox.Show
                    (
                        "A error occurred when trying to save to the STB Document Server. This document will not be added. Error: {0}".FormatWith(ex.Message),
                        "Unauthorized Access",
                        MessageBoxButtons.OK,
                        MessageBoxIcon.Error
                    );
                }
            }
        }