Example #1
0
        public async Task <object> NonMandatoryInsertPOS_MasterInfo([FromQuery] string TM_YEAR, string TM_SEASON, string STC_Core, string POS_Status)
        {
            ResultModel result = new ResultModel();

            result.IsSuccess = false;
            try
            {
                if (string.IsNullOrEmpty(STC_Core))
                {
                    result.Message = "Ship to Code Core is Null Or Empty! ";
                    return(Ok(result));
                }
                POS_Master entity = new POS_Master();//一些默认值
                entity.POS_CHANNEL   = "Core";
                entity.TM_SEASON     = TM_SEASON;
                entity.TM_YEAR       = TM_YEAR;
                entity.STC_CORE      = STC_Core;
                entity.STA_BULK_CORE = "";
                entity.POS_Status    = POS_Status;
                entity.PackagePOS    = "N";
                string userid = HttpContext.User.Claims.Where(item => item.Type == System.Security.Claims.ClaimTypes.NameIdentifier).FirstOrDefault().Value;
                Users  _users = await userRepository.GetUserAndRoles(int.Parse(userid));

                entity.Modified_User = _users.name;
                entity.Created_Date  = DateTime.Now;

                //获取customerInfo
                CustomersInfo customersInfo = await CustomerRepository.GetSingleEntityByShipTo_Code(STC_Core);

                if (customersInfo == null)
                {
                    result.Message = "Ship to Code Core is Error![CustomersInfo]";
                    return(Ok(result));
                }
                entity.CUSTOMER_GROUP  = customersInfo.Customer_Group;
                entity.CUSTOMER_CODE   = customersInfo.Customer_Code;
                entity.CUSTOMER_NAME   = customersInfo.Customer_Name;
                entity.BRANCH_CN       = customersInfo.branch_CN;
                entity.BRANCH_EN       = customersInfo.branch_EN;
                entity.WHS_CHANNEL     = customersInfo.WHS_Channel;
                entity.Product_Channel = customersInfo.Product_Channel;


                #region 生成Dummy Code  即POS_CODE
                string paraname = "NN" + entity.TM_YEAR.Substring(2, 2) + entity.TM_SEASON + "-" + entity.CUSTOMER_GROUP + entity.BRANCH_EN + "-" + entity.POS_CHANNEL.Substring(0, 1);
                var    maxindex = Repository.GetMaxPOSCode(paraname);
                if (!string.IsNullOrEmpty(maxindex.ToString()))
                {
                    int index = int.Parse(maxindex.ToString());
                    if (index > 0)
                    {
                        index++;
                        entity.POS_CODE = paraname + (index < 10 ? "0" + index : index + "");
                    }
                    else
                    {
                        entity.POS_CODE = paraname + "01";
                    }
                }
                else
                {
                    entity.POS_CODE = paraname + "01";
                }
                #endregion

                #region 验证 ship to Code
                if (!string.IsNullOrEmpty(entity.STC_CORE))
                {
                    entity.STC_CORE = entity.STC_CORE.ToUpper();
                }
                if (entity.STC_CORE != "TBD" && !string.IsNullOrEmpty(entity.STC_CORE))
                {
                    //  string Productchannel = Repository.GetProductchannel(entity.STC_CORE);

                    if (entity.Product_Channel.ToLower() != "core")
                    {
                        result.Message = "Ship to Code(Core) is Error [Product_Channel]!";
                        return(Ok(result));
                    }
                    int reuslt = Repository.ExistshipCode(entity.STC_CORE, 1);
                    if (reuslt > 0)
                    {
                        //ship to code 是否正确
                        result.Message = "Ship to Code(Core) is exist!";
                        return(Ok(result));
                    }
                }
                #endregion
                #region CURRENT_STATUS和 CURRENT_COMPSTATUS 和BLR 一些状态的默认值

                entity.BLRQ1              = "N";
                entity.COMPQ1             = "N";
                entity.BLRQ2              = "N";
                entity.COMPQ2             = "N";
                entity.BLRQ3              = "N";
                entity.COMPQ3             = "N";
                entity.BLRQ4              = "N";
                entity.COMPQ4             = "N";
                entity.CURRENT_STATUS     = "N";
                entity.CURRENT_COMPSTATUS = "N";

                #endregion
                await Repository.PostEntity(entity);

                result.Message   = "ok";
                result.IsSuccess = true;
            }
            catch (Exception ex)
            {
                result.Message = "" + ex.Message;
            }

            return(Ok(result));
        }
 public async Task <object> GetSingleEntityByShipTo_Code(string ShipTo_Code)
 {
     return(Ok(await Repository.GetSingleEntityByShipTo_Code(ShipTo_Code)));
 }