public bx_quote_many_source GetModel(int agent, int source) { bx_quote_many_source model = new bx_quote_many_source(); try { model = DataContextFactory.GetDataContext().bx_quote_many_source.First(x => x.child_agent == agent && x.source == source); } catch (Exception ex) { logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException); } return(model); }
public int Update(bx_quote_many_source model) { int count = 0; try { DataContextFactory.GetDataContext().bx_quote_many_source.AddOrUpdate(model); count = DataContextFactory.GetDataContext().SaveChanges(); } catch (Exception ex) { logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException); } return(count); }
public long Add(bx_quote_many_source model) { long modelId = 0; try { var result = DataContextFactory.GetDataContext().bx_quote_many_source.Add(model); DataContextFactory.GetDataContext().SaveChanges(); return(modelId); } catch (Exception ex) { logError.Info("发生异常:" + ex.Source + "\n" + ex.StackTrace + "\n" + ex.Message + "\n" + ex.InnerException); } return(modelId); }
public void UpdateQuoteManySourceMethod(int childAgent, int topAgent, string multiChannels, List <MultiChannels> models) { if (!string.IsNullOrWhiteSpace(multiChannels)) { models = multiChannels.FromJson <List <MultiChannels> >(); } if (models.Any()) { //取出已存bx_quote_many_source的记录 var sources = models.Select(l => l.Source).ToList(); string strSources = string.Join(",", sources); List <bx_quote_many_source> list = _quoteManySourceRepository.GetModels(childAgent, strSources); //开始循环传进来的报价渠道模型,进行更新 foreach (var item in models) { int oldSource = (int)item.Source; //根据source和childagent查对应记录,有就更新,没有就插 bx_quote_many_source model = list.Where(l => l.child_agent == childAgent && l.source == oldSource).FirstOrDefault(); if (model == null) { model = new bx_quote_many_source(); //插入 model.channel_id = item.ChannelId; model.source = oldSource; model.child_agent = childAgent; model.top_agent = topAgent; _quoteManySourceRepository.Add(model); } else if (model.channel_id != item.ChannelId) { //执行更新 model.channel_id = item.ChannelId; _quoteManySourceRepository.Update(model); } } } }