protected void gvTariffs_RowDeleting(object sender, GridViewDeleteEventArgs e) { if (this.Request["x"] != null && this.Request["y"] != null) { gvTariffs.EditIndex = -1; BindTariffs(NetworkId); } else { int networkTariffId = (int)gvTariffs.DataKeys[e.RowIndex].Value; var request = new DeleteNetworkTariffRequest() { TariffId = networkTariffId, User = Users.Current }; var response = NetworkService.DeleteNetworkTariff(request); if (response.IsSuccessful) { gvTariffs.EditIndex = -1; BindTariffs(NetworkId); UserMessage.SetSuccess("Tariff deleted."); } else { UserMessage.SetFailure(response.Message); } } }
public DeleteNetworkTariffResponse DeleteNetworkTariff(DeleteNetworkTariffRequest request) { var response = new DeleteNetworkTariffResponse(); #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(); var tariff = _networkTariffRepository[request.TariffId]; if (tariff == null) { response.Message = string.Format("Invalid Network Tariff. Id={0} does not exist.", request.TariffId); return response; } #endregion using (var ts = new TransactionScope()) { try { if (!_planTariffRepository.DeletePlanTariffsByNetworkTariff(tariff.Id.Value)) { LoggingUtility.LogDebug("DeleteNetworkTariff", "NetworkService", "Could not delete associated plan tariffs for network tariff"); response.Message = Constants.Messages.INTERNAL_ERROR; return response; } if (_networkTariffRepository.DeleteNetworkTariff(request.TariffId)) { LoggingUtility.WriteActivity(Constants.TableNames.NETWORK_TARIFF, request.TariffId, "Deleted NetworkTariff and associated Plan Tariffs"); ts.Complete(); response.IsSuccessful = true; } else { LoggingUtility.LogDebug("DeleteNetworkTariff", "NetworkService","Could not delete network tariff"); response.Message = Constants.Messages.INTERNAL_ERROR; return response; } } catch (Exception ex) { LoggingUtility.LogException(ex); response.Message = Constants.Messages.INTERNAL_ERROR; } } return response; }