protected void _grdContactDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            ContactServiceClient contactService = null;

            try
            {
                TextBox txtElementText = (TextBox)_grdContactDetails.Rows[e.RowIndex].FindControl("_txtElementText");
                contactService = new ContactServiceClient();
                AdditionalAddressElement element = new AdditionalAddressElement();

                Guid _memberId = DataConstants.DummyGuid;
                Guid _organisationId = DataConstants.DummyGuid;

                if (Session[SessionName.MemberId] != null && Session[SessionName.OrganisationId] != null)
                {
                    _memberId = (Guid)Session[SessionName.MemberId];
                    _organisationId = (Guid)Session[SessionName.OrganisationId];
                }

                if (_logonSettings.UserType == (int)DataConstants.UserType.ThirdParty && Request.QueryString["mydetails"] == "true")
                {
                    _memberId = _logonSettings.MemberId;
                    _organisationId = _logonSettings.OrganisationId;
                }

                element.MemberId = _memberId;
                element.OrganisationId = _organisationId;
                element.TypeId = (int)_grdContactDetails.DataKeys[e.RowIndex].Values["TypeId"];
                element.ElementText = txtElementText.Text.Trim();
                element.ElementComment = ((TextBox)_grdContactDetails.Rows[e.RowIndex].FindControl("_txtElementComment")).Text.Trim();
                element.AddressId = (int)_grdContactDetails.DataKeys[e.RowIndex].Values["AddressId"];

                ReturnValue returnValue = contactService.SaveAdditionalAddressElement(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, element);
                if (returnValue.Success)
                {
                    //update the modified additional info in the session
                    AdditionalAddressElement[] additionalAddressElements = (AdditionalAddressElement[])Session[SessionName.ContactDetails];
                    for (int i = 0; i < additionalAddressElements.Length; i++)
                    {
                        if (additionalAddressElements[i].TypeId == element.TypeId)
                        {
                            additionalAddressElements[i].ElementText = element.ElementText;
                            additionalAddressElements[i].ElementComment = element.ElementComment;
                            break;
                        }
                    }

                    _messageCssClass = "successMessage";
                    _message = "Edit successful";
                }
                else
                {
                    _messageCssClass = "errorMessage";
                    _message = returnValue.Message;
                }

                _grdContactDetails.EditIndex = -1;
                DisplayContactDetails();
            }
            catch (Exception ex)
            {
                _messageCssClass = "errorMessage";
                _message = ex.Message;
            }
            finally
            {
                if (contactService != null)
                {
                    if (contactService.State != System.ServiceModel.CommunicationState.Faulted)
                        contactService.Close();
                }

                if (ErrorOccured != null)
                {
                    OnErrorOccured(System.EventArgs.Empty);
                }
            }
        }
Beispiel #2
0
        protected void _grdContactDetails_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            ContactServiceClient contactService = null;

            try
            {
                TextBox txtElementText = (TextBox)_grdContactDetails.Rows[e.RowIndex].FindControl("_txtElementText");
                contactService = new ContactServiceClient();
                AdditionalAddressElement element = new AdditionalAddressElement();

                Guid _memberId       = DataConstants.DummyGuid;
                Guid _organisationId = DataConstants.DummyGuid;

                if (Session[SessionName.MemberId] != null && Session[SessionName.OrganisationId] != null)
                {
                    _memberId       = (Guid)Session[SessionName.MemberId];
                    _organisationId = (Guid)Session[SessionName.OrganisationId];
                }

                if (_logonSettings.UserType == (int)DataConstants.UserType.ThirdParty && Request.QueryString["mydetails"] == "true")
                {
                    _memberId       = _logonSettings.MemberId;
                    _organisationId = _logonSettings.OrganisationId;
                }

                element.MemberId       = _memberId;
                element.OrganisationId = _organisationId;
                element.TypeId         = (int)_grdContactDetails.DataKeys[e.RowIndex].Values["TypeId"];
                element.ElementText    = txtElementText.Text.Trim();
                element.ElementComment = ((TextBox)_grdContactDetails.Rows[e.RowIndex].FindControl("_txtElementComment")).Text.Trim();
                element.AddressId      = (int)_grdContactDetails.DataKeys[e.RowIndex].Values["AddressId"];

                ReturnValue returnValue = contactService.SaveAdditionalAddressElement(((LogonReturnValue)Session[SessionName.LogonSettings]).LogonId, element);
                if (returnValue.Success)
                {
                    //update the modified additional info in the session
                    AdditionalAddressElement[] additionalAddressElements = (AdditionalAddressElement[])Session[SessionName.ContactDetails];
                    for (int i = 0; i < additionalAddressElements.Length; i++)
                    {
                        if (additionalAddressElements[i].TypeId == element.TypeId)
                        {
                            additionalAddressElements[i].ElementText    = element.ElementText;
                            additionalAddressElements[i].ElementComment = element.ElementComment;
                            break;
                        }
                    }

                    _messageCssClass = "successMessage";
                    _message         = "Edit successful";
                }
                else
                {
                    _messageCssClass = "errorMessage";
                    _message         = returnValue.Message;
                }

                _grdContactDetails.EditIndex = -1;
                DisplayContactDetails();
            }
            catch (Exception ex)
            {
                _messageCssClass = "errorMessage";
                _message         = ex.Message;
            }
            finally
            {
                if (contactService != null)
                {
                    if (contactService.State != System.ServiceModel.CommunicationState.Faulted)
                    {
                        contactService.Close();
                    }
                }

                if (ErrorOccured != null)
                {
                    OnErrorOccured(System.EventArgs.Empty);
                }
            }
        }