コード例 #1
0
        public async Task <object> InsertPos_MasterInfo(POS_Master entity)
        {
            ResultModel result = new ResultModel();

            result.IsSuccess = false;

            try
            {
                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;
                #region 生成Dummy Code  即POS_CODE
                //Dummy Code的生成规则:Dummy Year(2 digit sequential number)&Quarter+"-"+Customer Short Name+Branch+"-"+Channel short Name+2 digit sequential number
                string paraname = 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 Productchannel = Repository.GetProductchannel(entity.STC_CORE);
                        entity.Product_Channel = Productchannel;
                        if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToString().ToLower() != "core")
                        {
                            result.Message = "Ship to Code(Core) is Error!";
                            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));
                        }
                    }
                }

                if (!string.IsNullOrEmpty(entity.STC_OCS))
                {
                    entity.STC_OCS = entity.STC_OCS.ToUpper();
                    if (entity.STC_OCS != "TBD")
                    {
                        string Productchannel = Repository.GetProductchannel(entity.STC_OCS);
                        entity.Product_Channel = Productchannel;
                        if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToLower() != "originals")
                        {
                            result.Message = "Ship to Code(Originals) is Error!";
                            return(Ok(result));
                        }
                        int reuslt = Repository.ExistshipCode(entity.STC_OCS, 2);
                        if (reuslt > 0)
                        {
                            //ship to code 是否正确
                            result.Message = "Ship to Code(Originals) is exist!";
                            return(Ok(result));
                        }
                    }
                }

                if (!string.IsNullOrEmpty(entity.STC_NEO))
                {
                    entity.STC_NEO = entity.STC_NEO.ToUpper();
                    if (entity.STC_NEO != "TBD")
                    {
                        string Productchannel = Repository.GetProductchannel(entity.STC_NEO);
                        entity.Product_Channel = Productchannel;
                        if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToLower() != "neo")
                        {
                            result.Message = "Ship to Code(Neo) is Error!";
                            return(Ok(result));
                        }
                        int reuslt = Repository.ExistshipCode(entity.STC_NEO, 3);
                        if (reuslt > 0)
                        {
                            //ship to code 是否正确
                            result.Message = "Ship to Code(Neo) is exist!";
                            return(Ok(result));
                        }
                    }
                }

                if (!string.IsNullOrEmpty(entity.STC_KIDS))
                {
                    entity.STC_KIDS = entity.STC_KIDS.ToUpper();
                    if (entity.STC_KIDS != "TBD")
                    {
                        string Productchannel = Repository.GetProductchannel(entity.STC_KIDS);
                        entity.Product_Channel = Productchannel;
                        if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToLower() != "kids")
                        {
                            result.Message = "Ship to Code(Kids) is Error!";
                            return(Ok(result));
                        }
                        int reuslt = Repository.ExistshipCode(entity.STC_KIDS, 4);
                        if (reuslt > 0)
                        {
                            //ship to code 是否正确
                            result.Message = "Ship to Code(Kids) is exist!";
                            return(Ok(result));
                        }
                    }
                }


                #endregion

                #region CURRENT_STATUS和 CURRENT_COMPSTATUS

                if (entity.TM_SEASON == "Q1")
                {
                    entity.CURRENT_STATUS     = entity.BLRQ1;
                    entity.CURRENT_COMPSTATUS = entity.COMPQ1;
                }
                else if (entity.TM_SEASON == "Q2")
                {
                    entity.CURRENT_STATUS     = entity.BLRQ2;
                    entity.CURRENT_COMPSTATUS = entity.COMPQ2;
                }
                else if (entity.TM_SEASON == "Q3")
                {
                    entity.CURRENT_STATUS     = entity.BLRQ3;
                    entity.CURRENT_COMPSTATUS = entity.COMPQ3;
                }
                else if (entity.TM_SEASON == "Q4")
                {
                    entity.CURRENT_STATUS     = entity.BLRQ4;
                    entity.CURRENT_COMPSTATUS = entity.COMPQ4;
                }

                #endregion
                await Repository.PostEntity(entity);

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

            return(Ok(result));
        }
コード例 #2
0
        public OkObjectResult EditMD_BulkShipTo(MD_BulkShipTo entity)
        {
            ResultModel result = new ResultModel();

            try
            {
                result.IsSuccess = false;
                int Total = 0;
                //获取customerInfo
                #region 验证 ship to Code 的输入是否正确
                if (!string.IsNullOrEmpty(entity.Bulk_Ship_to_Code_Core))
                {
                    entity.Bulk_Ship_to_Code_Core = entity.Bulk_Ship_to_Code_Core.ToUpper();
                    if (entity.Bulk_Ship_to_Code_Core != "TBD")
                    {
                        string[] codelist = entity.Bulk_Ship_to_Code_Core.Split('/');
                        foreach (string Code in codelist)
                        {
                            string Productchannel = PosRepository.GetProductchannel(Code);
                            if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToString().ToLower() != "core")
                            {
                                result.Message = "Bulk Ship to Code(Core) is Error!";
                                return(Ok(result));
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(entity.Bulk_Ship_to_Code_Originals))
                {
                    entity.Bulk_Ship_to_Code_Originals = entity.Bulk_Ship_to_Code_Originals.ToUpper();
                    if (entity.Bulk_Ship_to_Code_Originals != "TBD")
                    {
                        string[] codelist = entity.Bulk_Ship_to_Code_Originals.Split('/');
                        foreach (string Code in codelist)
                        {
                            string Productchannel = PosRepository.GetProductchannel(Code);
                            if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToLower() != "originals")
                            {
                                result.Message = "Bulk Ship to Code(Originals) is Error!";
                                return(Ok(result));
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(entity.Bulk_Ship_to_Code_Neo))
                {
                    entity.Bulk_Ship_to_Code_Neo = entity.Bulk_Ship_to_Code_Neo.ToUpper();
                    if (entity.Bulk_Ship_to_Code_Neo != "TBD")
                    {
                        string[] codelist = entity.Bulk_Ship_to_Code_Neo.Split('/');
                        foreach (string Code in codelist)
                        {
                            string Productchannel = PosRepository.GetProductchannel(Code);
                            if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToLower() != "neo")
                            {
                                result.Message = "Bulk Ship to Code(Neo) is Error!";
                                return(Ok(result));
                            }
                        }
                    }
                }
                if (!string.IsNullOrEmpty(entity.Bulk_Ship_to_Code_Kids))
                {
                    entity.Bulk_Ship_to_Code_Kids = entity.Bulk_Ship_to_Code_Kids.ToUpper();
                    if (entity.Bulk_Ship_to_Code_Kids != "TBD")
                    {
                        string[] codelist = entity.Bulk_Ship_to_Code_Kids.Split('/');
                        foreach (string Code in codelist)
                        {
                            string Productchannel = PosRepository.GetProductchannel(Code);
                            if (string.IsNullOrEmpty(Productchannel) || Productchannel.ToLower() != "kids")
                            {
                                result.Message = "Bulk Ship to Code(Kids) is Error!";
                                return(Ok(result));
                            }
                        }
                    }
                }
                #endregion
                //string sqlstr = "select count(ID) from SIDE_MD_BulkShipTo where BRANCH_CN=@BRANCH_CN and BRANCH_EN=@BRANCH_EN and WHS_Channel=@WHS_Channel ";
                //if (entity.ID > 0)
                //{
                //    sqlstr = sqlstr + " and ID<>@ID ";
                //}
                //DynamicParameters parameters = new DynamicParameters();
                //parameters.Add("@ID", entity.ID, DbType.Int32, ParameterDirection.Input);
                //parameters.Add("@BRANCH_CN", entity.BRANCH_CN, DbType.String, ParameterDirection.Input);
                //parameters.Add("@BRANCH_EN", entity.BRANCH_EN, DbType.String, ParameterDirection.Input);
                //parameters.Add("@WHS_Channel", entity.WHS_Channel, DbType.String, ParameterDirection.Input);

                //using (IDbConnection conn = DataBaseConfig.GetSqlConnection())
                //{
                //    Total = (Int32)conn.ExecuteScalar(sqlstr, parameters);
                //}
                if (Total > 0)
                {
                    result.IsSuccess  = false;
                    result.Message    = "Already exist";
                    result.StatusCode = "-4";
                }
                else
                {
                    if (entity.ID == 0)
                    {
                        int row = masterdataRepository.AddMD_BulkShipTo(entity);
                        result.StatusCode = row.ToString();
                        result.Message    = "OK";
                        result.IsSuccess  = true;
                    }
                    else
                    {
                        int row = masterdataRepository.UpdateMD_BulkShipTo(entity);
                        result.StatusCode = row.ToString();
                        result.Message    = "OK";
                        result.IsSuccess  = true;
                    }
                }
            }
            catch (Exception ex)
            {
                result.Message   = ex.Message;
                result.IsSuccess = false;
            }
            return(Ok(result));
        }