private void InsertNetworkTariff(string code, string tariff, bool freeCall, bool hasFlagfall, int networkId) { var newTariff = new NetworkTariff { Code = code, Name = tariff, IsCountedInFreeCall = freeCall, HasFlagfall = hasFlagfall, NetworkId = networkId }; var request = new InsertNetworkTariffRequest { Tariff = newTariff, User = Users.Current }; var response = NetworkService.InsertNetworkTariff(request); if (!response.IsSuccessful) { UserMessage.SetFailure(response.Message); } else { UserMessage.SetSuccess("Tariff added."); } BindTariffs(networkId); }
public InsertNetworkTariffResponse InsertNetworkTariff(InsertNetworkTariffRequest request) { var response = new InsertNetworkTariffResponse(); #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 (string.IsNullOrEmpty(request.Tariff.Code)) { response.Message = "A Tariff Code must be supplied"; return response; } if (string.IsNullOrEmpty(request.Tariff.Name)) { response.Message = " A Tariff Name must be supplied"; return response; } #endregion using (var ts = new TransactionScope()) { try { _networkTariffRepository.InsertNetworkTariff(request.Tariff); if (request.Tariff.Id == null) { response.Message = Constants.Messages.INTERNAL_ERROR; return response; } LoggingUtility.WriteActivity(Constants.TableNames.NETWORK_TARIFF, request.Tariff.Id.Value, "Insert Network Tariff"); // Insert a Plan Tariff for every plan on this network var plans = _planRepository.GetPlansByNetworkId(request.Tariff.NetworkId); foreach (var plan in plans) { var tariff = new PlanTariff(request.Tariff.Id.Value) { IsCountedInFreeCall = request.Tariff.IsCountedInFreeCall, PlanId = plan.Id.Value, UnitCost = 0M }; _planTariffRepository.InsertPlanTariff(tariff); if (tariff.Id != null) continue; LoggingUtility.LogDebug("InsertNetworkTariff", "NetworkService", "Count not insert Plan Tariff"); response.Message = Constants.Messages.INTERNAL_ERROR; return response; } ts.Complete(); response.IsSuccessful = true; } catch (Exception ex) { LoggingUtility.LogException(ex); response.Message = Constants.Messages.INTERNAL_ERROR; } } return response; }