Exemple #1
0
        void SharedRepositoryModelDisplay(RepositoryViewModel model)
        {
            var repo    = model.Repository;
            var appUser = User.GetAppUser();

            model.SettingsJson = repo.Settings;
            if (!string.IsNullOrEmpty(model.SettingsJson))
            {
                try
                {
                    model.SettingsJson = JsonSerializationUtils.FormatJsonString(repo.Settings);
                }
                catch { }
            }

            model.TableOfContentsJson = repo.TableOfContents;
            if (!string.IsNullOrEmpty(model.TableOfContentsJson))
            {
                try
                {
                    model.TableOfContentsJson = JsonSerializationUtils.FormatJsonString(repo.TableOfContents);
                }
                catch { }
            }

            if (!appUser.IsEmpty())
            {
                model.IsOwner = _repoBusiness.IsOwner(repo, appUser.UserId);
            }
        }
Exemple #2
0
        public async Task <ActionResult> SaveRepository(RepositoryViewModel model, Guid id)
        {
            InitializeViewModel(model);

            if (id != Guid.Empty)
            {
                model.Repository.Id = id;
            }

            var repo = _repoBusiness.GetRepository(model.Repository.Id);

            if (repo == null)
            {
                repo            = _repoBusiness.CreateRepository(User.GetAppUser().UserId);
                model.IsNewUser = true;
            }

            DataUtils.CopyObjectData(model.Repository, repo, "Id,Users,Organization");

            repo.Settings        = model.SettingsJson;
            repo.TableOfContents = model.TableOfContentsJson;

            bool validationResult = _repoBusiness.Validate(repo);

            if (!validationResult)
            {
                model.ErrorDisplay.AddMessages(_repoBusiness.ValidationErrors);
                model.ErrorDisplay.ShowError("Please fix the following");
            }
            else
            {
                _repoBusiness.AutoValidate = false;
                if (!_repoBusiness.Save())
                {
                    model.ErrorDisplay.ShowError(_repoBusiness.ErrorMessage, "Couldn't save Repository.");
                }
                else
                {
                    model.ErrorDisplay.ShowSuccess("Repository info saved.");
                }
            }


            if (model.IsNewUser)
            {
                model.IsNewUser = false;
                // do a full reload to ensure all dependencies get loaded
                repo = _repoBusiness.GetRepository(repo.Id);
                model.RepositoryWithUsers = await _repoBusiness.GetRepositoryWithUsersAndRoles(repo.Id);

                model.RepositoryWithUsers.Repository = repo;
            }
            else
            {
                model.Repository          = repo;
                model.RepositoryWithUsers = await _repoBusiness.GetRepositoryWithUsersAndRoles(repo.Id);
            }
            model.RepositoryWithUsers = await _repoBusiness.GetRepositoryWithUsersAndRoles(repo.Id);


            model.Repository = repo;


            SharedRepositoryModelDisplay(model);

            return(View("Repository", model));
        }