示例#1
0
        private ViewResult DoEditValidation(TeamEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            return(null);
        }
示例#2
0
        public static TeamV SetData(this TeamV teamV, TeamEditorViewModel viewModel, IRepositoryProvider dbProvider)
        {
            teamV.HeaderKey     = viewModel.HeaderKey;
            teamV.HomeVenueGuid = viewModel.HomeVenueGuid;
            teamV.CountryGuid   = viewModel.CountryGuid;
            teamV.ResourceGuid  = viewModel.ResourceGuid;
            teamV.WebAddress    = viewModel.WebAddress;
            teamV.EffectiveFrom = viewModel.EffectiveFrom;
            teamV.EffectiveTo   = viewModel.EffectiveTo;
            teamV.DateModified  = DateTime.Now;

            teamV.SyncTeamName(dbProvider, viewModel.EditorTeamNameNative, TeamNameType.Primary, LanguageType.Native);
            teamV.SyncTeamName(dbProvider, viewModel.EditorTeamNameEnglish, TeamNameType.Primary, LanguageType.English);
            teamV.SyncTeamName(dbProvider, viewModel.EditorShortname, TeamNameType.ShortName, LanguageType.Native);
            teamV.SyncTeamName(dbProvider, viewModel.EditorNickname, TeamNameType.Nickname, LanguageType.Native);
            teamV.SyncTeamName(dbProvider, viewModel.EditorFullName, TeamNameType.FullName, LanguageType.Native);

            return(teamV);
        }
示例#3
0
        public ActionResult Create(TeamEditorViewModel viewModel)
        {
            var validate = DoEditValidation(viewModel);

            if (validate != null)
            {
                return(validate);
            }

            var teamV = viewModel.ToTeamV(UserId, UserId);

            DbProvider.Add(new Team()
            {
                PrimaryKey = viewModel.HeaderKey
            });
            DbProvider.Add(teamV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(teamV.PrimaryKey));
        }
示例#4
0
        public async Task <ActionResult> Edit(TeamEditorViewModel viewModel, HttpPostedFileBase imageData)
        {
            await SetModelsByPrimaryKey(viewModel);

            viewModel.EditableViewModels = viewModel.VersionEntity.Team.GetEditableVersions(DateTime.Now);

            var validate = DoEditValidation(viewModel);

            if (validate != null)
            {
                return(validate);
            }

            var resourceGuid = AddImageData(imageData);

            if (resourceGuid != null)
            {
                viewModel.ResourceGuid = resourceGuid;
            }

            var query = viewModel.HeaderEntity.GetApprovedVersionsByEffectiveDate <Team, TeamV>(viewModel.EffectiveFrom);

            if (query.Any())
            {
                var entityV = query.Single();

                if (viewModel.Equals(entityV))
                {
                    ModelState.AddModelError(string.Empty, "No changes have been made.");
                    return(View(viewModel));
                }

                if (entityV.ModifiedUserId == UserId)
                {
                    entityV.SetData(viewModel, DbProvider);

                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToEditor("Summary", entityV));
                }
                else
                {
                    entityV.IsActive = false;

                    var newEntityV = viewModel.ToTeamV(entityV.OwnerUserId, UserId);
                    newEntityV.EffectiveTo = viewModel.EffectiveTo;

                    DbProvider.Add(newEntityV);
                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToEditor("Summary", newEntityV));
                }
            }
            else
            {
                if (viewModel.Equals(viewModel.VersionEntity))
                {
                    ModelState.AddModelError("EffectiveFrom", "Only the effective date has changed.");
                    return(View(viewModel));
                }

                var newEntityV = viewModel.ToTeamV(UserId, UserId);
                newEntityV.EffectiveTo = Date.HighDate;

                DbProvider.Add(newEntityV);
                viewModel.HeaderEntity.NormaliseVersionEffectiveDates <TeamV>();
                DbProvider.SaveChanges();
                SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                return(RedirectToEditor("Summary", newEntityV));
            }
        }
示例#5
0
 public ActionResult Create()
 {
     return(View(TeamEditorViewModel.CreateNew <TeamEditorViewModel>()));
 }