public HttpResponseMessage ArchivePRCMR([FromBody] Claim_Update_Cmr updateCmr, int updateID, string token)
        {
            Session          session = _ctx.Sessions.SingleOrDefault(i => i.SessionToken == token);
            Claim_Update_Cmr oldCMR  = _ctx.Claim_Update_Cmrs.SingleOrDefault(i => i.UpdateID == updateID);

            Claim_Update_Cmr_Archive archive = new Claim_Update_Cmr_Archive()
            {
                UserID                      = oldCMR.UserID,
                UpdateID                    = oldCMR.UpdateID,
                AbsenceAuthorization        = oldCMR.AbsenceAuthorization,
                ArchiveDate                 = DateTime.Now,
                ArchivedBy                  = Convert.ToInt32(session.UserID),
                ClaimHistoryInformation     = oldCMR.ClaimHistoryInformation,
                ClaimStatusID               = oldCMR.ClaimStatusID,
                DateOfAbsence               = oldCMR.DateOfAbsence,
                DateOfReferal               = oldCMR.DateOfReferal,
                DateOfReport                = oldCMR.DateOfReport,
                EmployeeID                  = oldCMR.EmployeeID,
                EmployeeName                = oldCMR.EmployeeName,
                EmployerContactID           = oldCMR.EmployerContactID,
                Location                    = oldCMR.Location,
                NextSteps                   = oldCMR.NextSteps,
                OSIContactID                = oldCMR.OSIContactID,
                ReturntoWorkRecommendations = oldCMR.ReturntoWorkRecommendations,
                TreatmentPlan               = oldCMR.TreatmentPlan
            };

            _ctx.Claim_Update_Cmr_Archives.InsertOnSubmit(archive);
            _ctx.SubmitChanges();

            oldCMR.UserID                      = updateCmr.UserID;
            oldCMR.UpdateID                    = updateCmr.UpdateID;
            oldCMR.AbsenceAuthorization        = updateCmr.AbsenceAuthorization;
            oldCMR.ClaimHistoryInformation     = updateCmr.ClaimHistoryInformation;
            oldCMR.ClaimStatusID               = updateCmr.ClaimStatusID;
            oldCMR.DateOfAbsence               = updateCmr.DateOfAbsence;
            oldCMR.DateOfReferal               = updateCmr.DateOfReferal;
            oldCMR.DateOfReport                = updateCmr.DateOfReport;
            oldCMR.EmployeeID                  = updateCmr.EmployeeID;
            oldCMR.EmployeeName                = updateCmr.EmployeeName;
            oldCMR.EmployerContactID           = updateCmr.EmployerContactID;
            oldCMR.Location                    = updateCmr.Location;
            oldCMR.NextSteps                   = updateCmr.NextSteps;
            oldCMR.OSIContactID                = updateCmr.OSIContactID;
            oldCMR.ReturntoWorkRecommendations = updateCmr.ReturntoWorkRecommendations;
            oldCMR.TreatmentPlan               = updateCmr.TreatmentPlan;
            oldCMR.EmployeeContactID           = updateCmr.EmployeeContactID;

            _ctx.SubmitChanges();

            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent("Updated")
            });
        }
        public HttpResponseMessage ArchiveUpdate(string token, int updateID)
        {
            Claim_Update claimUpdate = context.Claim_Updates.Single(i => i.UpdateID == updateID);
            Session      session     = context.Sessions.FirstOrDefault(i => i.SessionToken == token);

            if (claimUpdate.DateTimeSubmitted_ < DateTime.UtcNow.AddHours(-2))
            {
                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Content = new StringContent("Claim update exceeded 2 hours old, cannot be archived.")
                });
            }

            if (claimUpdate.UserID != Convert.ToInt32(session.UserID))
            {
                return(new HttpResponseMessage()
                {
                    StatusCode = HttpStatusCode.BadRequest,
                    Content = new StringContent("You did not create this claim update. you cannot delete it")
                });
            }
            Claim_Updates_Billing            updatesBilling   = context.Claim_Updates_Billings.Single(i => i.UpdateID == updateID);
            Claim_Update_Cmr                 oldCMR           = context.Claim_Update_Cmrs.SingleOrDefault(i => i.UpdateID == updateID);
            List <Claim_Updates_Document>    updatesDocuments = context.Claim_Updates_Documents.Where(i => i.UpdateID == updateID).ToList();
            Claim_Peer_Review                peerReview       = context.Claim_Peer_Reviews.SingleOrDefault(i => i.Update_ID == updateID);
            Claim_Updates_Billing_PR_Archive archive          = new Claim_Updates_Billing_PR_Archive()
            {
                UserID           = claimUpdate.UserID,
                ClaimRefNu       = claimUpdate.ClaimRefNu,
                ActionType       = claimUpdate.ActionType,
                Archived_By      = Convert.ToInt32(session.UserID),
                BillID           = updatesBilling.BillID,
                Billable         = claimUpdate.Billable,
                Comments         = updatesBilling.Comments,
                Completed        = updatesBilling.Completed,
                CompletionDate   = updatesBilling.CompletionDate,
                Courier          = updatesBilling.Courier,
                Date_Archived    = DateTime.Now,
                DirectContact    = updatesBilling.DirectContact,
                Duration         = updatesBilling.Duration,
                EmployeeComments = claimUpdate.EmployeeComments,
                InternalComments = claimUpdate.InternalComments,
                IsArchived       = claimUpdate.IsArchived,
                IsInReview       = false,
                Method           = updatesBilling.Method,
                Postage          = updatesBilling.Postage,
                Reason           = updatesBilling.Reason,
                ReportedComments = claimUpdate.ReportedComments,
                UpdateBy         = Convert.ToInt32(session.UserID),
                UpdateId         = claimUpdate.UpdateID,
                UpdatesDate      = claimUpdate.UpdatesDate,
                SeniorConsulting = updatesBilling.SeniorConsulting
            };

            if (oldCMR != null)
            {
                Claim_Update_Cmr_Archive cmrarchive = new Claim_Update_Cmr_Archive()
                {
                    UserID                      = oldCMR.UserID,
                    UpdateID                    = oldCMR.UpdateID,
                    AbsenceAuthorization        = oldCMR.AbsenceAuthorization,
                    ArchiveDate                 = DateTime.Now,
                    ArchivedBy                  = Convert.ToInt32(session.UserID),
                    ClaimHistoryInformation     = oldCMR.ClaimHistoryInformation,
                    ClaimStatusID               = oldCMR.ClaimStatusID,
                    DateOfAbsence               = oldCMR.DateOfAbsence,
                    DateOfReferal               = oldCMR.DateOfReferal,
                    DateOfReport                = oldCMR.DateOfReport,
                    EmployeeID                  = oldCMR.EmployeeID,
                    EmployeeName                = oldCMR.EmployeeName,
                    EmployerContactID           = oldCMR.EmployerContactID,
                    Location                    = oldCMR.Location,
                    NextSteps                   = oldCMR.NextSteps,
                    OSIContactID                = oldCMR.OSIContactID,
                    ReturntoWorkRecommendations = oldCMR.ReturntoWorkRecommendations,
                    TreatmentPlan               = oldCMR.TreatmentPlan
                };
                context.Claim_Update_Cmr_Archives.InsertOnSubmit(cmrarchive);
            }
            foreach (Claim_Updates_Document doc in updatesDocuments)
            {
                Claim_Updates_Documents_Archive docarchive = new Claim_Updates_Documents_Archive()
                {
                    UserID         = doc.UserID,
                    UpdateID       = doc.UpdateID,
                    ArchivedBy     = Convert.ToInt32(session.UserID),
                    ClaimReference = doc.ClaimReference,
                    DateArchived   = DateTime.Now,
                    DocumentID     = doc.DocumentID,
                    FileExt        = doc.FileExt,
                    FileName       = doc.FileName,
                    Timestamp      = doc.Timestamp,
                    VersionNumber  = doc.VersionNumber
                };
                context.Claim_Updates_Documents_Archives.InsertOnSubmit(docarchive);
            }
            if (peerReview != null)
            {
                context.Claim_Peer_Reviews.DeleteOnSubmit(peerReview);
            }
            context.Claim_Updates_Billing_PR_Archives.InsertOnSubmit(archive);
            context.SubmitChanges();
            context.Claim_Updates.DeleteOnSubmit(claimUpdate);
            context.Claim_Updates_Billings.DeleteOnSubmit(updatesBilling);
            if (oldCMR != null)
            {
                context.Claim_Update_Cmrs.DeleteOnSubmit(oldCMR);
            }
            foreach (Claim_Updates_Document doc in updatesDocuments)
            {
                context.Claim_Updates_Documents.DeleteOnSubmit(doc);
            }
            context.SubmitChanges();

            return(new HttpResponseMessage()
            {
                StatusCode = HttpStatusCode.OK,
                Content = new StringContent("Claim update and child records successfuly archived")
            });
        }