Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- public static string CheckPromoValid(Model.PromoModel model)
- {
- StringBuilder sb = new StringBuilder();
- Promo promo = Promo.AdminGetById(model.ID);
- if (string.IsNullOrEmpty(promo.Mekanisme))
- {
- sb.AppendLine("Mekanisme tidak boleh kosong");
- sb.AppendLine("<br>");
- }
- if (!string.IsNullOrEmpty(promo.PeriodeJam))
- {
- String[] arr = promo.PeriodeJam.Split('-');
- if (arr.Count() <= 1)
- {
- sb.AppendLine("Format periode jam salah");
- sb.AppendLine("<br>");
- }
- }
- if (!string.IsNullOrEmpty(promo.PeriodeMingguan))
- {
- int lengthWord = promo.PeriodeMingguan.Length;
- if (lengthWord != 7)
- {
- sb.AppendLine("Format periode mingguan salah");
- sb.AppendLine("<br>");
- }
- }
- if (string.IsNullOrEmpty(promo.ItemSyarat))
- {
- sb.AppendLine("Item syarat tidak boleh kosong");
- sb.AppendLine("<br>");
- }
- if (string.IsNullOrEmpty(promo.ItemTarget))
- {
- sb.AppendLine("Item target tidak boleh kosong");
- sb.AppendLine("<br>");
- }
- if (string.IsNullOrEmpty(promo.SyaratCampur))
- {
- sb.AppendLine("Syarat campuran tidak boleh kosong");
- sb.AppendLine("<br>");
- }
- #region qty syarat min
- if (promo.QtySyaratMax > 0)
- {
- if (promo.QtySyaratMin <= 0)
- {
- sb.AppendLine("Qty syarat min harus lebih besar dari 0");
- sb.AppendLine("<br>");
- }
- }
- if (promo.QtySyaratMin > 0)
- {
- if (promo.QtySyaratMax <= 0)
- {
- sb.AppendLine("Qty syarat max harus lebih besar dari 0");
- sb.AppendLine("<br>");
- }
- }
- if (promo.QtySyaratMin > promo.QtySyaratMax)
- {
- sb.AppendLine("Qty syarat min harus lebih kecil dari Qty syarat max");
- sb.AppendLine("<br>");
- }
- if (promo.RpSyaratMax > 0)
- {
- if (promo.RpSyaratMin <= 0)
- {
- sb.AppendLine("Rp syarat min harus lebih besar dari 0");
- sb.AppendLine("<br>");
- }
- }
- if (promo.RpSyaratMin > 0)
- {
- if (promo.RpSyaratMax <= 0)
- {
- sb.AppendLine("Rp syarat max harus lebih besar dari 0");
- sb.AppendLine("<br>");
- }
- }
- if (promo.RpSyaratMin > promo.RpSyaratMax)
- {
- sb.AppendLine("Rp syarat min harus lebih kecil dari Rp syarat max");
- sb.AppendLine("<br>");
- }
- if ((promo.QtySyaratMin > 0 && promo.RpSyaratMin > 0) || (promo.QtySyaratMax > 0 && promo.RpSyaratMax > 0))
- {
- sb.AppendLine("Promo tidak bisa menjalankan 2 mekanisme Rp syarat min dan Qty syarat min");
- sb.AppendLine("<br>");
- }
- #endregion
- if (!string.IsNullOrEmpty(promo.PotonganRpTargetTambah))
- {
- var arrTargetTambah = Promo.PopulateItemTargetString(promo.PotonganRpTargetTambah);
- var arrTarget = Promo.PopulateItemTargetString(promo.ItemTarget);
- if (arrTargetTambah.Count != arrTarget.Count)
- {
- sb.AppendLine("Jumlah potongan dengan target produk tidak sama");
- sb.AppendLine("<br>");
- }
- }
- if (!string.IsNullOrEmpty(promo.PotonganPersenTarget))
- {
- var arrTargetDiskon = Promo.PopulateItemTargetString(promo.PotonganPersenTarget);
- var arrTarget = Promo.PopulateItemTargetString(promo.ItemTarget);
- if (arrTargetDiskon.Count != arrTarget.Count)
- {
- sb.AppendLine("Jumlah potongan diskon dengan target produk tidak sama");
- sb.AppendLine("<br>");
- }
- }
- if (!string.IsNullOrEmpty(promo.KodeBIN))
- {
- var paymentType = PaymentType.GetByKodeBIN(promo.KodeBIN);
- if (paymentType == null)
- {
- sb.AppendLine("Kode BIN belum diinput di payment type");
- sb.AppendLine("<br>");
- }
- }
- if (!string.IsNullOrEmpty(promo.Toko))
- {
- if (!promo.ItemSyarat.Contains("&")) //validate exclude item syarat promo
- {
- if (promo.Toko == Constant.PromoToko.TIM8)
- {
- var listPLU = Promo.PopulateItemSyarat(promo.ItemSyarat);
- foreach (var item in listPLU)
- {
- Product product = Product.AdminGetByPLU(item.ItemKey.Replace("PLU=", ""));
- if (product != null)
- {
- if (product.ProductFlag != Constant.ProductFlag.Store)
- {
- sb.AppendLine("PLU : " + product.PLU + " tidak valid untuk promo ini");
- sb.AppendLine("<br>");
- break;
- }
- }
- }
- }
- else if (promo.Toko == Constant.PromoToko.TIM9)
- {
- var listPLU = Promo.PopulateItemTargetString(promo.ItemSyarat);
- foreach (var item in listPLU)
- {
- Product product = Product.AdminGetByPLU(item.ItemKey.Replace("PLU=", ""));
- if (product != null)
- {
- if (product.ProductFlag != Constant.ProductFlag.Plaza)
- {
- sb.AppendLine("PLU : " + product.PLU + " tidak valid untuk promo ini");
- sb.AppendLine("<br>");
- break;
- }
- }
- }
- }
- }
- }
- return sb.ToString();
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement