/// <summary>
 /// Create a new ProductionJobAttachment object.
 /// </summary>
 /// <param name="id">Initial value of the ID property.</param>
 /// <param name="jobID">Initial value of the JobID property.</param>
 public static ProductionJobAttachment CreateProductionJobAttachment(global::System.Decimal id, global::System.Decimal jobID)
 {
     ProductionJobAttachment productionJobAttachment = new ProductionJobAttachment();
     productionJobAttachment.ID = id;
     productionJobAttachment.JobID = jobID;
     return productionJobAttachment;
 }
        protected void UpdateJobAttachments(ProductionJob editJob, FileAttacher attacher)
        {
            if (attacher != null)
            {
                List<string> delIDS = attacher.DelFileIDs();
                if (delIDS.IsAny())
                {
                    string sql = "DELETE FROM FG_PRDN_JOB_ATTACHMENT WHERE FG_PRDN_JOB_ATT_ID IN (" +
                        PrdnDataHelper.ParmFormatList(delIDS.Count()) + ")";
                    PrdnDBContext.ExecuteStoreCommand(sql, delIDS.Cast<object>().ToArray());
                }

                if (attacher.NotNullAny(a => a.ExtantFiles))
                {
                    foreach (var dbFile in attacher.ExtantFiles)
                    {
                        var mods = editJob.Attachments.Where(a =>
                            (a.ID == dbFile.DecimalID)
                            && ((a.AttachmentTypeID != dbFile.AttTypeID) && (dbFile.AttTypeID != null)
                                || a.Description != dbFile.Description)
                        );
                        foreach (var modFile in mods)
                        {
                            modFile.AttachmentTypeID = (decimal)dbFile.AttTypeID;
                            modFile.Description = dbFile.Description;
                        }
                    }
                };
                if (attacher.NotNullAny(a => a.CachedFiles))
                {
                    foreach (var newFile in attacher.CachedFiles)
                    {
                        CST.Prdn.Data.ProductionJobAttachment newAttachment = new CST.Prdn.Data.ProductionJobAttachment
                        {   //JobID = editJob.ID,
                            FileName = newFile.FileName,
                            MimeType = newFile.MimeType,
                            Description = newFile.Description,
                            Attachment = newFile.FileData
                        };
                        if (newFile.AttTypeID != null)
                        {
                            newAttachment.AttachmentTypeID = (decimal)newFile.AttTypeID;
                        }
                        editJob.Attachments.Add(newAttachment);
                    }
                }
            }
        }
 /// <summary>
 /// Deprecated Method for adding a new object to the ProductionJobAttachments EntitySet. Consider using the .Add method of the associated ObjectSet&lt;T&gt; property instead.
 /// </summary>
 public void AddToProductionJobAttachments(ProductionJobAttachment productionJobAttachment)
 {
     base.AddObject("ProductionJobAttachments", productionJobAttachment);
 }
        //[HttpPost]
        //public ActionResult RequestRun()
        //{
        //    RequestScheduleViewModel model = null;
        //    if (TryValidateModel(model)) {
        //        return RedirectToAction(actionName: model.RouteAction, controllerName: model.RouteController,
        //                routeValues: new
        //                {
        //                    requestID = model.RequestID,
        //                    urlReturn = model.UrlReturn,
        //                    runID = model.RunID
        //                });
        //    }
        //    else {
        //        model.LookupRunModel = new PrdnRunLookupModel();
        //        model.NewRunModel = new NewPrdnRunViewModel(Session, model.RouteController, model.RouteAction,
        //            new RequestCreateRunActionParm { RequestID = model.RequestID, UrlReturn = model.UrlReturn });
        //        return View(model);
        //    }
        //}
        protected void UpdateScheduledRequest(EditPrdnJobViewModel newViewJob, ProductionJob job)
        {
            if (job.CstRequestID == null) {
                return;
            }

            var request = (from r in PrdnDBContext.Requests
                            where r.ID == job.CstRequestID
                            select r).FirstOrDefault();

            if (request != null)
            {
                CST.Prdn.Data.ProductionJobAttachment newAttachment = null;

                request.Status = RequestStatus.SCHEDULED;
                request.ScheduledJobID = job.ID;
                request.ScheduledDt = DateTime.Now;
                request.ScheduledUserID = GetCurrentUserID();

                var reqAtt = (from a in PrdnDBContext.RequestAttachments
                                where a.ID == job.CstRequestID && a.Attachment != null
                                select new
                                {   a.ID,
                                    a.FileName,
                                    MimeContentType = a.MimeType.ContentType,
                                    MimeSubType = a.MimeTypeCD,
                                    a.MimeType,
                                }).FirstOrDefault();

                if (reqAtt != null)
                {
                    string requestAttachmentTypeID = WebConfigurationManager.AppSettings["RequestAttachmentTypeID"];
                    decimal attTypeID = Convert.ToDecimal(requestAttachmentTypeID);

                    newAttachment = new CST.Prdn.Data.ProductionJobAttachment
                    {   //JobID = editJob.ID,
                        FileName = reqAtt.FileName,
                        MimeType = CST.ISIS.Data.Attachment.ConcatMimeType(reqAtt.MimeContentType, reqAtt.MimeSubType),
                        Description = "Original Request Attachment",
                        Attachment = null,
                        AttachmentTypeID = attTypeID
                    };
                    job.Attachments.Add(newAttachment);
                }

                PrdnDBContext.SaveChanges();

                if (newAttachment != null) {
                    PrdnDBContext.ExecuteStoreCommand(
            @"UPDATE FG_PRDN_JOB_ATTACHMENT J SET J.FG_ATTACH_DATA = (SELECT R.FG_ATTACHMENT FROM FG_REQ_PART R WHERE R.FG_REQUEST_ID = :p0) WHERE J.FG_PRDN_JOB_ATT_ID = :p1"
                    , reqAtt.ID, newAttachment.ID);
                }

            }
        }