Ejemplo n.º 1
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));
        }