public JsonResult CreatePackageCommissionsJSON(string clientName, string packageName, string packageCommissionRate) { clientName = clientName != null?clientName.Trim() : ""; packageName = packageName != null?packageName.Trim() : ""; packageCommissionRate = packageCommissionRate != null?packageCommissionRate.Trim() : ""; string errorMessage = ""; if (String.IsNullOrWhiteSpace(clientName)) { errorMessage += "Client Name not provided. "; } if (String.IsNullOrWhiteSpace(packageName)) { errorMessage += "Package Name not provided. "; } decimal decPackageCommissionRate = 0; if (!decimal.TryParse(packageCommissionRate, out decPackageCommissionRate)) { errorMessage += "Commission Rate is invalid. "; } errorMessage = errorMessage.Trim(); if (errorMessage != "") { return(new JsonResult { Data = new { success = false, message = errorMessage } }); } try { var results = Commissions.CreatePackageCommissions(clientName, packageName, decPackageCommissionRate); if (results.Count <= 0) { errorMessage += "Record already exists, or Client Name is wrong. "; } errorMessage = errorMessage.Trim(); return(new JsonResult { Data = new { success = results.Count > 0, message = errorMessage, packageCommissionID = (results.Count > 0 ? new int?(results[0].PackageCommissionID) : new int?()), clientID = (results.Count > 0 ? results[0].ClientID : ""), clientName = (results.Count > 0 ? results[0].ClientName : ""), packageCommissionRate = (results.Count > 0 ? results[0].PackageCommissionRate.ToString("f2") : "") } }); } catch (Exception ex) { errorMessage += "Record already exists, or Client Name is wrong. \n\n[" + ex.Message + "]"; errorMessage = errorMessage.Trim(); return(new JsonResult { Data = new { success = false, message = errorMessage } }); } }