Ejemplo n.º 1
0
        private static void FinaliseCurrentSaveOperation(
            IList <AssociateHistorySaveOperation> saveOperations,
            AssociateEditHistoryItem lastHistoryItem,
            AssociateHistorySaveOperation currentSaveOperation)
        {
            currentSaveOperation.LastSaveTimeStamp = lastHistoryItem.ModifiedTime;

            if (saveOperations.Count > 1)
            {
                // If the two most recent items in the list are save operations from the user
                // we are just about to add another record for then replace the middle one
                // rather than add a new one. (We only show the first and last save per
                // contiguous edit session)
                AssociateHistorySaveOperation p1 = saveOperations[saveOperations.Count - 1];
                AssociateHistorySaveOperation p2 = saveOperations[saveOperations.Count - 2];

                if (p1.ModifiedBy == currentSaveOperation.ModifiedBy &&
                    p1.ModifiedSource == currentSaveOperation.ModifiedSource && p1.ModifiedBy == p2.ModifiedBy &&
                    p1.ModifiedSource == p2.ModifiedSource)
                {
                    saveOperations[saveOperations.Count - 1] = currentSaveOperation;
                    return;
                }
            }

            saveOperations.Add(currentSaveOperation);
        }
Ejemplo n.º 2
0
        private static void FinaliseCurrentSaveOperation(
            IList<AssociateHistorySaveOperation> saveOperations, 
            AssociateEditHistoryItem lastHistoryItem, 
            AssociateHistorySaveOperation currentSaveOperation)
        {
            currentSaveOperation.LastSaveTimeStamp = lastHistoryItem.ModifiedTime;

            if (saveOperations.Count > 1)
            {
                // If the two most recent items in the list are save operations from the user
                // we are just about to add another record for then replace the middle one
                // rather than add a new one. (We only show the first and last save per
                // contiguous edit session)
                AssociateHistorySaveOperation p1 = saveOperations[saveOperations.Count - 1];
                AssociateHistorySaveOperation p2 = saveOperations[saveOperations.Count - 2];

                if (p1.ModifiedBy == currentSaveOperation.ModifiedBy
                    && p1.ModifiedSource == currentSaveOperation.ModifiedSource && p1.ModifiedBy == p2.ModifiedBy
                    && p1.ModifiedSource == p2.ModifiedSource)
                {
                    saveOperations[saveOperations.Count - 1] = currentSaveOperation;
                    return;
                }
            }

            saveOperations.Add(currentSaveOperation);
        }
Ejemplo n.º 3
0
        public IEnumerable <AssociateHistorySaveOperation> GetAssociateCollapsedEditHistory(
            int associateId, out bool associateChangeAfterAdmin)
        {
            IEnumerable <AssociateEditHistoryItem> editHistory =
                this.dataMapper.MapEditHistoryM2E(this.associateRepo.GetAssociateEditHistory(associateId));

            /* The list is ordered in ascending order of ModifiedTime. Where there are multiple consecutive edits
             * by the same user we only show the first and last save in each session. Slightly complicating matters
             * is that each "save" as perceived by the user may actually be carried out by separate SQL statements with
             * slightly different timestamps. If two consecutive saves have the same ModifiedSource, ModifiedTime and
             * are separated by <= one second we regard this as one operation.
             *
             * So timestamps of 10:00, 11:13:00,11:13:01,11:13:02, 14:00 would be treated as 3 saves (at 10:00, 11:13:00 and 14:00).
             *
             * We need to keep track internally of the fact that this save spans from 11:13:00 to 11:13:02 however.
             *
             * Because if we compare the 10:00 version with the 11:13:00 version we should include the changes up until 11:13:02 in what is displayed.
             *
             */
            AssociateEditHistoryItem lastHistoryItem = null;

            AssociateHistorySaveOperation currentSaveOperation = null;

            var saveOperations = new List <AssociateHistorySaveOperation>();

            foreach (AssociateEditHistoryItem historyItem in editHistory)
            {
                if (lastHistoryItem != null
                    &&
                    (lastHistoryItem.ModifiedBy != historyItem.ModifiedBy ||
                     lastHistoryItem.ModifiedSource != historyItem.ModifiedSource ||
                     historyItem.ModifiedTime.Subtract(lastHistoryItem.ModifiedTime).TotalMilliseconds > 1000))
                {
                    FinaliseCurrentSaveOperation(saveOperations, lastHistoryItem, currentSaveOperation);

                    currentSaveOperation = null;
                }

                if (currentSaveOperation == null)
                {
                    currentSaveOperation = new AssociateHistorySaveOperation
                    {
                        FirstSaveTimeStamp = historyItem.ModifiedTime,
                        ModifiedBy         = historyItem.ModifiedBy,
                        ModifiedSource     = historyItem.ModifiedSource
                    };
                }

                lastHistoryItem = historyItem;
            }

            if (currentSaveOperation != null)
            {
                FinaliseCurrentSaveOperation(saveOperations, lastHistoryItem, currentSaveOperation);
            }

            AssociateEditHistoryItem lastAdminEdit     = editHistory.FirstOrDefault(e => e.ModifiedSource == "Admin");
            AssociateEditHistoryItem lastAssociateEdit =
                editHistory.FirstOrDefault(e => e.ModifiedSource == "AssociatePortal");

            associateChangeAfterAdmin = lastAdminEdit != null && lastAssociateEdit != null &&
                                        lastAssociateEdit.ModifiedTime > lastAdminEdit.ModifiedTime;

            return(saveOperations);
        }
Ejemplo n.º 4
0
        public IEnumerable<AssociateHistorySaveOperation> GetAssociateCollapsedEditHistory(
            int associateId, out bool associateChangeAfterAdmin)
        {
            IEnumerable<AssociateEditHistoryItem> editHistory =
                this.dataMapper.MapEditHistoryM2E(this.associateRepo.GetAssociateEditHistory(associateId));

            /* The list is ordered in ascending order of ModifiedTime. Where there are multiple consecutive edits
               by the same user we only show the first and last save in each session. Slightly complicating matters
               is that each "save" as perceived by the user may actually be carried out by separate SQL statements with
               slightly different timestamps. If two consecutive saves have the same ModifiedSource, ModifiedTime and
               are separated by <= one second we regard this as one operation.

              So timestamps of 10:00, 11:13:00,11:13:01,11:13:02, 14:00 would be treated as 3 saves (at 10:00, 11:13:00 and 14:00).

              We need to keep track internally of the fact that this save spans from 11:13:00 to 11:13:02 however.

              Because if we compare the 10:00 version with the 11:13:00 version we should include the changes up until 11:13:02 in what is displayed.

             */
            AssociateEditHistoryItem lastHistoryItem = null;

            AssociateHistorySaveOperation currentSaveOperation = null;

            var saveOperations = new List<AssociateHistorySaveOperation>();

            foreach (AssociateEditHistoryItem historyItem in editHistory)
            {
                if (lastHistoryItem != null
                    &&
                    (lastHistoryItem.ModifiedBy != historyItem.ModifiedBy
                     || lastHistoryItem.ModifiedSource != historyItem.ModifiedSource
                     || historyItem.ModifiedTime.Subtract(lastHistoryItem.ModifiedTime).TotalMilliseconds > 1000))
                {
                    FinaliseCurrentSaveOperation(saveOperations, lastHistoryItem, currentSaveOperation);

                    currentSaveOperation = null;
                }

                if (currentSaveOperation == null)
                {
                    currentSaveOperation = new AssociateHistorySaveOperation
                                               {
                                                   FirstSaveTimeStamp = historyItem.ModifiedTime,
                                                   ModifiedBy = historyItem.ModifiedBy,
                                                   ModifiedSource = historyItem.ModifiedSource
                                               };
                }

                lastHistoryItem = historyItem;
            }

            if (currentSaveOperation != null)
            {
                FinaliseCurrentSaveOperation(saveOperations, lastHistoryItem, currentSaveOperation);
            }

            AssociateEditHistoryItem lastAdminEdit = editHistory.FirstOrDefault(e => e.ModifiedSource == "Admin");
            AssociateEditHistoryItem lastAssociateEdit =
                editHistory.FirstOrDefault(e => e.ModifiedSource == "AssociatePortal");

            associateChangeAfterAdmin = lastAdminEdit != null && lastAssociateEdit != null
                                        && lastAssociateEdit.ModifiedTime > lastAdminEdit.ModifiedTime;

            return saveOperations;
        }
Ejemplo n.º 5
0
        public ActionResult Details(
            [ModelBinder(typeof (AssociateModelBinder))] AssociateModel associate,
            AssociateHistorySaveOperation versionB,
            string deletedAccountants,
            string deletedAddresses,
            string deletedReferences,
            string notes,
            string selectedBusinessAreas)
        {
            if (!associate.HasValidActionName())
            {
                // Typing $("#mainForm")[0].submit(); into the console can do this for example.
                // in which case all validation is bypassed
                throw new ApplicationException(string.Format(@"Unexpected ActionName:""{0}"" ", associate.ActionName));
            }

            try
            {
                // Basic validation passed.
                if (!this.ModelState.IsValid)
                {
                    this.ViewBag.Feedback = "Your changes have NOT been saved.";

                    this.ModelState.AddModelError(
                        string.Empty,
                        "You have entered some invalid data, please check all highlighted fields on all tabs.");
                }
                else
                {
                    var comment = this.CreateComment(notes);

                    if (comment != null)
                    {
                        associate.Comments.Add(comment);
                    }

                    IEnumerable<int> accountantsToDelete = deletedAccountants.SplitToIntArray();
                    IEnumerable<int> addressesToDelete = deletedAddresses.SplitToIntArray();
                    IEnumerable<int> referencesToDelete = deletedReferences.SplitToIntArray();

                    IEnumerable<int> areaIds = selectedBusinessAreas.SplitToIntArray();

                    //Clear VAT if needed
                    if (associate.VATRegistered.HasValue)
                    {
                        if (!associate.VATRegistered.Value)
                        {
                            associate.VATRegistration = "";
                        }
                    }

                    // Do the Save
                    var initialOptOutSelfBillingSignedDate = associate.OptOutSelfBillingSignedDate; // this will change if associate has changed company details
                    AssociateModel originalAssociate=this.associateService.GetAssociateAndCheckLock(associate.Id);
                    var initialOptOutSelfBilling = originalAssociate.OptOutSelfBilling;
                    var updatedAssociate = this.associateService.UpdateAssociate(associate, accountantsToDelete,
                        addressesToDelete, referencesToDelete, areaIds, Site.Admin);

                    //if there is a change and the change is to opt in
                    if (associate.OptOutSelfBilling != initialOptOutSelfBilling && !associate.OptOutSelfBilling)
                    {
                        //if you opt in
                        if (!associate.OptOutSelfBilling && associate.AssociateRegistrationTypeId == (byte)AssociateRegistrationType.Contract)
                        {
                            // if you haven't signed send email regarding change
                            if (associate.OptOutSelfBillingSignedDate == initialOptOutSelfBillingSignedDate)
                            //||
                            //        associate.VATRegistered != originalAssociate.VATRegistered || associate.VATRegistration != originalAssociate.VATRegistration ||
                            //        associate.DateVatRegistered != originalAssociate.DateVatRegistered || associate.RegisteredCompanyName != originalAssociate.RegisteredCompanyName)
                            {
                                //if you have never signed
                                if (associate.OptOutSelfBillingSignedDate == null)
                                {
                                    //check if previously sent
                                    //if (!this.emailService.HasOptInEmailBeenSent(associate.Id))
                                    //{
                                    SendNewOptOutSelfBillingSignatureRequiredEmail(associate, originalAssociate);
                                    //}
                                }
                            }
                        }

                    }

                    this.associateService.CheckAssociateDefaultDocument(associate.Id);
                    //if (updatedAssociate.OptOutSelfBilling != originalAssociate.OptOutSelfBilling ||
                    //    updatedAssociate.VATRegistered!=originalAssociate.VATRegistered||
                    //    updatedAssociate.VATRegistration!=originalAssociate.VATRegistration||
                    //    updatedAssociate.DateVatRegistered!=originalAssociate.DateVatRegistered||
                    //    updatedAssociate.RegistedCompanyBankAcctName != originalAssociate.RegistedCompanyBankAcctName ||
                    //    updatedAssociate.RegistedCompanyBankAcctNumber != originalAssociate.RegistedCompanyBankAcctNumber ||
                    //    updatedAssociate.RegistedCompanyBankAcctNumber != originalAssociate.RegistedCompanyBankAcctNumber)
                    //{
                    //    this.ViewBag.originalassociate = originalAssociate;
                    //    var id = associate.Id;
                    //    var msg = this.emailService.GetAssociateEmail(id, EmailTemplate.AdminAssociateSaveDetails, originalAssociate);
                    //    msg.ToAddress = associate.Email;
                    //    msg.IsHtml = true;
                    //    this.emailService.SendEmail(msg);
                    //}

                    var warnings = this.associateService.ValidateBusinessRules(associate);

                    // Preserve the locking user since this value is not stored in the Associate entity
                    // so the update will always return null.
                    //updatedAssociate.LockingUser = associate.LockingUser;
                    associate = updatedAssociate;
                    this.associateService.UpdateReferenceAdminEventHistoryForAssociate(associate);

                    /*
                     * Clear model state for these so that when the page is re-displayed it
                     * passes new values for these. Not the values that were originally posted.
                     */
                    this.ModelState.Remove("PWRId");
                    this.ModelState.Remove("ReferencesJson");
                    this.ModelState.Remove("AddressHistoryJson");
                    this.ModelState.Remove("DateVatDeRegisteredRequired");
                    this.ModelState.Remove("HasBeenVatRegistered");

                    this.ViewBag.Feedback = "Your changes have been saved.";

                    // Do Accept if that was the requested action and the Model is fully valid
                    if (associate.ActionName == associate.ApproveAssociate)
                    {
                        this.associateService.ApproveAssociate(associate);

                        var filters = new StringBuilder();

                        filters.AppendFormat("{0}.", Convert.ToInt32(EmailTemplate.AssociateApprovedNotification));
                        filters.AppendFormat("{0}.",
                            Convert.ToInt32(EmailTemplate.AssociateRejectionInsufficientExperience));
                        filters.AppendFormat("{0}.", Convert.ToInt32(EmailTemplate.ExploringExperience));
                        filters.AppendFormat("{0}", Convert.ToInt32(EmailTemplate.AssociateRejectionVisa));

                        var routeValues =
                            new
                            {
                                associate.Id,
            //                                AutoUnlocked = true,
                                filter = filters.ToString(),
                                sendEmail = true
                            };

                        return this.RedirectToAction("Details", routeValues);
                    }

                    if (associate.ActionName == associate.AcceptAssociate)
                    {
                        if (warnings == null)
                        {
                            this.associateService.AcceptAssociate(associate);

                            // return this.RedirectToAction("Index");
                            return this.RedirectToAction("Details", new {associate.Id, AutoUnlocked = true});
                        }

                        this.ViewBag.Feedback =
                            "Your changes have been saved but it was not possible to accept the associate.";

                        foreach (string warning in warnings)
                        {
                            this.ModelState.AddModelError(string.Empty, warning);
                        }

                        this.ModelState.AddModelError(
                            string.Empty, "Incomplete applications cannot be accepted");
                    }
                    else if (associate.ActionName == associate.SaveToITRIS)
                    {
                        this.associateService.UpdateAssociateToITRIS(associate,
                            this.MembershipService.GetCurrentUserId());

                        return this.RedirectToAction("Index");
                    }
                }
            }
            catch (DataException ex)
            {
                this.ViewBag.Feedback = "Unexpected error.";

                ErrorSignal.FromCurrentContext().Raise(ex);
                this.ModelState.AddModelError(
                    string.Empty,
                    "Unable to save associate details. Please try again or contact your system administrator.");
            }

            this.SetOptionsForDetailsView(associate, true, false, versionB);

            SetUpArchiveAssociateModel();

            // update model - as VAT not being updated
            ModelState.Clear();
            return View(associate);
        }
Ejemplo n.º 6
0
        // GET: /Associate/
        // Get Associate Details
        // GET: /Associate/
        // Get Associate Details
        public ActionResult Details(
            int id,
            bool? isCompare,
            AssociateHistorySaveOperation versionA,
            AssociateHistorySaveOperation versionB,
            bool holdingBay = false)
        {
            bool comparing = isCompare.GetValueOrDefault();

            AssociateModel associate;

            if (comparing && versionA != null && versionB != null)
            {
                if (versionA.LastSaveTimeStamp > versionB.LastSaveTimeStamp)
                {
                    var tmp = versionA;
                    versionA = versionB;
                    versionB = tmp;
                }

                associate = this.associateService.GetAssociateVersion(
                    id, versionA.LastSaveTimeStamp, versionB.LastSaveTimeStamp);
            }
            else
            {
                comparing = false;

                associate = this.associateService.GetAssociateAndCheckLock(id);
            }

            this.SetOptionsForDetailsView(associate, false, comparing, versionB);

            ViewBag.ArchiveAssociate = SetUpArchiveAssociateModel();
            ViewBag.FromHoldingBay = holdingBay;

            ViewBag.VatRate = associate.VATRegistered.GetValueOrDefault()
                ? Convert.ToDecimal(ConfigurationManager.AppSettings["VatRate"])
                : 0;

            return View("Details", associate);
        }
Ejemplo n.º 7
0
        public ActionResult Compare(int id, string versionA, string versionB)
        {
            long[] splitA = versionA.SplitToLongArray();
            long[] splitB = versionB.SplitToLongArray();

            var a = new AssociateHistorySaveOperation
            {
                FirstSaveTimeStamp = new DateTime(splitA[0]),
                LastSaveTimeStamp = new DateTime(splitA[1])
            };

            var b = new AssociateHistorySaveOperation
            {
                FirstSaveTimeStamp = new DateTime(splitB[0]),
                LastSaveTimeStamp = new DateTime(splitB[1])
            };

            return this.Details(id, true, a, b);
        }
Ejemplo n.º 8
0
        private void SetOptionsForDetailsView(
            AssociateModel associate, 
            bool isPostBack, 
            bool isCompare, 
            AssociateHistorySaveOperation versionB)
        {
            bool associateChangeAfterAdmin;

            int associateId = associate.Id;
            var saveOperations =
                this.associateService.GetAssociateCollapsedEditHistory(associateId, out associateChangeAfterAdmin);

            this.ViewBag.AssociateHistorySaveOperations = saveOperations;

            this.ViewBag.EditedByAssociateAfterAdmin = associateChangeAfterAdmin;

            var mostCurrentVersion = !saveOperations.Any()
                ? true
                : (versionB.LastSaveTimeStamp == saveOperations.Last().LastSaveTimeStamp);

            var currentUserId = this.MembershipService.GetCurrentUserId();

            var lockedByCurrentUser = associate.LockingUser.HasValue && currentUserId == associate.LockingUser;

            this.ViewBag.CompareToolMessage = GetCompareToolMessage(
                lockedByCurrentUser, isPostBack, isCompare, mostCurrentVersion, associateChangeAfterAdmin);

            this.ViewBag.Readonly = !lockedByCurrentUser || (isCompare && !mostCurrentVersion);

            this.ViewBag.IsCompare = isCompare;

            if (associate.LockingUser.HasValue && currentUserId != associate.LockingUser)
            {
                this.ViewBag.LockMessage = "This record is currently locked by "
                                           + this.MembershipService.GetUserNameById(associate.LockingUser.Value);
            }

            this.ViewBag.AdminUserFoundInItris =
                !string.IsNullOrEmpty(this.associateService.GetItrisEmployeeIdFromMembershipId(currentUserId));

            if (associate.ApprovalStatus != AssociateApprovalStatus.PendingApproval)
            {
                this.ViewBag.warnings = this.associateService.ValidateBusinessRules(associate);
            }

            this.ViewBag.MomentaEmployeeList = this.employeeService.GetMomentaEmployeeList();

            this.ViewBag.AssociateOwnerList = this.employeeService.GetMomentaEmployeeListForRole(RoleName.AssociateOwner);

            this.ViewBag.VettingContactList = this.employeeService.GetMomentaEmployeeListForRole(RoleName.Vetting);

            this.ViewBag.BusinessUnits = ListItem.GetSelectListItems(
                this.associateService.GetBusinessUnitOptions(),
                arg => associate.BusinessUnitId.HasValue && (byte)associate.BusinessUnitId == arg.Value,
                true);

            this.ViewBag.ReferralSources = this.associateService.GetReferralSourceOptions();

            this.ViewBag.DocumentationWarning = this.SetContractingDocumentationStatus(associate);

            this.ViewBag.IsApprover = this.associateService.AssociateIsApprover(associateId);

            if (associate.AssociateRegistrationTypeId == (byte)AssociateRegistrationType.Agency)
            {
                // agency
                var agency = ListItem.GetSelectListItems(
                    this.associateService.GetAgencyOptions(),
                    arg => associate.AgencyId.HasValue && associate.AgencyId == arg.Value);

                this.ViewBag.Agency = agency;
            }

            this.ViewBag.Roles = this.roleService.GetRoleTypeList();

            this.SetOptionsForDetailsView(associate);
        }