internal async Task <JArray> AddItem(AddSO so) { SqlConnection cn = null; try { cn = Connection.GetConnection(); SqlCommand smd = new SqlCommand("sale_order_add_new_item", cn) { CommandType = CommandType.StoredProcedure }; smd.Parameters.Add("@jsonOutput", SqlDbType.NVarChar, -1).Direction = ParameterDirection.Output; smd.Parameters.AddWithValue("@item_no", so.ItemNo); // Execute the command await smd.ExecuteNonQueryAsync().ConfigureAwait(false); // Get the values string json = smd.Parameters["@jsonOutput"].Value.ToString(); smd.Dispose(); JArray arr = JArray.Parse(json); return(arr); } catch (Exception) { throw; } finally { Connection.CloseConnection(ref cn); } }
public async Task <JsonResult> AddItem([FromBody] AddSO so) { try { if (string.IsNullOrEmpty(so.ItemNo)) { return(await _saleLogic.SendRespose("False", "Blank Item No").ConfigureAwait(false)); } JArray item_info = await _saleLogic.AddItem(so).ConfigureAwait(false); JObject jo = item_info.Children <JObject>().FirstOrDefault(o => o["condition"] != null); if (jo.Value <string>("condition") == "True") { decimal gst_percentage; gst_percentage = jo.Value <decimal>("gst_percentage"); jo.Add(new JProperty("cost_per_unit", (so.CostPerUnit))); jo.Add(new JProperty("quantity", (so.Quantity))); jo.Add(new JProperty("discount_percentage", so.Discount)); jo.Add(new JProperty("amount", decimal.Round((jo.Value <decimal>("cost_per_unit") * so.Quantity), 2))); jo.Add(new JProperty("discount", decimal.Round((jo.Value <decimal>("amount") * so.Discount) / 100, 2))); jo.Add(new JProperty("total_amount", decimal.Round(jo.Value <decimal>("amount") - jo.Value <decimal>("discount"), 2))); jo.Add(new JProperty("gst_amount", decimal.Round((jo.Value <decimal>("total_amount") * gst_percentage) / 100, 2))); jo.Add(new JProperty("grand_total", decimal.Round(jo.Value <decimal>("total_amount") + jo.Value <decimal>("gst_amount"), 2))); JArray response = new JArray(jo); return(new JsonResult(response)); } else { return(new JsonResult(item_info)); } } catch (Exception ee) { return(await _saleLogic.SendRespose("False", ee.Message).ConfigureAwait(false)); } }