Exemple #1
0
        /// <summary>
        /// Get a specific Document
        /// </summary>
        /// <param name="id">Document Id</param>
        /// <param name="authorized">bool to check if user should be able to retrieve HIDDEN documents</param>
        /// <returns></returns>
        public tbl_Document SelectById(string id, bool authorized)
        {
            int          docId;
            tbl_Document document = null;

            try
            {
                docId = Int32.Parse(id);

                if (authorized == true)
                {
                    document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId);
                }
                else
                {
                    document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId && p.Active_IND == true);
                }

                //if document exists and ArchiveFile is null, it will look into the purged WAS db instead.
                if (document.ArchivedFile == null)
                {
                    this._db = new WASEntities("name=WASArchiveEntities");

                    if (authorized == true)
                    {
                        document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId);
                    }
                    else
                    {
                        document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId && p.Active_IND == true);
                    }
                    //Because this is a rare occurance, I would rather blindly search through other db's than change my model to bring in the repo value
                    //if more than one repo is used, we will have to create a repo attribute on the document model and bring tbl_Document.Repository_ID over to check and find
                }

                return(document);
            }
            catch (FormatException e)
            {
                FormatException exception = new FormatException("Document Id must be a positive integer", e);
                exception.HelpLink            = "Please check over the provided information and try again.";
                exception.Data["Document ID"] = id;

                throw exception;
            }
            catch (InvalidOperationException e) {
                InvalidOperationException exception = new InvalidOperationException("There was an issue connecting to the database", e);
                exception.HelpLink = "Please contact Support through ServiceNow.";

                throw exception;
            }
            catch (Exception e)
            {
                //maybe write more here
                throw new Exception("There seems to be an issue.", e);
            }
        }
Exemple #2
0
        /// <summary>
        /// Updates the entity model with the changes, but does not save.
        /// </summary>
        /// <param name="publicVM">The publicVm instance</param>
        /// <param name="db">the database</param>
        /// <returns>(make use of this)</returns>
        public bool UpdateChanges(PublicVM publicVM, WASEntities db)
        {
            tbl_Document modDoc = SelectById(publicVM.Document_ID.ToString(), true);

            //maybe more elegant way to do this
            modDoc.Issue_DT    = publicVM.IssueDate;
            modDoc.Description = publicVM.Description;
            modDoc.Method      = publicVM.Method;
            modDoc.Originator  = publicVM.Originator;
            modDoc.Reason      = publicVM.Reason;
            modDoc.Recipient   = publicVM.Recipient;
            modDoc.Active_IND  = publicVM.Hidden;

            db.Entry(modDoc).State = System.Data.Entity.EntityState.Modified; //tags the row as one thats modifed and needs to be saved

            //should probably do some conditional check here to allow user to know if it actually got modified
            return(true);
        }
        public tbl_Document SelectById(string id, bool authorized)
        {
            int          docId    = 0;
            tbl_Document document = null;

            try {
                docId = Int32.Parse(id);

                if (authorized == true)
                {
                    document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId);
                }
                else
                {
                    document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId && p.Active_IND == true);
                }

                //if document exists and ArchiveFile is null, it will look into the purged WAS db instead.
                if (document.ArchivedFile == null)
                {
                    this._db = new WASEntities("name=WASArchiveEntities");

                    if (authorized == true)
                    {
                        document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId && p.Active_IND == true);
                    }
                    else
                    {
                        document = _db.tbl_Document.AsNoTracking().SingleOrDefault(p => p.Document_ID == docId && p.Active_IND == false);
                    }
                    //Because this is a rare occurance, I would rather blindly search through other db's than change my model to bring in the repo value
                    //if more than one repo is used, we will have to create a repo attribute on the document model and bring tbl_Document.Repository_ID over to check and find
                }
            } catch {
                return(null);
            }

            return(document);
        }
 public FolderRepository()
 {
     this._db = new WASEntities();
 }
Exemple #5
0
 public PublicRepository()
 {
     this._db = new WASEntities(); //dbcontext class
 }
 public DocumentRepository()
 {
     this._db = new WASEntities();
 }