Пример #1
0
        public ActionResult OrganisationDetails([Bind(Include = "AppUserId,SelectedOrganisationId,OrganisationName,BusinessType,AddressLine1,AddressLine2,AddressLine3,AddressTownCity,AddressCounty,AddressPostcode,TelephoneNumber,Email,Website,ContactName,CompanyRegistrationDetails,CharityRegistrationDetails,VATRegistrationDetails,ListingPrivacyLevel,PrivacyLevel,GroupPrivacyLevel")] HomeOrganisationDetailsView model)
        {
            if (Request.Form["resetbutton"] != null)
            {
                return(RedirectToAction("OrganisationDetails", "Home"));
            }

            if (ModelState.IsValid)
            {
                //If the 'Submit' button pressed then update tables, else leave as are so that on reload it takes original values once again.
                if (Request.Form["submitbutton"] != null)
                {
                    if (model.SelectedOrganisationId == null)
                    {
                        //Add organisation update appUser with this organisationId
                        Organisation organisation = OrganisationHelpers.CreateOrganisation(model, User);
                        AppUserHelpers.UpdateAppUserOrganisationId(User, organisation.OrganisationId);
                        AppUserHelpers.UpdateAppUserRoleAndEntityStatus(User, UserRoleEnum.Admin, EntityStatusEnum.Active, User);
                        ApplicationUser user = UserHelpers.UpdateUserRole(User, UserRoleEnum.Admin);
                    }
                    else
                    {
                        AppUserHelpers.UpdateAppUserOrganisationId(User, model.SelectedOrganisationId.Value);
                        AppUserHelpers.UpdateAppUserRoleAndEntityStatus(User, UserRoleEnum.User, EntityStatusEnum.OnHold, User);
                    }

                    return(RedirectToAction("Index", "Home"));
                }
            }

            //DropDown - rebuild and clear selected option
            ViewBag.OrganisationList     = ControlHelpers.AllOrganisationsListDropDown();
            model.SelectedOrganisationId = null;
            return(View(model));
        }