public JsonResult Calculate(string sourceId, string destinyId, string planId, string time) { try { var _areaCodeValueMin = _contextAreaCodeValueMinute.ValueMin(int.Parse(sourceId), int.Parse(destinyId)); var _plan = _contextPlan.GetById(int.Parse(planId)); var _speakMore = SpeakMore.CalculateRate(_areaCodeValueMin, _plan, int.Parse(time)); var json = JsonConvert.SerializeObject(_speakMore); return(Json(json, JsonRequestBehavior.AllowGet)); } catch (Exception ex) { return(Json(new { error = true, responseText = ex.Message }, JsonRequestBehavior.AllowGet)); } }
public static SpeakMore CalculateRate(AreaCodeValueMinute areaCodeValueMinute, Plan plan, int minutesUsed) { var _speakMore = new SpeakMore(); if (minutesUsed > plan.Minute) { var _rest = minutesUsed - plan.Minute; var _pay = areaCodeValueMinute.ValueMin * _rest; _speakMore.Value = areaCodeValueMinute.ValueMin * minutesUsed; _speakMore.ValueWith = _pay * 0.1m + _pay; } else { _speakMore.Value = areaCodeValueMinute.ValueMin * minutesUsed; _speakMore.ValueWith = 0.0m; } return(_speakMore); }