daily pastebin goal
7%
SHARE
TWEET

Untitled

a guest May 17th, 2018 106 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. public void ModifyInstsAndChannels(ChannelEditRequest request)
  2. {
  3.     var merchantInsts = _dbfd.MerchantInst.Where(mi => mi.MerchantId == request.MerchantId).ToList();
  4.     var query = (from miNew in request.MerchantInsts
  5.                  join mi in merchantInsts
  6.                      on miNew.InstCode equals mi.InstCode into g
  7.                  from miOld in g.DefaultIfEmpty()
  8.                  select new { miNew, miOld });
  9.     var list = query.ToList();
  10.     foreach (var pair in list)
  11.     {
  12.         var miNew = pair.miNew;
  13.         var miOld = pair.miOld;
  14.  
  15.         if (miOld == null)
  16.         {
  17.             if (!miNew.Checked) continue;
  18.  
  19.             var mi = miNew;
  20.             mi.Guid = Guid.NewGuid().ToString("N");
  21.             mi.CreateTime = DateTime.Now;
  22.             mi.OptUser = request.OptUser;
  23.             mi.MerchantChannels = miNew.MerchantChannels.Where(mc => mc.Checked).Select(mc =>
  24.             {
  25.                 mc.CreateTime = DateTime.Now;
  26.                 mc.OptUser = request.OptUser;
  27.                 mc.Guid = Guid.NewGuid().ToString("N");
  28.                 return mc;
  29.             }).ToList();
  30.             _dbfd.MerchantInst.Add(mi);
  31.         }
  32.         else if (miNew.Checked)
  33.         {
  34.             miOld.InstMerchantId = miNew.InstMerchantId;
  35.             miOld.InstKey = miNew.InstKey;
  36.             miOld.InstShowName = miNew.InstShowName;
  37.             miOld.Checked = miNew.Checked;
  38.             miOld.UpdateTime = DateTime.Now;
  39.             miOld.OptUser = request.OptUser;
  40.             miOld.Guid = Guid.NewGuid().ToString("N");
  41.  
  42.             ModifyMerchantChannels(request.MerchantId, miNew.InstCode, request.OptUser, miNew.MerchantChannels);
  43.         }
  44.         else if (miOld.Checked && !miNew.Checked)
  45.         {
  46.             miOld.Checked = false;
  47.             miOld.OptUser = request.OptUser;
  48.             miOld.UpdateTime = DateTime.Now;
  49.             miOld.Guid = Guid.NewGuid().ToString("N");
  50.         }
  51.     }
  52.  
  53.     _dbfd.SaveChanges();
  54. }
  55.  
  56. private void ModifyMerchantChannels(string merchantId, string instCode, string optUser, IEnumerable<MerchantChannel> newMerchantChannels)
  57. {
  58.     var oldMerchantChannels = _dbfd.MerchantChannel.Where(mc => mc.MerchantId == merchantId && mc.InstCode == instCode).ToList();
  59.     var query = (from mcNew in newMerchantChannels
  60.                  join mcOld in oldMerchantChannels
  61.                      on mcNew.ChannelId equals mcOld.ChannelId into g
  62.                  from mcOld in g.DefaultIfEmpty()
  63.                  select new { mcNew, mcOld });
  64.  
  65.     var list = query.ToList();
  66.     foreach (var pair in list)
  67.     {
  68.         var mcOld = pair.mcOld;
  69.         var mcNew = pair.mcNew;
  70.  
  71.         if (mcOld == null)
  72.         {
  73.             if (!mcNew.Checked) continue;
  74.  
  75.             MerchantChannel mc = mcNew;
  76.             mc.CreateTime = DateTime.Now;
  77.             mc.OptUser = optUser;
  78.             mc.Guid = Guid.NewGuid().ToString("N");
  79.             _dbfd.MerchantChannel.Add(mc);
  80.         }
  81.         else if (mcNew.Checked)
  82.         {
  83.             mcOld.InstCode = mcNew.InstCode;
  84.             mcOld.ApplyingType = mcNew.ApplyingType;
  85.             mcOld.Fee = mcNew.Fee;
  86.             mcOld.Checked = mcNew.Checked;
  87.             mcOld.UpdateTime = DateTime.Now;
  88.             mcOld.OptUser = optUser;
  89.             mcOld.Guid = Guid.NewGuid().ToString("N");
  90.         }
  91.         else if (mcOld.Checked && !mcNew.Checked)
  92.         {
  93.             mcOld.Checked = false;
  94.             mcOld.UpdateTime = DateTime.Now;
  95.             mcOld.OptUser = optUser;
  96.             mcOld.Guid = Guid.NewGuid().ToString("N");
  97.         }
  98.     }
  99. }
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top