ProductAPI
using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Web.Http;
using WMS_WebAPI.Models.Context;
namespace WMS_WebAPI.Controllers
{
[Authorize]
public class ProductController : ApiController
{
WMS_Entities _context = new WMS_Entities();
[HttpGet]
[Route("api/ProductTypes")]
public IHttpActionResult GetProductType()
{
var data = _context.ProductTypes.ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpGet]
[Route("api/ProductGroups")]
public IHttpActionResult GetProductGroups()
{
var data = _context.ProductGroups.ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpGet]
[Route("api/uomlist")]
public IHttpActionResult GetUOMs()
{
var data = _context.UOMs.ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpGet]
[Route("api/GetBillingCycles")]
public IHttpActionResult GetBillingCycles()
{
var data = _context.BillingCycle_Select().ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpGet]
[Route("api/GetPackingTypes")]
public IHttpActionResult GetPackingTypes()
{
var data = _context.PackingTypes.ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpGet]
[Route("api/TemperatureCategories")]
public IHttpActionResult GetTemperatureCategories()
{
var data = _context.TemperatureCategories_Select().ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpGet]
[Route("api/ProductList")]
public IHttpActionResult GetProductList()
{
var data = _context.Product_Select().ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
//OnItem Selection Change----------
[HttpGet]
[Route("api/itemwisetempCategory")]
public IHttpActionResult Get_TemperatureCategory(int itemid)
{
var data = _context.Get_TemperatureCategory(itemid).ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
[HttpPost]
[Route("api/SaveProduct")]
public IHttpActionResult SaveProduct(ProductMaster p)
{
var data = _context.ProductMaster_Insert_Update(p.ProductID, p.ProductCode, p.ProductName, p.ItemID, p.ProductGroupID, p.PackingTypeID, p.UOMID,
Convert.ToDecimal(p.ItemUnit), p.ItemCount, p.ProductTypeID, p.ProductTaxCategoryID, p.TemperatureCategoryID, p.WeightinKG, p.Width, p.Length, p.Height, p.CubicArea,
p.SelfLife, p.IsActive, p.CreatedBy, p.ApproxValue, p.BillingcycleID).ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
}
}
ProductTaxDetails API
using System;
using System.Data;
using System.Data.SqlClient;
using System.Linq;
using System.Web.Http;
using WMS_WebAPI.Models;
using WMS_WebAPI.Models.Context;
namespace WMS_WebAPI.Controllers
{
public class ProductTaxDetailsController : ApiController
{
WMS_Entities _context = new WMS_Entities();
CommanListToDataTableConverter ConvertDataTable = new CommanListToDataTableConverter();
string connectionstring = System.Configuration.ConfigurationManager.ConnectionStrings["ConStr"].ConnectionString;
[HttpGet]
[Route("api/ProductTaxDetails/ProductTaxDetail_Select")]
public IHttpActionResult ProductTaxDetail_Select()
{
try
{
var data = _context.ProductTaxDetail_Select().ToList();
if (data == null)
{
return NotFound();
}
return Ok(data);
}
catch (System.Exception)
{
return BadRequest();
}
}
[HttpPost]
[Route("api/ProductTaxDetails/ProductTaxDetails_insert")]
public IHttpActionResult ProductTaxDetails_insert(cls_ProductTaxDetails obj)
{
DataTable dtLTD_ProductTaxDetailProductID = new DataTable();
dtLTD_ProductTaxDetailProductID = ConvertDataTable.ConvertToDataTable(obj.LTD_ProductTaxDetailProductID);
DataTable dtLTD_ProductTaxDetailServiesIDs = new DataTable();
dtLTD_ProductTaxDetailServiesIDs = ConvertDataTable.ConvertToDataTable(obj.LTD_ProductTaxDetailServiesIDs);
DataSet ds = new DataSet();
try
{
using (SqlConnection connection = new SqlConnection(connectionstring))
{
using (SqlCommand command = new SqlCommand("ProductTaxDetails_insert", connection))
{
command.CommandType = System.Data.CommandType.StoredProcedure;
SqlParameter[] param = new SqlParameter[7];
param[0] = new SqlParameter("@ProductTaxID", Convert.ToInt32(obj.ProductTaxID));
param[1] = new SqlParameter("@TaxID", Convert.ToInt32(obj.TaxID));
param[2] = new SqlParameter("@WefDate", Convert.ToDateTime(obj.WefDate));
param[3] = new SqlParameter("@TD_ProductID", dtLTD_ProductTaxDetailProductID);
param[4] = new SqlParameter("@TD_ServiesID", dtLTD_ProductTaxDetailServiesIDs);
param[5] = new SqlParameter("@CreatedBy", Convert.ToInt32(obj.CreatedBy));
param[6] = new SqlParameter("@HSNCode", Convert.ToString(obj.HSNCode));
param[3].SqlDbType = SqlDbType.Structured;
param[4].SqlDbType = SqlDbType.Structured;
command.Parameters.AddRange(param);
connection.Open();
using (SqlDataAdapter da = new SqlDataAdapter(command))
{
da.Fill(ds);
}
connection.Close();
}
return Ok(ds);
}
}
catch (System.Exception ex)
{
return BadRequest(ex.Message);
}
}
}
}