/// <summary> /// Save and update information of the organization /// </summary> /// <returns>status of save</returns> public bool SaveData() { try { NexsoProDAL.MIFNEXSOEntities mifnexsoEntities = new MIFNEXSOEntities(); mifnexsoEntities.Connection.Open(); var trans = mifnexsoEntities.Connection.BeginTransaction(); try { if (organizationComponent.Organization.OrganizationID == Guid.Empty) { organizationComponent.Organization.Created = DateTime.Now; organizationComponent.Organization.Updated = organizationComponent.Organization.Created.GetValueOrDefault(DateTime.Now); } else { organizationComponent.Organization.Updated = DateTime.Now; } organizationComponent.Organization.Name = ValidateSecurity.ValidateString(txtInstitutionName.Text, false); organizationComponent.Organization.Description = ValidateSecurity.ValidateString(txtDescription.Text, false); organizationComponent.Organization.ZipCode = CountryStateCityEditMode.SelectedPostalCode; organizationComponent.Organization.Phone = ValidateSecurity.ValidateString(txtPhone.Text, false); organizationComponent.Organization.Skype = ValidateSecurity.ValidateString(txtSkype.Text, false); organizationComponent.Organization.Twitter = ValidateSecurity.ValidateString(txtTwitter.Text, false); organizationComponent.Organization.Facebook = ValidateSecurity.ValidateString(txtFacebook.Text, false); organizationComponent.Organization.GooglePlus = ValidateSecurity.ValidateString(txtGoogle.Text, false); organizationComponent.Organization.LinkedIn = ValidateSecurity.ValidateString(txtLinkedIn.Text, false); organizationComponent.Organization.Address = ValidateSecurity.ValidateString(CountryStateCityEditMode.SelectedAddress, false); organizationComponent.Organization.Country = CountryStateCityEditMode.SelectedCountry; organizationComponent.Organization.Region = CountryStateCityEditMode.SelectedState; organizationComponent.Organization.City = CountryStateCityEditMode.SelectedCity; organizationComponent.Organization.Latitude = CountryStateCityEditMode.SelectedLatitude; organizationComponent.Organization.Longitude = CountryStateCityEditMode.SelectedLongitude; CountryStateCityViewMode.SelectedAddress = ValidateSecurity.ValidateString(CountryStateCityEditMode.SelectedAddress, false); CountryStateCityViewMode.SelectedCountry = CountryStateCityEditMode.SelectedCountry; CountryStateCityViewMode.SelectedState = CountryStateCityEditMode.SelectedState; CountryStateCityViewMode.SelectedCity = CountryStateCityEditMode.SelectedCity; CountryStateCityViewMode.SelectedLatitude = CountryStateCityEditMode.SelectedLatitude; CountryStateCityViewMode.SelectedLongitude = CountryStateCityEditMode.SelectedLongitude; CountryStateCityViewMode.SelectedPostalCode = CountryStateCityEditMode.SelectedPostalCode; CountryStateCityViewMode.UpdateMap(); organizationComponent.Organization.Email = txtEmail.Text; string newImg = Path.GetFileName(imgInstitution.ImageUrl); if (organizationComponent.Organization.Logo != newImg && newImg.ToUpper() != "NOIMAGE.PNG") { File.Move(Server.MapPath(PortalSettings.HomeDirectory + "ModIma/TempImages/" + newImg), Server.MapPath(PortalSettings.HomeDirectory + "ModIma/Images/" + newImg)); imgInstitution.ImageUrl = PortalSettings.HomeDirectory + "ModIma/Images/" + newImg; organizationComponent.Organization.Logo = newImg; } if (organizationComponent.Save() > 0) { if (organizationId == Guid.Empty) { UserInfo userInfo = UserController.Instance.GetCurrentUserInfo(); organizationId = organizationComponent.Organization.OrganizationID; UserOrganizationComponent userOrganizationComponent = new UserOrganizationComponent( userInfo.UserID, organizationId, 1); userOrganizationComponent.ChangeContext(ref mifnexsoEntities); if (userOrganizationComponent.Save() < 0) { throw new Exception(); } } } else { throw new Exception(); } mifnexsoEntities.AcceptAllChanges(); trans.Commit(); mifnexsoEntities.Dispose(); organizationId = organizationComponent.Organization.OrganizationID; return(true); } catch (Exception exc) { trans.Rollback(); mifnexsoEntities.Dispose(); Exceptions. ProcessModuleLoadException( this, exc); return(false); } } catch (Exception exc) { Exceptions. ProcessModuleLoadException( this, exc); return(false); } }
/// <summary> /// Enable buttons and inputs to load information from the organization /// </summary> /// <param name="enabled"></param> private void EnableEditControls(bool enabled) { // if querystring [in] (organizationId) exist if (EnabledButtons) { // if organizationId is diferent of Guid.Empty if (enabled) { if (organizationId != Guid.Empty) { //get text for buttons and visibility options btnEditProfile.CommandArgument = ""; btnEditProfile2.CommandArgument = ""; btnCancel.Visible = true; btnEditProfile.Text = Localization.GetString("SaveProfile", LocalResourceFile); btnEditProfile2.Text = Localization.GetString("SaveProfile", LocalResourceFile); } else { //get text for buttons and visibility options btnEditProfile.CommandArgument = ""; btnEditProfile2.CommandArgument = ""; btnCancel.Visible = false; btnEditProfile.Text = Localization.GetString("CreateNew", LocalResourceFile); btnEditProfile2.Text = Localization.GetString("CreateNew", LocalResourceFile); } } else { //Get relacion from user and organization UserOrganizationComponent com = new UserOrganizationComponent(UserId, organizationId); if ((com.UserOrganization.Role == 1 && EnabledButtons) || UserController.GetCurrentUserInfo().IsInRole("Administrator")) { //get text for buttons and visibility options btnEditProfile.CommandArgument = "EDIT"; btnEditProfile.Text = Localization.GetString("EditProfile", LocalResourceFile); btnEditProfile.Visible = true; btnEditProfile2.CommandArgument = "EDIT"; btnEditProfile2.Text = Localization.GetString("EditProfile", LocalResourceFile); btnEditProfile2.Visible = true; btnCancel.Visible = false; } else { //visibility options btnEditProfile.Visible = false; btnEditProfile2.Visible = false; btnCancel.Visible = false; } } } else { //visibility options btnEditProfile.Visible = false; btnCancel.Visible = false; } ViewPanel.Visible = !enabled; EditPanel.Visible = enabled; }