Advertisement
febripratama

promo validasi

May 29th, 2020
834
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C# 6.88 KB | None | 0 0
  1.  
  2.         public static string CheckPromoValid(Model.PromoModel model)
  3.         {
  4.             StringBuilder sb = new StringBuilder();
  5.  
  6.             Promo promo = Promo.AdminGetById(model.ID);
  7.  
  8.             if (string.IsNullOrEmpty(promo.Mekanisme))
  9.             {
  10.                 sb.AppendLine("Mekanisme tidak boleh kosong");
  11.                 sb.AppendLine("<br>");
  12.             }
  13.  
  14.             if (!string.IsNullOrEmpty(promo.PeriodeJam))
  15.             {
  16.                 String[] arr = promo.PeriodeJam.Split('-');
  17.  
  18.                 if (arr.Count() <= 1)
  19.                 {
  20.                     sb.AppendLine("Format periode jam salah");
  21.                     sb.AppendLine("<br>");
  22.                 }
  23.             }
  24.  
  25.             if (!string.IsNullOrEmpty(promo.PeriodeMingguan))
  26.             {
  27.                 int lengthWord = promo.PeriodeMingguan.Length;
  28.  
  29.                 if (lengthWord != 7)
  30.                 {
  31.                     sb.AppendLine("Format periode mingguan salah");
  32.                     sb.AppendLine("<br>");
  33.                 }
  34.             }
  35.  
  36.             if (string.IsNullOrEmpty(promo.ItemSyarat))
  37.             {
  38.                 sb.AppendLine("Item syarat tidak boleh kosong");
  39.                 sb.AppendLine("<br>");
  40.             }
  41.  
  42.             if (string.IsNullOrEmpty(promo.ItemTarget))
  43.             {
  44.                 sb.AppendLine("Item target tidak boleh kosong");
  45.                 sb.AppendLine("<br>");
  46.             }
  47.  
  48.             if (string.IsNullOrEmpty(promo.SyaratCampur))
  49.             {
  50.                 sb.AppendLine("Syarat campuran tidak boleh kosong");
  51.                 sb.AppendLine("<br>");
  52.             }
  53.  
  54.             #region qty syarat min
  55.             if (promo.QtySyaratMax > 0)
  56.             {
  57.                 if (promo.QtySyaratMin <= 0)
  58.                 {
  59.                     sb.AppendLine("Qty syarat min harus lebih besar dari 0");
  60.                     sb.AppendLine("<br>");
  61.                 }
  62.             }
  63.  
  64.             if (promo.QtySyaratMin > 0)
  65.             {
  66.                 if (promo.QtySyaratMax <= 0)
  67.                 {
  68.                     sb.AppendLine("Qty syarat max harus lebih besar dari 0");
  69.                     sb.AppendLine("<br>");
  70.                 }
  71.             }
  72.  
  73.             if (promo.QtySyaratMin > promo.QtySyaratMax)
  74.             {
  75.                 sb.AppendLine("Qty syarat min harus lebih kecil dari Qty syarat max");
  76.                 sb.AppendLine("<br>");
  77.             }
  78.  
  79.             if (promo.RpSyaratMax > 0)
  80.             {
  81.                 if (promo.RpSyaratMin <= 0)
  82.                 {
  83.                     sb.AppendLine("Rp syarat min harus lebih besar dari 0");
  84.                     sb.AppendLine("<br>");
  85.                 }
  86.             }
  87.  
  88.             if (promo.RpSyaratMin > 0)
  89.             {
  90.                 if (promo.RpSyaratMax <= 0)
  91.                 {
  92.                     sb.AppendLine("Rp syarat max harus lebih besar dari 0");
  93.                     sb.AppendLine("<br>");
  94.                 }
  95.             }
  96.  
  97.             if (promo.RpSyaratMin > promo.RpSyaratMax)
  98.             {
  99.                 sb.AppendLine("Rp syarat min harus lebih kecil dari Rp syarat max");
  100.                 sb.AppendLine("<br>");
  101.             }
  102.  
  103.             if ((promo.QtySyaratMin > 0 && promo.RpSyaratMin > 0) || (promo.QtySyaratMax > 0 && promo.RpSyaratMax > 0))
  104.             {
  105.                 sb.AppendLine("Promo tidak bisa menjalankan 2 mekanisme Rp syarat min dan Qty syarat min");
  106.                 sb.AppendLine("<br>");
  107.             }
  108.             #endregion
  109.  
  110.             if (!string.IsNullOrEmpty(promo.PotonganRpTargetTambah))
  111.             {
  112.                 var arrTargetTambah = Promo.PopulateItemTargetString(promo.PotonganRpTargetTambah);
  113.                 var arrTarget = Promo.PopulateItemTargetString(promo.ItemTarget);
  114.  
  115.                 if (arrTargetTambah.Count != arrTarget.Count)
  116.                 {
  117.                     sb.AppendLine("Jumlah potongan dengan target produk tidak sama");
  118.                     sb.AppendLine("<br>");
  119.                 }
  120.             }
  121.  
  122.             if (!string.IsNullOrEmpty(promo.PotonganPersenTarget))
  123.             {
  124.                 var arrTargetDiskon = Promo.PopulateItemTargetString(promo.PotonganPersenTarget);
  125.                 var arrTarget = Promo.PopulateItemTargetString(promo.ItemTarget);
  126.  
  127.                 if (arrTargetDiskon.Count != arrTarget.Count)
  128.                 {
  129.                     sb.AppendLine("Jumlah potongan diskon dengan target produk tidak sama");
  130.                     sb.AppendLine("<br>");
  131.                 }
  132.             }
  133.  
  134.             if (!string.IsNullOrEmpty(promo.KodeBIN))
  135.             {
  136.                 var paymentType = PaymentType.GetByKodeBIN(promo.KodeBIN);
  137.  
  138.                 if (paymentType == null)
  139.                 {
  140.                     sb.AppendLine("Kode BIN belum diinput di payment type");
  141.                     sb.AppendLine("<br>");
  142.                 }
  143.             }
  144.  
  145.             if (!string.IsNullOrEmpty(promo.Toko))
  146.             {
  147.                 if (!promo.ItemSyarat.Contains("&")) //validate exclude item syarat promo
  148.                 {
  149.                     if (promo.Toko == Constant.PromoToko.TIM8)
  150.                     {
  151.                         var listPLU = Promo.PopulateItemSyarat(promo.ItemSyarat);
  152.  
  153.                         foreach (var item in listPLU)
  154.                         {
  155.                             Product product = Product.AdminGetByPLU(item.ItemKey.Replace("PLU=", ""));
  156.  
  157.                             if (product != null)
  158.                             {
  159.                                 if (product.ProductFlag != Constant.ProductFlag.Store)
  160.                                 {
  161.                                     sb.AppendLine("PLU : " + product.PLU + " tidak valid untuk promo ini");
  162.                                     sb.AppendLine("<br>");
  163.                                     break;
  164.                                 }
  165.                             }
  166.                         }
  167.  
  168.                     }
  169.                     else if (promo.Toko == Constant.PromoToko.TIM9)
  170.                     {
  171.                         var listPLU = Promo.PopulateItemTargetString(promo.ItemSyarat);
  172.  
  173.                         foreach (var item in listPLU)
  174.                         {
  175.                             Product product = Product.AdminGetByPLU(item.ItemKey.Replace("PLU=", ""));
  176.  
  177.                             if (product != null)
  178.                             {
  179.                                 if (product.ProductFlag != Constant.ProductFlag.Plaza)
  180.                                 {
  181.                                     sb.AppendLine("PLU : " + product.PLU + " tidak valid untuk promo ini");
  182.                                     sb.AppendLine("<br>");
  183.                                     break;
  184.                                 }
  185.                             }
  186.                         }
  187.                     }
  188.  
  189.                 }
  190.             }
  191.  
  192.             return sb.ToString();
  193.         }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement