예제 #1
0
        public static OrganisationV SetData(this OrganisationV entity, OrganisationEditorViewModel viewModel)
        {
            entity.OrganisationName        = viewModel.OrganisationName;
            entity.OrganisationDescription = viewModel.OrganisationDescription;
            entity.ParentOrganisationGuid  = viewModel.ParentOrganisationGuid;
            entity.CountryGuid             = viewModel.CountryGuid;
            entity.WebAddress = viewModel.WebAddress;

            return(entity);
        }
예제 #2
0
        private ViewResult DoEditValidation(OrganisationEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            //Can't have country and parent organisation
            if (viewModel.ParentOrganisationGuid != null && viewModel.CountryGuid != null)
            {
                ModelState.AddModelError("ParentOrganisationGuid", "Only one of country and parent organisation can be set.");
                return(View(viewModel));
            }

            return(null);
        }
예제 #3
0
        public ActionResult Create(OrganisationEditorViewModel viewModel)
        {
            if (!ModelState.IsValid)
            {
                return(View(viewModel));
            }

            var organisationV = viewModel.ToOrganisationV(UserId, UserId);

            organisationV.EffectiveTo = Date.HighDate;
            DbProvider.Add(new Organisation()
            {
                PrimaryKey = organisationV.HeaderKey
            });
            DbProvider.Add(organisationV);
            DbProvider.SaveChanges();

            return(RedirectToDetailsIndex(organisationV.HeaderKey));
        }
예제 #4
0
        public async Task <ActionResult> Edit(OrganisationEditorViewModel viewModel)
        {
            await SetModelsByPrimaryKey(viewModel);

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

            var validate = DoEditValidation(viewModel);

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

            var query = viewModel.HeaderEntity.GetApprovedVersionsByEffectiveDate <Organisation, OrganisationV>(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);
                    entityV.DateModified = DateTime.Now;

                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToAction("Summary", new { hk = entityV.HeaderKey.ToShortGuid(), pk = entityV.PrimaryKey.ToShortGuid() }));
                }
                else
                {
                    entityV.IsActive = false;

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

                    DbProvider.Add(newEntityV);

                    DbProvider.SaveChanges();
                    SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                    return(RedirectToAction("Summary", new { hk = newEntityV.HeaderKey.ToShortGuid(), pk = newEntityV.PrimaryKey.ToShortGuid() }));
                }
            }
            else
            {
                if (viewModel.Equals(viewModel.VersionEntity))
                {
                    ModelState.AddModelError("EffectiveFrom", "Only the effective date has changed.");
                    return(View(viewModel));
                }

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

                DbProvider.Add(newEntityV);
                viewModel.HeaderEntity.NormaliseVersionEffectiveDates <OrganisationV>();

                DbProvider.SaveChanges();
                SetSaveChangesMessage(SaveChangesMessageType.ChangesSaved);
                return(RedirectToAction("Summary", new { hk = newEntityV.HeaderKey.ToShortGuid(), pk = newEntityV.PrimaryKey.ToShortGuid() }));
            }
        }
예제 #5
0
 public ActionResult Create()
 {
     return(View(OrganisationEditorViewModel.CreateNew <OrganisationEditorViewModel>()));
 }