Exemplo n.º 1
0
        /// <summary>
        /// Update client details
        /// </summary>
        /// <param name="headerInfo"> </param>
        /// <param name="eventClient"> </param>
        public static ResponseStatus ClientUpdate(HeaderInfo headerInfo, Client.Client eventClient)
        {
            var response = new ResponseStatus();

            // --------------------------------------------------------------
            // Check if user ID is already connected to a client
            // --------------------------------------------------------------
            var checkLinkedUser = new Client.Client
            {
                FKUserID = eventClient.FKUserID,
                UID      = eventClient.UID
            };

            if (!string.IsNullOrEmpty(eventClient.FKUserID))
            {
                var responseLinked = checkLinkedUser.ReadLinkedUser();

                if (responseLinked.ReturnCode == 0001 && responseLinked.ReasonCode == 0001)
                {
                    response.ReturnCode = 0001;
                    response.ReasonCode = 0002;
                    response.Message    = "User ID is already linked to another client.";
                    response.Contents   = 0;

                    return(response);
                }

                if (responseLinked.ReturnCode == 0001 && responseLinked.ReasonCode == 0003)
                {
                    // All good. User ID is connected to Client Supplied.
                }


                if (responseLinked.ReturnCode == 0001 && responseLinked.ReasonCode == 0001)
                {
                    response.ReturnCode = -0010;
                    response.ReasonCode = 0002;
                    response.Message    = "User ID is already linked to another client.";
                    response.Contents   = 0;

                    return(response);
                }
            }


            using (var connection = new SqlConnection(ConnString.ConnectionString))
            {
                using (var tr = new TransactionScope(TransactionScopeOption.Required))
                {
                    connection.Open();

                    var responseClientUpdate = eventClient.Update(headerInfo);
                    if (!responseClientUpdate.Successful)
                    {
                        // Rollback
                        tr.Dispose();
                        return(responseClientUpdate);
                    }
                    // -------------------------------------------
                    // Call method to add client extra information
                    // -------------------------------------------

                    var ceiResponse = ClientExtraInformation.Read(headerInfo, eventClient.UID);
                    if (ceiResponse.ReturnCode != 1)
                    {
                        // Rollback
                        tr.Dispose();
                        return(ceiResponse);
                    }
                    var ceiRead = (ClientExtraInformation)ceiResponse.Contents;

                    eventClient.clientExtraInformation.RecordVersion = ceiRead.RecordVersion;

                    var cei = ClientExtraInformation.Update(
                        headerInfo,
                        eventClient.clientExtraInformation);
                    if (!cei.Successful)
                    {
                        return(cei);
                    }

                    tr.Complete();
                }
            }

            return(response);
        }