Пример #1
0
        public static List <ReceiverEntity> GetReceiverAll(bool isRead = true)
        {
            List <ReceiverEntity> all    = new List <ReceiverEntity>();
            ReceiverRepository    mr     = new ReceiverRepository();
            List <ReceiverInfo>   miList = Cache.Get <List <ReceiverInfo> >("ReceiverALL");

            if (miList.IsEmpty())
            {
                miList = mr.GetAllReceiver();
                Cache.Add("ReceiverALL", miList);
            }
            if (!miList.IsEmpty())
            {
                foreach (ReceiverInfo mInfo in miList)
                {
                    ReceiverEntity ReceiverEntity = TranslateReceiverEntity(mInfo, isRead);
                    all.Add(ReceiverEntity);
                }
            }

            return(all);
        }
Пример #2
0
        public static bool ModifyReceiver(ReceiverEntity entity)
        {
            long result = 0;

            if (entity != null)
            {
                ReceiverRepository mr = new ReceiverRepository();

                ReceiverInfo ReceiverInfo = TranslateReceiverInfo(entity);

                ContactJsonEntity jsonlist = null;
                if (!string.IsNullOrEmpty(entity.ContactJson))
                {
                    try
                    {
                        jsonlist = (ContactJsonEntity)JsonHelper.FromJson(entity.ContactJson, typeof(ContactJsonEntity));
                    }
                    catch (Exception ex)
                    {
                        string str = ex.ToString();
                    }
                }

                if (entity.ReceiverID > 0)
                {
                    ReceiverInfo.ReceiverID = entity.ReceiverID;
                    ReceiverInfo.ChangeDate = DateTime.Now;
                    result = mr.ModifyReceiver(ReceiverInfo);
                }
                else
                {
                    ReceiverInfo.ChangeDate = DateTime.Now;
                    ReceiverInfo.CreateDate = DateTime.Now;
                    result = mr.CreateNew(ReceiverInfo);
                }

                #region 更新联系人信息
                if (jsonlist != null)
                {
                    List <ContactJson> list = jsonlist.listContact;
                    if (list != null && list.Count > 0)
                    {
                        foreach (ContactJson cc in list)
                        {
                            ContactRepository cr      = new ContactRepository();
                            ContactInfo       contact = new ContactInfo();
                            contact.ContactName = cc.ContactName;
                            contact.Mobile      = cc.Mobile;
                            contact.Telephone   = cc.Telephone;
                            contact.Email       = cc.Email;
                            contact.Remark      = cc.Remark;
                            contact.UnionType   = UnionType.Receiver.ToString();//客户
                            if (cc.ContactID > 0)
                            {
                                contact.ContactID  = cc.ContactID;
                                contact.UnionID    = entity.ReceiverID;
                                contact.ChangeDate = DateTime.Now;
                                cr.ModifyContact(contact);
                            }
                            else
                            {
                                contact.UnionID    = entity.ReceiverID > 0 ? entity.ReceiverID : result;
                                contact.CreateDate = DateTime.Now;
                                contact.ChangeDate = DateTime.Now;
                                cr.CreateNew(contact);
                            }
                        }
                    }
                }
                #endregion

                List <ReceiverInfo> miList = mr.GetAllReceiver();//刷新缓存
                Cache.Add("ReceiverALL", miList);

                Cache.Add("GetReceiverByCustomerID" + entity.CustomerID, miList);
            }
            return(result > 0);
        }