WMS系统后端开发-产品档案

本文档概述了两个API控制器,ProductAPI用于处理产品类型、组别等数据,而ProductTaxDetailsAPI则关注产品税详情的查询和插入操作。通过WMS_Entities_context 和 SQL 数据库交互实现前后端数据同步。
摘要由CSDN通过智能技术生成

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);
            }

        }
       
    }
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

!chen

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值