public ActionResult AddUrdmsUser(TViewModelStep2 vm)
        {
            if (!string.IsNullOrWhiteSpace(vm.FindUserId))
            {
                var urdmsUser = GetUser(vm.FindUserId.Trim());
                if (urdmsUser != null)
                {
                    var dataCollection = DataCollectionRepository.Get(vm.Id);
                    vm.AddUrdmsUser(urdmsUser, DataCollectionRelationshipType.AssociatedResearcher);

                    var entityUser = dataCollection.Parties
                                     .Where(user => user.Party.UserId != null && string.Compare(user.Party.UserId.Trim(), urdmsUser.CurtinId.Trim(), true) == 0)
                                     .Take(1)
                                     .FirstOrDefault();

                    var modelUser = vm.UrdmsUsers
                                    .Where(user => string.Compare(user.UserId.Trim(), urdmsUser.CurtinId.Trim(), true) == 0)
                                    .Take(1)
                                    .FirstOrDefault();

                    if (entityUser != null && modelUser != null)
                    {
                        modelUser.Id = entityUser.Party.Id;
                    }
                }

                vm.FindUserId = null;
            }

            return(View("DataCollectionStep2", vm));
        }
Ejemplo n.º 2
0
        public ActionResult Index(int id)
        {
            var project = ProjectRepository.Get(id);

            if (project == null)
            {
                return(View("ProjectNotFound"));
            }

            ActionResult result;

            if (!VerifyCreate(project, out result))
            {
                return(result);
            }

            var collections = DataCollectionRepository.GetByProject(id);
            var vm          = new DataCollectionListViewModel
            {
                ProjectId           = id,
                ProjectTitle        = project.Title,
                DataCollectionItems = collections.Select(c =>
                                                         new DataCollectionItemViewModel
                {
                    Id = c.Id,
                    RecordCreationDate = c.RecordCreationDate.ToShortDateString(),
                    Title  = c.Title,
                    Status = c.CurrentState.State
                }
                                                         )
            };

            return(View(vm));
        }
        public virtual ActionResult Step1(TViewModelStep1 vm)
        {
            if (DataCollectionRepository.TitleExistsAlreadyForProject(vm.Id, vm.ProjectId, vm.Title))
            {
                ModelState.AddModelError("Title", "A data collection with this title exists already within this project, please choose another title");
            }

            if (!ModelState.IsValid)
            {
                return(View("DataCollectionStep1", vm));
            }

            var collection = vm.Id == 0 ? new DataCollection() : DataCollectionRepository.Get(vm.Id);

            collection.MapFrom(vm);

            if (vm.Id == 0)
            {
                collection.Parties.Add(new DataCollectionParty
                {
                    Party = new Party
                    {
                        UserId       = CurrentUser.CurtinId,
                        Email        = CurrentUser.EmailAddress,
                        FirstName    = CurrentUser.FirstName,
                        FullName     = CurrentUser.FullName,
                        LastName     = CurrentUser.LastName,
                        Organisation = ""                               // TODO: Insert your organisation here
                    },
                    DataCollection = collection,
                    Relationship   = DataCollectionRelationshipType.Manager
                });
            }
            return(OnPostToStep1(collection));
        }
Ejemplo n.º 4
0
        public ActionResult Step2(int projectId, int id)
        {
            var project = ProjectRepository.Get(projectId);

            if (project == null)
            {
                return(View("ProjectNotFound"));
            }

            var viewModel = new DataCollectionViewModelStep2();

            var collection = DataCollectionRepository.Get(id);

            if (collection == null || collection.ProjectId != projectId)
            {
                return(View("DataCollectionNotFound"));
            }
            if (collection.CurrentState.State != DataCollectionStatus.Draft)
            {
                return(RedirectToAction("ViewReadOnlyDataCollection",
                                        new { projectId = collection.ProjectId, id = collection.Id }));
            }

            viewModel.MapFrom(collection);

            return(View("DataCollectionStep2", viewModel));
        }
Ejemplo n.º 5
0
        public ActionResult Index()
        {
            if (User.IsInRole(ApplicationRole.QaApprover.GetDescription()))
            {
                var ordCollections = DataCollectionRepository.GetByStatus(new List <DataCollectionStatus> {
                    DataCollectionStatus.Submitted, DataCollectionStatus.SecondaryApproved
                });
                var ordModel = new DataCollectionApprovalListViewModel
                {
                    DataCollectionItems = MapDataCollectionItems(ordCollections)
                };
                ViewBag.EmptyListMessage = "No Data Collections requiring QA approval.";
                return(View(ordModel));
            }

            var qaCollections = DataCollectionRepository.GetByStatus(new List <DataCollectionStatus> {
                DataCollectionStatus.QaApproved, DataCollectionStatus.RecordAmended
            });
            var qaModel = new DataCollectionApprovalListViewModel
            {
                DataCollectionItems = MapDataCollectionItems(qaCollections)
            };

            ViewBag.EmptyListMessage = "No Data Collections requiring secondary approval.";
            return(View(qaModel));
        }
        public ActionResult AddNonUrdmsUser(TViewModelStep2 vm)
        {
            if (!string.IsNullOrWhiteSpace(vm.NonUrdmsNewUserName))
            {
                var dataCollection = DataCollectionRepository.Get(vm.Id);
                vm.AddNonUrdmsUser(vm.NonUrdmsNewUserName, DataCollectionRelationshipType.AssociatedResearcher);

                var entityUser = dataCollection.Parties
                                 .Where(user => string.Compare(user.Party.FullName.Trim(), vm.NonUrdmsNewUserName.Trim(), true) == 0)
                                 .Take(1)
                                 .FirstOrDefault();

                var modelUser = vm.NonUrdmsUsers
                                .Where(user => string.Compare(user.FullName.Trim(), vm.NonUrdmsNewUserName.Trim(), true) == 0)
                                .Take(1)
                                .FirstOrDefault();

                if (entityUser != null && modelUser != null)
                {
                    modelUser.Id = entityUser.Party.Id;
                }

                vm.NonUrdmsNewUserName = null;
            }

            return(View("DataCollectionStep2", vm));
        }
Ejemplo n.º 7
0
        private static IDataCollectionRepository GetDataCollectionRepository()
        {
            const string connectionString = @"Data Source=;Initial Catalog=UrdmsCI;Integrated Security=True;Pooling=False";
            var          repository       = new DataCollectionRepository(connectionString);

            return(repository);
        }
        public virtual ActionResult Step2(TViewModelStep2 vm)
        {
            if (!ModelState.IsValid)
            {
                return(View("DataCollectionStep2", vm));
            }

            var collection = DataCollectionRepository.Get(vm.Id);

            collection.MapFrom(vm, true);
            return(OnPostToStep2(collection));
        }
        public ActionResult BackToStep1(TViewModelStep2 vm)
        {
            if (!ModelState.IsValid)
            {
                return(View("DataCollectionStep2", vm));
            }

            var collection = DataCollectionRepository.Get(vm.Id);

            collection.MapFrom(vm, true);

            DataCollectionRepository.Save(collection);
            return(OnRedirectToStep1(collection));
        }
Ejemplo n.º 10
0
        public void Handle(ApprovalStateChanged message)
        {
            Log.InfoFormat("[URDMS] Received ApprovalStateChanged message id:{0} approvalState:{1}.", message.DataCollectionId, message.ApprovalState);

            try
            {
                var repository = new DataCollectionRepository();
                repository.UpdateStatus(message.DataCollectionId, message.ApprovalState, message.StateChangedOn);
            }
            catch (Exception ex)
            {
                Log.Error("[URDMS] Error hanling ApprovalStateChanged", ex);
                throw;
            }
        }
Ejemplo n.º 11
0
        public ActionResult Confirm(int id)
        {
            var dataCollection = DataCollectionRepository.Get(id);

            if (dataCollection != null)
            {
                if (VerifyUserRoleWithDataCollectionStatus(dataCollection))
                {
                    var vm = new ApprovalConfirmationViewModel {
                        DataCollectionId = id
                    };
                    PopulateModel(vm, dataCollection, HashCodeRepository.GetByDataCollectionId(dataCollection.Id));
                    return(View(vm));
                }
                return(View("DataCollectionInvalidState"));
            }
            return(View("DataCollectionNotFound"));
        }
 protected virtual ActionResult OnPostToStep1(DataCollection collection)
 {
     // enforce business rule relationships
     if (collection.Availability == DataSharingAvailability.Never)
     {
         collection.AwareOfEthics = false;
     }
     if (!collection.AwareOfEthics)
     {
         collection.EthicsApprovalNumber = null;
     }
     if (collection.Availability != DataSharingAvailability.AfterASpecifiedEmbargoPeriod)
     {
         collection.AvailabilityDate = null;
     }
     DataCollectionRepository.Save(collection);
     return(OnRedirectToStep2(collection));
 }
Ejemplo n.º 13
0
        public ActionResult Step2(int id)
        {
            var collection = DataCollectionRepository.Get(id);

            if (collection == null || !VerifyUserRoleWithDataCollectionStatus(collection))
            {
                return(View("DataCollectionNotFound"));
            }
            var project = ProjectRepository.Get(collection.ProjectId);

            if (project == null)
            {
                return(View("ProjectNotFound"));
            }
            var viewModel = new DataCollectionApprovalViewModelStep2();

            viewModel.MapFrom(collection);
            return(View("DataCollectionStep2", viewModel));
        }
Ejemplo n.º 14
0
        public ActionResult Step1(int projectId, int?id)
        {
            var project = ProjectRepository.Get(projectId);

            if (project == null)
            {
                return(View("ProjectNotFound"));
            }
            ActionResult result;

            if (!VerifyCreate(project, out result))
            {
                return(result);
            }
            var viewModel = new DataCollectionViewModelStep1();

            if (id != null)
            {
                var collection = DataCollectionRepository.Get(id.Value);

                if (collection == null)
                {
                    return(HttpNotFound());
                }
                if (collection.ProjectId != projectId)
                {
                    return(View("DataCollectionNotFound"));
                }
                if (collection.CurrentState.State != DataCollectionStatus.Draft)
                {
                    return(RedirectToAction("ViewReadOnlyDataCollection",
                                            new { projectId = collection.ProjectId, id = collection.Id }));
                }
                viewModel.MapFrom(project, collection);
            }
            else
            {
                viewModel.MapFrom(project);
            }
            return(View("DataCollectionStep1", viewModel));
        }
Ejemplo n.º 15
0
        public ActionResult ViewReadOnlyDataCollection(int projectId, int id)
        {
            var vm      = new DataCollectionReadOnlyViewModel();
            var project = ProjectRepository.Get(projectId);

            if (project == null)
            {
                return(View("ProjectNotFound"));
            }
            var dataCollection = DataCollectionRepository.Get(id);

            if (dataCollection != null)
            {
                if (dataCollection.CurrentState.State != DataCollectionStatus.Draft)
                {
                    vm.MapFrom(dataCollection, project);
                    return(View("ReadOnly", vm));
                }
                return(RedirectToAction("Step1", new { projectId = dataCollection.ProjectId, id = dataCollection.Id }));
            }
            return(View("DataCollectionNotFound"));
        }
Ejemplo n.º 16
0
        public ActionResult SubmitForReapproval(ApprovalConfirmationViewModel vm)
        {
            var collection = DataCollectionRepository.Get(vm.DataCollectionId);

            if (collection == null)
            {
                return(View("DataCollectionNotFound"));
            }
            if (!VerifyUserRoleWithDataCollectionStatus(collection))
            {
                return(View("DataCollectionInvalidState"));
            }

            var hashCode = HashCodeRepository.GetByDataCollectionId(collection.Id);

            PopulateModel(vm, collection, hashCode);

            if (vm.IsChanged)
            {
                // TODO: You can use the URDMS.Integration solution to handle approvals in a robust manner or just alter the database directly as in the
                // commented code below.
                Bus.Send <SubmitForSecondaryReApproval>(m =>
                {
                    m.DataCollectionId = collection.Id;
                    m.ApprovedBy       = CurrentUser.CurtinId;
                    m.ApprovedOn       = DateTime.Now;
                });

                //collection.CurrentState = new DataCollectionState(DataCollectionStatus.RecordAmended, DateTime.Now);
                //DataCollectionRepository.Save(collection);

                // clear out hashcode at this point.
                this.HashCodeRepository.Delete(hashCode);
            }

            return(RedirectToAction("Index"));
        }
Ejemplo n.º 17
0
 public override void Setup()
 {
     base.Setup();
     _repository = new DataCollectionRepository(CreateSession());
 }
Ejemplo n.º 18
0
        public ActionResult Confirm(ApprovalConfirmationViewModel vm)
        {
            var collection = DataCollectionRepository.Get(vm.DataCollectionId);

            if (collection == null)
            {
                return(View("DataCollectionNotFound"));
            }

            if (!VerifyUserRoleWithDataCollectionStatus(collection))
            {
                return(View("DataCollectionInvalidState"));
            }

            var hashCode = HashCodeRepository.GetByDataCollectionId(collection.Id);

            PopulateModel(vm, collection, hashCode);

            switch (vm.State)
            {
            case DataCollectionStatus.Submitted:
                if (!vm.IsQaApproved)
                {
                    ModelState.AddModelError("IsQaApproved", "Please confirm approval");
                    return(View(vm));
                }

                // TODO: You can use the URDMS.Integration solution to handle approvals in a robust manner or just alter the database directly as in the
                // commented code below.
                Bus.Send <SubmitForSecondaryApproval>(m =>
                {
                    m.DataCollectionId = collection.Id;
                    m.ApprovedBy       = CurrentUser.CurtinId;
                    m.ApprovedOn       = DateTime.Now;
                });

                //collection.CurrentState = new DataCollectionState(DataCollectionStatus.QaApproved, DateTime.Now);
                //DataCollectionRepository.Save(collection);

                vm.ProposedState = DataCollectionStatus.QaApproved;
                return(View("Approved", vm));

            case DataCollectionStatus.QaApproved:
            case DataCollectionStatus.RecordAmended:
                if (!vm.DoesNotViolateAgreements || !vm.DoesNotViolateConfidentialityAndEthics)
                {
                    if (!vm.DoesNotViolateAgreements)
                    {
                        ModelState.AddModelError("DoesNotViolateAgreements", "Please confirm that agreements are not violated");
                    }
                    if (!vm.DoesNotViolateConfidentialityAndEthics)
                    {
                        ModelState.AddModelError("DoesNotViolateConfidentialityAndEthics", "Please confirm that confidentiality and ethics requirements are met");
                    }
                    return(View(vm));
                }
                // TODO: You can use the URDMS.Integration solution to handle approvals in a robust manner or just alter the database directly as in the
                // commented code below.
                Bus.Send <SubmitForFinalApproval>(m =>
                {
                    m.DataCollectionId = collection.Id;
                    m.ApprovedBy       = CurrentUser.CurtinId;
                    m.ApprovedOn       = DateTime.Now;
                });

                //collection.CurrentState = new DataCollectionState(DataCollectionStatus.SecondaryApproved, DateTime.Now);
                //DataCollectionRepository.Save(collection);

                vm.ProposedState = DataCollectionStatus.SecondaryApproved;
                // save hashcode to capture the snapshot of the data
                this.HashCodeRepository.SaveByDataCollection(collection);
                return(View("Approved", vm));

            case DataCollectionStatus.SecondaryApproved:
            {
                if (!vm.IsPublicationApproved)
                {
                    ModelState.AddModelError("IsPublicationApproved", "Please confirm publication approval");
                    return(View(vm));
                }
                // TODO: You can use the URDMS.Integration solution to handle approvals in a robust manner or just alter the database directly as in the
                // commented code below.
                Bus.Send <PublishDataCollection>(m =>
                    {
                        m.DataCollectionId = collection.Id;
                        m.ApprovedBy       = CurrentUser.CurtinId;
                        m.ApprovedOn       = DateTime.Now;
                    });

                //collection.CurrentState = new DataCollectionState(DataCollectionStatus.Publishing, DateTime.Now);
                //DataCollectionRepository.Save(collection);

                vm.ProposedState = DataCollectionStatus.Publishing;
            }

                return(View("Approved", vm));

            default:
                throw new InvalidOperationException();
            }
        }
 protected virtual ActionResult OnPostToStep2(DataCollection collection)
 {
     DataCollectionRepository.Save(collection);
     return(OnSaveToStep2(collection));
 }
Ejemplo n.º 20
0
        public ActionResult Index(DataCollectionListViewModel vm)
        {
            if (!ModelState.IsValid)
            {
                return(View(vm));
            }

            var project = ProjectRepository.Get(vm.ProjectId);

            if (project == null)
            {
                return(View("ProjectNotFound"));
            }
            ActionResult result;

            if (!VerifyCreate(project, out result))
            {
                return(result);
            }
            // Start provisioning workflow
            var dataCollectionsForApproval    = vm.DataCollectionItems.Where(dc => dc.IsUserSubmitted).ToList();
            var dataCollectionsForApprovalIds = dataCollectionsForApproval.Select(dc => dc.Id).ToList();

            dataCollectionsForApprovalIds.ForEach(id =>
            {
                var dataCollection = DataCollectionRepository.Get(id);
                if (dataCollection != null)
                {
                    var manager = dataCollection.Parties
                                  .Where(p => p.Relationship == DataCollectionRelationshipType.Manager)
                                  .Take(1)
                                  .FirstOrDefault();

                    Debug.Assert(manager != null);

                    // TODO: Implement integration with approvals service/application or alter database directly as below
                    Bus.Send <SubmitForApproval>(m =>
                    {
                        m.ApprovedBy       = manager.Party.UserId.ToString();
                        m.ApprovedOn       = DateTime.Now;
                        m.DataCollectionId = dataCollection.Id;
                    });
                    //dataCollection.CurrentState = new DataCollectionState(DataCollectionStatus.Submitted, DateTime.Now);
                    //DataCollectionRepository.Save(dataCollection);
                }
            });

            var submittedDataCollectionsModels = dataCollectionsForApproval.Select(
                dc => new DataCollectionsForApprovalItemViewModel {
                Id = dc.Id, SubmisionDate = DateTime.Now.ToShortDateString(), Title = dc.Title
            }).ToList();

            if (submittedDataCollectionsModels.Count > 0)
            {
                return(View("Submitted",
                            new SubmittedDataCollectionsViewModel
                {
                    ProjectId = vm.ProjectId,
                    PublishedDataCollectionItems = submittedDataCollectionsModels
                }));
            }
            return(View(vm));
        }