//
        // GET: /ProductDocument/Create
        public ActionResult Create()
        {
            SetViewBagData();

            // Generate Decoration method for member initialization
            ProductDocument productDocument = new ProductDocument();
            productDocument.OnCreate();

            return View(productDocument);
        }
        // ProductDocument
        public AuditTrail(DateTime dateTime, string userName, ProductDocument productDocument, int id, string comment)
        {
            this.AuditTrailTimeStamp = dateTime;
            this.AuditTrailUserName = userName;
            this.AuditTrailComment = comment;

            if (id > 0)
            {
                this.ProductDocumentID = id;
            }
            else
            {
                this.ProductDocument = productDocument;
            }
        }
        private void SetViewBagData(ProductDocument productDocument = null)
        {
            var attachmentTypeList = db.AttachmentTypes.Where(a => a.Status != archived);
            var productList = db.Products.Where(p => p.ProductStatus != archived &&
                                                    p.Campaign.CampaignStatus != archived &&
                                                    p.Campaign.Company.CompanyStatus != archived);

            if (productDocument != null)
            {
                ViewBag.AttachmentTypes = new SelectList(attachmentTypeList, "ID", "TypeName", productDocument.AttachmentTypeID);
                ViewBag.Products = new SelectList(productList, "ProductID", "ProductName", productDocument.ProductID);
            }
            else
            {
                ViewBag.AttachmentTypes = new SelectList(attachmentTypeList, "ID", "TypeName");
                ViewBag.Products = new SelectList(productList, "ProductID", "ProductName");
            }
        }
        public ActionResult Edit(ProductDocument productDocument, HttpPostedFileBase Document)
        {
            if (ModelState.IsValid)
            {
                // Add Audit Entry
                AuditTrail audit = new AuditTrail(DateTime.Now, User.Identity.Name, productDocument, productDocument.ID, "Edit");
                db.AuditTrails.Add(audit);

                // Document
                if (Document != null && Document.ContentLength > 0)
                {
                    byte[] documentBinaryData = new byte[Document.ContentLength];
                    int readresult = Document.InputStream.Read(documentBinaryData, 0, Document.ContentLength);
                    productDocument.Document = documentBinaryData;
                    productDocument.DocumentFileType = Document.ContentType;
                    productDocument.DocumentFileName = Document.FileName;
                }

                db.Entry(productDocument).State = EntityState.Modified;
                db.SaveChanges();
                return RedirectToAction("Index");
            }
            SetViewBagData(productDocument);
            return View(productDocument);
        }