protected void Seed(CreateOrUpdateConfigurationCommand command)
 {
     command.AllowedTypeValues = new[]
     {
         "Agreement Type #1",
         "Agreement Type #2",
         "Agreement Type #3",
     };
     command.AllowedStatusValues = new[]
     {
         "Current Status #1",
         "Current Status #2",
         "Current Status #3",
         "Current Status #4",
     };
     command.AllowedContactTypeValues = new[]
     {
         "Contact Type #1",
         "Contact Type #2",
         "Contact Type #3",
         "Contact Type #4",
     };
     _settingsHandler.Handle(command);
     _unitOfWork.SaveChanges();
 }
 protected void Seed(CreateOrUpdateConfigurationCommand command)
 {
     command.AllowedTypeValues = new[]
     {
         "Agreement Type #1",
         "Agreement Type #2",
         "Agreement Type #3",
     };
     command.AllowedStatusValues = new[]
     {
         "Current Status #1",
         "Current Status #2",
         "Current Status #3",
         "Current Status #4",
     };
     command.AllowedContactTypeValues = new[]
     {
         "Contact Type #1",
         "Contact Type #2",
         "Contact Type #3",
         "Contact Type #4",
     };
     _settingsHandler.Handle(command);
     _unitOfWork.SaveChanges();
 }
        public virtual ActionResult Edit(InstitutionalAgreementConfigurationForm model)
        {
            if (model != null)
            {
                // look for current entity
                var existingEntity = _queryProcessor.Execute(
                    new GetInstitutionalAgreementConfigurationByGuidQuery(model.EntityId)
                {
                    EagerLoad = new Expression <Func <InstitutionalAgreementConfiguration, object> >[]
                    {
                        c => c.ForEstablishment.Affiliates.Select(a => a.Person.User),
                        c => c.AllowedTypeValues,
                        c => c.AllowedStatusValues,
                        c => c.AllowedContactTypeValues,
                    },
                });

                if (existingEntity == null)
                {
                    return(HttpNotFound());
                }

                var compareConfiguration =
                    _queryProcessor.Execute(new GetMyInstitutionalAgreementConfigurationQuery(User));

                if (existingEntity.RevisionId != compareConfiguration.RevisionId || existingEntity.EntityId != compareConfiguration.EntityId)
                {
                    ModelState.AddModelError(string.Empty, string.Format(
                                                 "You are not authorized to configure the Institutional Agreements module for {0}.", existingEntity.ForEstablishment.OfficialName));
                }

                if (ModelState.IsValid)
                {
                    var command = new CreateOrUpdateConfigurationCommand(User, model.RevisionId)
                    {
                        IsCustomTypeAllowed        = model.IsCustomTypeAllowed,
                        IsCustomStatusAllowed      = model.IsCustomStatusAllowed,
                        IsCustomContactTypeAllowed = model.IsCustomTypeAllowed,
                        AllowedTypeValues          = model.AllowedTypeValues.Select(x => x.Text),
                        AllowedStatusValues        = model.AllowedStatusValues.Select(x => x.Text),
                        AllowedContactTypeValues   = model.AllowedContactTypeValues.Select(x => x.Text),
                    };
                    _commandHandler.Handle(command);
                    SetFeedbackMessage("Module configuration was saved successfully.");
                    return(RedirectToAction(MVC.InstitutionalAgreements.ConfigurationForms.Edit()));
                }

                AddEmptyAllowedOptions(model);
                return(View(model));
            }
            return(HttpNotFound());
        }
        public override void Seed()
        {
            // seed settings for a few test tenants
            PurgeCurrentSettings();
            var tenants = new Dictionary<string, string>
            {
                { "www.fue.edu.eg", "@fue.edu.eg" },
                { "www.griffith.edu.au", "@griffith.edu.au" },
                { "www.unsw.edu.au", "@unsw.edu.au" },
            };

            foreach (var tenant in tenants)
            {
                var principal = GetPrincipal(tenant.Value);
                var command = new CreateOrUpdateConfigurationCommand(principal);
                Seed(command);
            }
        }
        public override void Seed()
        {
            // seed settings for a few test tenants
            PurgeCurrentSettings();
            var tenants = new Dictionary <string, string>
            {
                { "www.fue.edu.eg", "@fue.edu.eg" },
                { "www.griffith.edu.au", "@griffith.edu.au" },
                { "www.unsw.edu.au", "@unsw.edu.au" },
            };

            foreach (var tenant in tenants)
            {
                var principal = GetPrincipal(tenant.Value);
                var command   = new CreateOrUpdateConfigurationCommand(principal);
                Seed(command);
            }
        }
        public virtual ActionResult Add(InstitutionalAgreementConfigurationForm model)
        {
            // do nothing without a viewmodel
            if (model != null)
            {
                if (ModelState.IsValid)
                {
                    // make sure configuration does not already exist
                    var configuration = _queryProcessor.Execute(new GetMyInstitutionalAgreementConfigurationQuery(User));
                    if (configuration != null)
                    {
                        SetFeedbackMessage("Your configuration has already been set up.");
                        return(RedirectToAction(MVC.InstitutionalAgreements.ConfigurationForms.Add()));
                    }

                    // configuration must have a ForEstablishmentId, and all items should be added
                    var person        = _queryProcessor.Execute(new GetMyPersonQuery(User));
                    var establishment = person.DefaultAffiliation.Establishment;
                    model.ForEstablishmentId = establishment.RevisionId;

                    var command = new CreateOrUpdateConfigurationCommand(User)
                    {
                        IsCustomTypeAllowed        = model.IsCustomTypeAllowed,
                        IsCustomStatusAllowed      = model.IsCustomStatusAllowed,
                        IsCustomContactTypeAllowed = model.IsCustomTypeAllowed,
                        AllowedTypeValues          = model.AllowedTypeValues.Select(x => x.Text),
                        AllowedStatusValues        = model.AllowedStatusValues.Select(x => x.Text),
                        AllowedContactTypeValues   = model.AllowedContactTypeValues.Select(x => x.Text),
                    };
                    _commandHandler.Handle(command);

                    SetFeedbackMessage("Module configuration was set up successfully.");
                    return(RedirectToAction(MVC.InstitutionalAgreements.ManagementForms.Browse()));
                }

                // add a default empty allowed options
                AddEmptyAllowedOptions(model);
                return(View(model));
            }
            return(HttpNotFound());
        }
        public virtual ActionResult Add(InstitutionalAgreementConfigurationForm model)
        {
            // do nothing without a viewmodel
            if (model != null)
            {
                if (ModelState.IsValid)
                {
                    // make sure configuration does not already exist
                    var configuration = _queryProcessor.Execute(new GetMyInstitutionalAgreementConfigurationQuery(User));
                    if (configuration != null)
                    {
                        SetFeedbackMessage("Your configuration has already been set up.");
                        return RedirectToAction(MVC.InstitutionalAgreements.ConfigurationForms.Add());
                    }

                    // configuration must have a ForEstablishmentId, and all items should be added
                    var person = _queryProcessor.Execute(new GetMyPersonQuery(User));
                    var establishment = person.DefaultAffiliation.Establishment;
                    model.ForEstablishmentId = establishment.RevisionId;

                    var command = new CreateOrUpdateConfigurationCommand(User)
                    {
                        IsCustomTypeAllowed = model.IsCustomTypeAllowed,
                        IsCustomStatusAllowed = model.IsCustomStatusAllowed,
                        IsCustomContactTypeAllowed = model.IsCustomTypeAllowed,
                        AllowedTypeValues = model.AllowedTypeValues.Select(x => x.Text),
                        AllowedStatusValues = model.AllowedStatusValues.Select(x => x.Text),
                        AllowedContactTypeValues = model.AllowedContactTypeValues.Select(x => x.Text),
                    };
                    _commandHandler.Handle(command);

                    SetFeedbackMessage("Module configuration was set up successfully.");
                    return RedirectToAction(MVC.InstitutionalAgreements.ManagementForms.Browse());
                }

                // add a default empty allowed options
                AddEmptyAllowedOptions(model);
                return View(model);
            }
            return HttpNotFound();
        }
        public virtual ActionResult Edit(InstitutionalAgreementConfigurationForm model)
        {
            if (model != null)
            {
                // look for current entity
                var existingEntity = _queryProcessor.Execute(
                    new GetInstitutionalAgreementConfigurationByGuidQuery(model.EntityId)
                        {
                            EagerLoad = new Expression<Func<InstitutionalAgreementConfiguration, object>>[]
                            {
                                c => c.ForEstablishment.Affiliates.Select(a => a.Person.User),
                                c => c.AllowedTypeValues,
                                c => c.AllowedStatusValues,
                                c => c.AllowedContactTypeValues,
                            },
                        });

                if (existingEntity == null)
                    return HttpNotFound();

                var compareConfiguration =
                    _queryProcessor.Execute(new GetMyInstitutionalAgreementConfigurationQuery(User));

                if (existingEntity.RevisionId != compareConfiguration.RevisionId || existingEntity.EntityId != compareConfiguration.EntityId)
                    ModelState.AddModelError(string.Empty, string.Format(
                        "You are not authorized to configure the Institutional Agreements module for {0}.", existingEntity.ForEstablishment.OfficialName));

                if (ModelState.IsValid)
                {
                    var command = new CreateOrUpdateConfigurationCommand(User, model.RevisionId)
                    {
                        IsCustomTypeAllowed = model.IsCustomTypeAllowed,
                        IsCustomStatusAllowed = model.IsCustomStatusAllowed,
                        IsCustomContactTypeAllowed = model.IsCustomTypeAllowed,
                        AllowedTypeValues = model.AllowedTypeValues.Select(x => x.Text),
                        AllowedStatusValues = model.AllowedStatusValues.Select(x => x.Text),
                        AllowedContactTypeValues = model.AllowedContactTypeValues.Select(x => x.Text),
                    };
                    _commandHandler.Handle(command);
                    SetFeedbackMessage("Module configuration was saved successfully.");
                    return RedirectToAction(MVC.InstitutionalAgreements.ConfigurationForms.Edit());
                }

                AddEmptyAllowedOptions(model);
                return View(model);
            }
            return HttpNotFound();
        }