protected void gvTariffs_RowUpdating(object sender, GridViewUpdateEventArgs e) { var code = gvTariffs.Rows[e.RowIndex].Cells[1].Controls[1] as Label; var name = gvTariffs.Rows[e.RowIndex].Cells[2].Controls[1] as Label; var unitcost = gvTariffs.Rows[e.RowIndex].Cells[3].Controls[1] as TextBox; var hasflagfall = gvTariffs.Rows[e.RowIndex].Cells[4].Controls[1] as CheckBox; var infreecall = gvTariffs.Rows[e.RowIndex].Cells[5].Controls[1] as CheckBox; var networktariffid = gvTariffs.Rows[e.RowIndex].Cells[6].Controls[1] as Label; var entity = new PlanTariff((int)gvTariffs.DataKeys[e.RowIndex].Value, int.Parse(networktariffid.Text)) { Code = code.Text, Name = name.Text, UnitCost = decimal.Parse(unitcost.Text, NumberStyles.AllowCurrencySymbol | NumberStyles.AllowThousands | NumberStyles.AllowDecimalPoint, CultureInfo.CurrentCulture), HasFlagfall = hasflagfall.Checked, IsCountedInFreeCall = infreecall.Checked }; if (PlanService.UpdatePlanTariff(entity)) { UserMessage.SetSuccess("Successfully saved Tariff"); } gvTariffs.EditIndex = -1; BindPlanTariffs(); }
public InsertPlanResponse InsertPlan(InsertPlanRequest request) { var response = new InsertPlanResponse(); System.Threading.Thread.CurrentPrincipal = request.User.GetUserPrincipal(); #region Validation if (!PermitOnlyI()) { response.Message = Constants.Messages.NO_PERMISSIONS; return response; } // Only allow inserting of plans by I personnel var validationErrors = ValidateNewPlan(request.Plan); if (validationErrors.Count > 0) { response.Message = validationErrors[0]; return response; } #endregion // Creating a new plan involves: // 1. Creating the new plan. // 2. Create a plan tariff for each network tariff that exists for the network of this plan // 3. Setting the default tariff for the plan. using (var ts = new TransactionScope()) { _planRepository.InsertPlan(request.Plan); if (request.Plan.Id == null) { response.IsSuccessful = false; return response; } var networkTariffs = _networkTariffRepository.GetNetworkTariffsByNetworkId(request.Plan.NetworkId); foreach (var netTariff in networkTariffs) { var tariff = new PlanTariff(netTariff.Id.Value) { UnitCost = 0, IsCountedInFreeCall = netTariff.IsCountedInFreeCall, PlanId = request.Plan.Id.Value }; _planTariffRepository.InsertPlanTariff(tariff); if (tariff.Id == null) { response.IsSuccessful = false; return response; } if (tariff.NetworkTariffId != request.DefaultNetworkTariffId) continue; request.Plan.DefaultTariffId = tariff.Id.Value; if (!request.Plan.IsValid) { response.Message = request.Plan.GetRuleViolations().First().ErrorMessage; return response; } if (_planRepository.UpdatePlan(request.Plan)) continue; response.IsSuccessful = false; return response; } ts.Complete(); response.IsSuccessful = true; } return response; }
public bool UpdatePlanTariff(PlanTariff entity) { return _planTariffRepository.UpdatePlanTariff(entity); }
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; }