protected void Page_Load(object sender, EventArgs e)
        {
            if (Request.QueryString["id"] != null)
             {
            m_oIASpot = DataAccess.IASpots.SingleOrDefault(row => row.IASpotID == MemberProtect.Utility.ValidateInteger(Request.QueryString["id"]));
             }

             if (m_oIASpot == null)
             {
            Response.Redirect("~/Default.aspx");
             }

             if (!IsPostBack)
             {
            if (m_oIASpot != null)
            {
               m_oTalentFees.DataSource = m_oIASpot.IASpotFees;
               m_oTalentFees.DataBind();

               IList<IASpotFile> spotFiles =
                  m_oIASpot.IASpotFiles.Where(row => row.IASpotFileTypeID == ApplicationContext.GetSpotFileTypeID(SpotFileTypes.Production)).ToList();
               if (spotFiles.Count > 0)
               {
                  rptProductionFiles.DataSource = spotFiles;
                  rptProductionFiles.DataBind();
               }
               else
               {
                  divReferenceFiles.Visible = false;
               }
            }
             }
        }
        public IASpot DuplicateSpot(IASpot oIASpot, int iIAProductionOrderID)
        {
            // Duplicate Spot Record
             var oIASpotDuplicate = new IASpot();
             oIASpotDuplicate.IAProductionOrderID = iIAProductionOrderID;
             oIASpotDuplicate.IASpotStatusID = GetSpotStatusID(SpotStatus.OnHold);
             oIASpotDuplicate.IASpotTypeID = oIASpot.IASpotTypeID;
             oIASpotDuplicate.PurchaseOrderNumber = oIASpot.PurchaseOrderNumber;
             oIASpotDuplicate.DueDateTime = oIASpot.DueDateTime;
             oIASpotDuplicate.Length = oIASpot.Length;
             oIASpotDuplicate.LengthActual = oIASpot.LengthActual;
             oIASpotDuplicate.Title = oIASpot.Title;
             oIASpotDuplicate.ProductionNotes = oIASpot.ProductionNotes;
             oIASpotDuplicate.Script = oIASpot.Script;
             oIASpotDuplicate.IsAsap = oIASpot.IsAsap;
             oIASpotDuplicate.IsReviewed = true;

             var oIAProductionOrder = DataAccess.IAProductionOrders.SingleOrDefault(row => row.IAProductionOrderID == iIAProductionOrderID);
             if (oIAProductionOrder != null)
             {
            if (oIAProductionOrder.IAJob.IAJobStatusID == GetJobStatusID(JobStatus.ReCutRequested))
            {
               // Mark duplicates created from recut request as not having been reviewed to force SS staff to review each and every spot before
               // being able to send them off to production.
               oIASpotDuplicate.IsReviewed = false;
            }
             }

             oIASpotDuplicate.CreatedDateTime = DateTime.Now;
             oIASpotDuplicate.CompletedDateTime = DateTime.Now;
             DataAccess.IASpots.InsertOnSubmit(oIASpotDuplicate);
             DataAccess.SubmitChanges();

             // Duplicate Spot Fee Records
             foreach (var oIASpotFee in oIASpot.IASpotFees)
             {
            var oIASpotFeeDuplicate = new IASpotFee();
            oIASpotFeeDuplicate.IASpotID = oIASpotDuplicate.IASpotID;
            oIASpotFeeDuplicate.IASpotFeeTypeID = oIASpotFee.IASpotFeeTypeID;
            oIASpotFeeDuplicate.Fee = oIASpotFee.Fee;
            oIASpotFeeDuplicate.LengthActual = oIASpotFee.LengthActual;
            DataAccess.IASpotFees.InsertOnSubmit(oIASpotFeeDuplicate);
            DataAccess.SubmitChanges();
             }

             // Duplicate Spot File Records
             foreach (var oIASpotFile in oIASpot.IASpotFiles.Where(row => row.IASpotFileTypeID == GetSpotFileTypeID(SpotFileTypes.Production)))
             {
            var sExtension = string.Empty;
            var iIndex = oIASpotFile.FilenameUnique.LastIndexOf(".");
            if (iIndex > 0)
            {
               sExtension = oIASpotFile.FilenameUnique.Substring(iIndex, oIASpotFile.FilenameUnique.Length - iIndex);
            }

            var sFilename = string.Format("{0}{1}", Guid.NewGuid(), sExtension);

            try
            {
               File.Copy(string.Format("{0}{1}", UploadPath, oIASpotFile.FilenameUnique), string.Format("{0}{1}", UploadPath, sFilename));
            }
            catch (Exception)
            {
            }

            var oIASpotFileDuplicate = new IASpotFile();
            oIASpotFileDuplicate.IASpotID = oIASpotDuplicate.IASpotID;
            oIASpotFileDuplicate.IASpotFileTypeID = oIASpotFile.IASpotFileTypeID;
            oIASpotFileDuplicate.Filename = oIASpotFile.Filename;
            oIASpotFileDuplicate.FilenameUnique = sFilename;
            oIASpotFileDuplicate.FileSize = oIASpotFile.FileSize;
            oIASpotFileDuplicate.IsDeletable = true;
            oIASpotFileDuplicate.CreatedDateTime = DateTime.Now;
            DataAccess.IASpotFiles.InsertOnSubmit(oIASpotFileDuplicate);
            DataAccess.SubmitChanges();
             }

             return oIASpotDuplicate;
        }
        private bool ProcessUploadedFiles(RadUpload oUpload, IASpot oIASpot)
        {
            if (oUpload.UploadedFiles.Count > 0)
             {
            if (oIASpot.IASpotStatusID == ApplicationContext.GetSpotStatusID(SpotStatus.NeedsFix))
            {
               // Mark all older files as 'old' by appending the word to their filenames.
               foreach (var oIASpotFIle in oIASpot.IASpotFiles.Where(row => row.IASpotFileTypeID == ApplicationContext.GetSpotFileTypeID(SpotFileTypes.Talent)))
               {
                  var sNewFilename = string.Empty;
                  var sExtension = string.Empty;

                  var iIndex = oIASpotFIle.Filename.LastIndexOf(".");
                  if (iIndex > 0)
                  {
                     sExtension = oIASpotFIle.Filename.Substring(iIndex, oIASpotFIle.Filename.Length - iIndex);
                  }
                  sNewFilename = string.Format("{0}_old{1}", MemberProtect.Utility.Left(oIASpotFIle.Filename, iIndex), sExtension);
                  oIASpotFIle.Filename = sNewFilename;
                  DataAccess.SubmitChanges();
               }
            }

            foreach (UploadedFile oFile in oUpload.UploadedFiles)
            {
               // Create file record
               var oIASpotFile = new IASpotFile();
               oIASpotFile.IASpotFileTypeID = ApplicationContext.GetSpotFileTypeID(SpotFileTypes.Talent);
               oIASpotFile.Filename = oFile.GetName();
               oIASpotFile.FilenameUnique = string.Format("{0}{1}", Guid.NewGuid(), oFile.GetExtension());
               oIASpotFile.FileSize = oFile.ContentLength;
               oIASpotFile.IsDeletable = true;
               oIASpotFile.CreatedDateTime = DateTime.Now;
               oIASpot.IASpotFiles.Add(oIASpotFile);
               DataAccess.SubmitChanges();

               // Save physical file under a new name
               oFile.SaveAs(string.Format("{0}{1}", ApplicationContext.UploadPath, oIASpotFile.FilenameUnique));
            }

            return true;
             }
             else
             {
            return false;
             }
        }
 // Duplicate all records for the spot, including duplicate copies of the physical files
 public IASpot DuplicateSpot(IASpot oIASpot)
 {
     return DuplicateSpot(oIASpot, oIASpot.IAProductionOrderID);
 }