Ejemplo n.º 1
0
        protected void SaveNetwork(object sender, EventArgs e)
        {
            ResponseBase response;
            bool isNewNetwork = NetworkId == 0;
            if (!isNewNetwork)
            {
                var entity = new Network(NetworkId)
                                 {
                                     Name = Name,
                                     AcceptsNewContracts = AcceptsNewContracts,
                                     AirtimeProviderId = AirtimeProviderId
                                 };
                var updateRequest = new UpdateNetworkRequest
                {
                    Network = entity,
                    User = Users.Current
                };
                response = NetworkService.UpdateNetwork(updateRequest);
            }
            else
            {
                var entity = new Network
                                 {
                                    Name = Name,
                                    AcceptsNewContracts = AcceptsNewContracts,
                                    AirtimeProviderId = AirtimeProviderId
                                 };
                var insertRequest = new InsertNetworkRequest
                                    {
                                        Network = entity,
                                        User = Users.Current
                                    };
                response = NetworkService.InsertNetwork(insertRequest);
            }

            if (response.IsSuccessful)
            {
                if (isNewNetwork) {
                    NetworkId = ((InsertNetworkResponse)response).NetworkId;
                }

                if (EmptyTariffsHolder.Visible) {
                    InsertNetworkTariff(txtNewCode.Text, txtNewTariff.Text, chkNewFreeCall.Checked,chkNewHasFlagfall.Checked, NetworkId);
                }

                BindTariffs(NetworkId);

                UserMessage.SetSuccess("Network " + (isNewNetwork ? "Added" : "Updated"));
            }
            else
            {
                UserMessage.SetFailure(response.Message);
            }
        }
Ejemplo n.º 2
0
        public UpdateNetworkResponse UpdateNetwork(UpdateNetworkRequest request)
        {
            var response = new UpdateNetworkResponse();
            System.Threading.Thread.CurrentPrincipal = request.User.GetUserPrincipal();

            #region Validation

            if (!PermitOnlyI())
            {
                response.Message = Constants.Messages.NO_PERMISSIONS;
                return response;
            }

            var validationErrors = ValidateNetwork(request.Network);
            if (validationErrors.Count > 0)
            {
                response.Message = validationErrors[0];
                return response;
            }

            #endregion

            try
            {
                using (var ts = new TransactionScope())
                {
                    if (_networkRepository.UpdateNetwork(request.Network))
                    {
                        response.IsSuccessful = true;
                    }
                    else
                    {
                        response.Message = Constants.Messages.INTERNAL_ERROR;
                    }
                    ts.Complete();
                }
            } catch (Exception ex)
                {
                    LoggingUtility.LogException(ex);
                    response.Message = Constants.Messages.INTERNAL_ERROR;
                }

            return response;
        }