Ejemplo n.º 1
0
        protected void gvTariffs_RowUpdating(object sender, GridViewUpdateEventArgs e)
        {
            var code = gvTariffs.Rows[e.RowIndex].Cells[1].Controls[1] as TextBox;
            var name = gvTariffs.Rows[e.RowIndex].Cells[2].Controls[1] as TextBox;
            var hasflagfall = gvTariffs.Rows[e.RowIndex].Cells[3].Controls[1] as CheckBox;
            var infreecall = gvTariffs.Rows[e.RowIndex].Cells[4].Controls[1] as CheckBox;

            // (Changed rag 15/02/2009) #001-10
            //Label networkid = gvTariffs.Rows[e.RowIndex].Cells[4].Controls[1] as Label;
            var networkTariffId = (int)gvTariffs.DataKeys[e.RowIndex].Value;

            var entity = new NetworkTariff(networkTariffId)
                                {
                                    Code = code.Text,
                                    Name = name.Text,
                                    IsCountedInFreeCall = infreecall.Checked,
                                    HasFlagfall = hasflagfall.Checked,
                                    NetworkId = NetworkId
                                };

            var request = new UpdateNetworkTariffRequest()
            {
                Tariff = entity,
                User = Users.Current
            };

            var response = NetworkService.UpdateNetworkTariff(request);
            if (response.IsSuccessful)
            {
                gvTariffs.EditIndex = -1;
                BindTariffs(NetworkId);
                UserMessage.SetSuccess("Tariff updated.");
            }
            else
            {
                UserMessage.SetFailure(response.Message);
            }
        }
Ejemplo n.º 2
0
        public UpdateNetworkTariffResponse UpdateNetworkTariff(UpdateNetworkTariffRequest request)
        {
            var response = new UpdateNetworkTariffResponse();

            #region Validation

            if (request.User == null || request.User is AgentUser || request.User is ContactUser)
            {
                response.IsSuccessful = false;
                response.Message = Constants.Messages.NO_PERMISSIONS;
                return response;
            }
            System.Threading.Thread.CurrentPrincipal = request.User.GetUserPrincipal();

            if (request.Tariff == null)
            {
                response.Message = "No Network Tariff has been supplied";
                return response;
            }

            if (!request.Tariff.IsValid)
            {
                response.Message = request.Tariff.GetRuleViolations().First().ErrorMessage;
                return response;
            }

            #endregion

            try
            {
                using (var ts = new TransactionScope())
                {
                    var success = _networkTariffRepository.UpdateNetworkTariff(request.Tariff);
                    if (success)
                    {
                        request.Tariff.LogActivity("Updated Tariff");
                        response.IsSuccessful = true;
                    }
                    else
                    {
                        LoggingUtility.LogDebug("UpdateNetworkTariff", "NetworkService", "Could not updat network tariff");
                        response.Message = Constants.Messages.INTERNAL_ERROR;
                    }
                    ts.Complete();
                }
            }
            catch (Exception ex)
            {
                LoggingUtility.LogException(ex);
                response.Message = Constants.Messages.INTERNAL_ERROR;
            }

            return response;
        }